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

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