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 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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. import org.eclipse.jgit.JGitText;
  48. /**
  49. * Important state of the repository that affects what can and cannot bed
  50. * done. This is things like unhandled conflicted merges and unfinished rebase.
  51. *
  52. * The granularity and set of states are somewhat arbitrary. The methods
  53. * on the state are the only supported means of deciding what to do.
  54. */
  55. public enum RepositoryState {
  56. /** Has no work tree and cannot be used for normal editing. */
  57. BARE {
  58. public boolean canCheckout() { return false; }
  59. public boolean canResetHead() { return false; }
  60. public boolean canCommit() { return false; }
  61. public String getDescription() { return "Bare"; }
  62. },
  63. /**
  64. * A safe state for working normally
  65. * */
  66. SAFE {
  67. public boolean canCheckout() { return true; }
  68. public boolean canResetHead() { return true; }
  69. public boolean canCommit() { return true; }
  70. public String getDescription() { return JGitText.get().repositoryState_normal; }
  71. },
  72. /** An unfinished merge. Must resolve or reset before continuing normally
  73. */
  74. MERGING {
  75. public boolean canCheckout() { return false; }
  76. public boolean canResetHead() { return true; }
  77. public boolean canCommit() { return false; }
  78. public String getDescription() { return JGitText.get().repositoryState_conflicts; }
  79. },
  80. /**
  81. * An merge where all conflicts have been resolved. The index does not
  82. * contain any unmerged paths.
  83. */
  84. MERGING_RESOLVED {
  85. public boolean canCheckout() { return true; }
  86. public boolean canResetHead() { return true; }
  87. public boolean canCommit() { return true; }
  88. public String getDescription() { return JGitText.get().repositoryState_merged; }
  89. },
  90. /**
  91. * An unfinished rebase or am. Must resolve, skip or abort before normal work can take place
  92. */
  93. REBASING {
  94. public boolean canCheckout() { return false; }
  95. public boolean canResetHead() { return false; }
  96. public boolean canCommit() { return true; }
  97. public String getDescription() { return JGitText.get().repositoryState_rebaseOrApplyMailbox; }
  98. },
  99. /**
  100. * An unfinished rebase. Must resolve, skip or abort before normal work can take place
  101. */
  102. REBASING_REBASING {
  103. public boolean canCheckout() { return false; }
  104. public boolean canResetHead() { return false; }
  105. public boolean canCommit() { return true; }
  106. public String getDescription() { return JGitText.get().repositoryState_rebase; }
  107. },
  108. /**
  109. * An unfinished apply. Must resolve, skip or abort before normal work can take place
  110. */
  111. APPLY {
  112. public boolean canCheckout() { return false; }
  113. public boolean canResetHead() { return false; }
  114. public boolean canCommit() { return true; }
  115. public String getDescription() { return JGitText.get().repositoryState_applyMailbox; }
  116. },
  117. /**
  118. * An unfinished rebase with merge. Must resolve, skip or abort before normal work can take place
  119. */
  120. REBASING_MERGE {
  121. public boolean canCheckout() { return false; }
  122. public boolean canResetHead() { return false; }
  123. public boolean canCommit() { return true; }
  124. public String getDescription() { return JGitText.get().repositoryState_rebaseWithMerge; }
  125. },
  126. /**
  127. * An unfinished interactive rebase. Must resolve, skip or abort before normal work can take place
  128. */
  129. REBASING_INTERACTIVE {
  130. public boolean canCheckout() { return false; }
  131. public boolean canResetHead() { return false; }
  132. public boolean canCommit() { return true; }
  133. public String getDescription() { return JGitText.get().repositoryState_rebaseInteractive; }
  134. },
  135. /**
  136. * Bisecting being done. Normal work may continue but is discouraged
  137. */
  138. BISECTING {
  139. /* Changing head is a normal operation when bisecting */
  140. public boolean canCheckout() { return true; }
  141. /* Do not reset, checkout instead */
  142. public boolean canResetHead() { return false; }
  143. /* Commit during bisect is useful */
  144. public boolean canCommit() { return true; }
  145. public String getDescription() { return JGitText.get().repositoryState_bisecting; }
  146. };
  147. /**
  148. * @return true if changing HEAD is sane.
  149. */
  150. public abstract boolean canCheckout();
  151. /**
  152. * @return true if we can commit
  153. */
  154. public abstract boolean canCommit();
  155. /**
  156. * @return true if reset to another HEAD is considered SAFE
  157. */
  158. public abstract boolean canResetHead();
  159. /**
  160. * @return a human readable description of the state.
  161. */
  162. public abstract String getDescription();
  163. }