Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

RepositoryState.java 7.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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.internal.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 boolean canAmend() { return false; }
  62. public String getDescription() { return "Bare"; }
  63. },
  64. /**
  65. * A safe state for working normally
  66. * */
  67. SAFE {
  68. public boolean canCheckout() { return true; }
  69. public boolean canResetHead() { return true; }
  70. public boolean canCommit() { return true; }
  71. public boolean canAmend() { return true; }
  72. public String getDescription() { return JGitText.get().repositoryState_normal; }
  73. },
  74. /** An unfinished merge. Must resolve or reset before continuing normally
  75. */
  76. MERGING {
  77. public boolean canCheckout() { return false; }
  78. public boolean canResetHead() { return true; }
  79. public boolean canCommit() { return false; }
  80. public boolean canAmend() { return false; }
  81. public String getDescription() { return JGitText.get().repositoryState_conflicts; }
  82. },
  83. /**
  84. * An merge where all conflicts have been resolved. The index does not
  85. * contain any unmerged paths.
  86. */
  87. MERGING_RESOLVED {
  88. public boolean canCheckout() { return true; }
  89. public boolean canResetHead() { return true; }
  90. public boolean canCommit() { return true; }
  91. public boolean canAmend() { return false; }
  92. public String getDescription() { return JGitText.get().repositoryState_merged; }
  93. },
  94. /** An unfinished cherry-pick. Must resolve or reset before continuing normally
  95. */
  96. CHERRY_PICKING {
  97. public boolean canCheckout() { return false; }
  98. public boolean canResetHead() { return true; }
  99. public boolean canCommit() { return false; }
  100. public boolean canAmend() { return false; }
  101. public String getDescription() { return JGitText.get().repositoryState_conflicts; }
  102. },
  103. /**
  104. * A cherry-pick where all conflicts have been resolved. The index does not
  105. * contain any unmerged paths.
  106. */
  107. CHERRY_PICKING_RESOLVED {
  108. public boolean canCheckout() { return true; }
  109. public boolean canResetHead() { return true; }
  110. public boolean canCommit() { return true; }
  111. public boolean canAmend() { return false; }
  112. public String getDescription() { return JGitText.get().repositoryState_merged; }
  113. },
  114. /**
  115. * An unfinished rebase or am. Must resolve, skip or abort before normal work can take place
  116. */
  117. REBASING {
  118. public boolean canCheckout() { return false; }
  119. public boolean canResetHead() { return false; }
  120. public boolean canCommit() { return true; }
  121. public boolean canAmend() { return true; }
  122. public String getDescription() { return JGitText.get().repositoryState_rebaseOrApplyMailbox; }
  123. },
  124. /**
  125. * An unfinished rebase. Must resolve, skip or abort before normal work can take place
  126. */
  127. REBASING_REBASING {
  128. public boolean canCheckout() { return false; }
  129. public boolean canResetHead() { return false; }
  130. public boolean canCommit() { return true; }
  131. public boolean canAmend() { return true; }
  132. public String getDescription() { return JGitText.get().repositoryState_rebase; }
  133. },
  134. /**
  135. * An unfinished apply. Must resolve, skip or abort before normal work can take place
  136. */
  137. APPLY {
  138. public boolean canCheckout() { return false; }
  139. public boolean canResetHead() { return false; }
  140. public boolean canCommit() { return true; }
  141. public boolean canAmend() { return true; }
  142. public String getDescription() { return JGitText.get().repositoryState_applyMailbox; }
  143. },
  144. /**
  145. * An unfinished rebase with merge. Must resolve, skip or abort before normal work can take place
  146. */
  147. REBASING_MERGE {
  148. public boolean canCheckout() { return false; }
  149. public boolean canResetHead() { return false; }
  150. public boolean canCommit() { return true; }
  151. public boolean canAmend() { return true; }
  152. public String getDescription() { return JGitText.get().repositoryState_rebaseWithMerge; }
  153. },
  154. /**
  155. * An unfinished interactive rebase. Must resolve, skip or abort before normal work can take place
  156. */
  157. REBASING_INTERACTIVE {
  158. public boolean canCheckout() { return false; }
  159. public boolean canResetHead() { return false; }
  160. public boolean canCommit() { return true; }
  161. public boolean canAmend() { return true; }
  162. public String getDescription() { return JGitText.get().repositoryState_rebaseInteractive; }
  163. },
  164. /**
  165. * Bisecting being done. Normal work may continue but is discouraged
  166. */
  167. BISECTING {
  168. /* Changing head is a normal operation when bisecting */
  169. public boolean canCheckout() { return true; }
  170. /* Do not reset, checkout instead */
  171. public boolean canResetHead() { return false; }
  172. /* Commit during bisect is useful */
  173. public boolean canCommit() { return true; }
  174. public boolean canAmend() { return false; }
  175. public String getDescription() { return JGitText.get().repositoryState_bisecting; }
  176. };
  177. /**
  178. * @return true if changing HEAD is sane.
  179. */
  180. public abstract boolean canCheckout();
  181. /**
  182. * @return true if we can commit
  183. */
  184. public abstract boolean canCommit();
  185. /**
  186. * @return true if reset to another HEAD is considered SAFE
  187. */
  188. public abstract boolean canResetHead();
  189. /**
  190. * @return true if amending is considered SAFE
  191. */
  192. public abstract boolean canAmend();
  193. /**
  194. * @return a human readable description of the state.
  195. */
  196. public abstract String getDescription();
  197. }