You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RepositoryState.java 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. /*
  2. * Copyright (C) 2008, Mike Ralphson <mike@abacus.co.uk>
  3. * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg.lists@dewire.com>
  4. * Copyright (C) 2007, Robin Rosenberg <robin.rosenberg@dewire.com>
  5. * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org>
  6. * and other copyright owners as documented in the project's IP log.
  7. *
  8. * This program and the accompanying materials are made available
  9. * under the terms of the Eclipse Distribution License v1.0 which
  10. * accompanies this distribution, is reproduced below, and is
  11. * available at http://www.eclipse.org/org/documents/edl-v10.php
  12. *
  13. * All rights reserved.
  14. *
  15. * Redistribution and use in source and binary forms, with or
  16. * without modification, are permitted provided that the following
  17. * conditions are met:
  18. *
  19. * - Redistributions of source code must retain the above copyright
  20. * notice, this list of conditions and the following disclaimer.
  21. *
  22. * - Redistributions in binary form must reproduce the above
  23. * copyright notice, this list of conditions and the following
  24. * disclaimer in the documentation and/or other materials provided
  25. * with the distribution.
  26. *
  27. * - Neither the name of the Eclipse Foundation, Inc. nor the
  28. * names of its contributors may be used to endorse or promote
  29. * products derived from this software without specific prior
  30. * written permission.
  31. *
  32. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  33. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  34. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  35. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  36. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  37. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  38. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  39. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  40. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  41. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  42. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  43. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  44. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  45. */
  46. package org.eclipse.jgit.lib;
  47. /**
  48. * Important state of the repository that affects what can and cannot bed
  49. * done. This is things like unhandled conflicted merges and unfinished rebase.
  50. *
  51. * The granularity and set of states are somewhat arbitrary. The methods
  52. * on the state are the only supported means of deciding what to do.
  53. */
  54. public enum RepositoryState {
  55. /**
  56. * A safe state for working normally
  57. * */
  58. SAFE {
  59. public boolean canCheckout() { return true; }
  60. public boolean canResetHead() { return true; }
  61. public boolean canCommit() { return true; }
  62. public String getDescription() { return "Normal"; }
  63. },
  64. /** An unfinished merge. Must resole or reset before continuing normally
  65. */
  66. MERGING {
  67. public boolean canCheckout() { return false; }
  68. public boolean canResetHead() { return false; }
  69. public boolean canCommit() { return false; }
  70. public String getDescription() { return "Conflicts"; }
  71. },
  72. /**
  73. * An unfinished rebase or am. Must resolve, skip or abort before normal work can take place
  74. */
  75. REBASING {
  76. public boolean canCheckout() { return false; }
  77. public boolean canResetHead() { return false; }
  78. public boolean canCommit() { return true; }
  79. public String getDescription() { return "Rebase/Apply mailbox"; }
  80. },
  81. /**
  82. * An unfinished rebase. Must resolve, skip or abort before normal work can take place
  83. */
  84. REBASING_REBASING {
  85. public boolean canCheckout() { return false; }
  86. public boolean canResetHead() { return false; }
  87. public boolean canCommit() { return true; }
  88. public String getDescription() { return "Rebase"; }
  89. },
  90. /**
  91. * An unfinished apply. Must resolve, skip or abort before normal work can take place
  92. */
  93. APPLY {
  94. public boolean canCheckout() { return false; }
  95. public boolean canResetHead() { return false; }
  96. public boolean canCommit() { return true; }
  97. public String getDescription() { return "Apply mailbox"; }
  98. },
  99. /**
  100. * An unfinished rebase with merge. Must resolve, skip or abort before normal work can take place
  101. */
  102. REBASING_MERGE {
  103. public boolean canCheckout() { return false; }
  104. public boolean canResetHead() { return false; }
  105. public boolean canCommit() { return true; }
  106. public String getDescription() { return "Rebase w/merge"; }
  107. },
  108. /**
  109. * An unfinished interactive rebase. Must resolve, skip or abort before normal work can take place
  110. */
  111. REBASING_INTERACTIVE {
  112. public boolean canCheckout() { return false; }
  113. public boolean canResetHead() { return false; }
  114. public boolean canCommit() { return true; }
  115. public String getDescription() { return "Rebase interactive"; }
  116. },
  117. /**
  118. * Bisecting being done. Normal work may continue but is discouraged
  119. */
  120. BISECTING {
  121. /* Changing head is a normal operation when bisecting */
  122. public boolean canCheckout() { return true; }
  123. /* Do not reset, checkout instead */
  124. public boolean canResetHead() { return false; }
  125. /* Actually it may make sense, but for now we err on the side of caution */
  126. public boolean canCommit() { return false; }
  127. public String getDescription() { return "Bisecting"; }
  128. };
  129. /**
  130. * @return true if changing HEAD is sane.
  131. */
  132. public abstract boolean canCheckout();
  133. /**
  134. * @return true if we can commit
  135. */
  136. public abstract boolean canCommit();
  137. /**
  138. * @return true if reset to another HEAD is considered SAFE
  139. */
  140. public abstract boolean canResetHead();
  141. /**
  142. * @return a human readable description of the state.
  143. */
  144. public abstract String getDescription();
  145. }