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.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 merge where all conflicts have been resolved. The index does not
  74. * contain any unmerged paths.
  75. */
  76. MERGING_RESOLVED {
  77. public boolean canCheckout() { return true; }
  78. public boolean canResetHead() { return true; }
  79. public boolean canCommit() { return true; }
  80. public String getDescription() { return "Merged"; }
  81. },
  82. /**
  83. * An unfinished rebase or am. Must resolve, skip or abort before normal work can take place
  84. */
  85. REBASING {
  86. public boolean canCheckout() { return false; }
  87. public boolean canResetHead() { return false; }
  88. public boolean canCommit() { return true; }
  89. public String getDescription() { return "Rebase/Apply mailbox"; }
  90. },
  91. /**
  92. * An unfinished rebase. Must resolve, skip or abort before normal work can take place
  93. */
  94. REBASING_REBASING {
  95. public boolean canCheckout() { return false; }
  96. public boolean canResetHead() { return false; }
  97. public boolean canCommit() { return true; }
  98. public String getDescription() { return "Rebase"; }
  99. },
  100. /**
  101. * An unfinished apply. Must resolve, skip or abort before normal work can take place
  102. */
  103. APPLY {
  104. public boolean canCheckout() { return false; }
  105. public boolean canResetHead() { return false; }
  106. public boolean canCommit() { return true; }
  107. public String getDescription() { return "Apply mailbox"; }
  108. },
  109. /**
  110. * An unfinished rebase with merge. Must resolve, skip or abort before normal work can take place
  111. */
  112. REBASING_MERGE {
  113. public boolean canCheckout() { return false; }
  114. public boolean canResetHead() { return false; }
  115. public boolean canCommit() { return true; }
  116. public String getDescription() { return "Rebase w/merge"; }
  117. },
  118. /**
  119. * An unfinished interactive rebase. Must resolve, skip or abort before normal work can take place
  120. */
  121. REBASING_INTERACTIVE {
  122. public boolean canCheckout() { return false; }
  123. public boolean canResetHead() { return false; }
  124. public boolean canCommit() { return true; }
  125. public String getDescription() { return "Rebase interactive"; }
  126. },
  127. /**
  128. * Bisecting being done. Normal work may continue but is discouraged
  129. */
  130. BISECTING {
  131. /* Changing head is a normal operation when bisecting */
  132. public boolean canCheckout() { return true; }
  133. /* Do not reset, checkout instead */
  134. public boolean canResetHead() { return false; }
  135. /* Actually it may make sense, but for now we err on the side of caution */
  136. public boolean canCommit() { return false; }
  137. public String getDescription() { return "Bisecting"; }
  138. };
  139. /**
  140. * @return true if changing HEAD is sane.
  141. */
  142. public abstract boolean canCheckout();
  143. /**
  144. * @return true if we can commit
  145. */
  146. public abstract boolean canCommit();
  147. /**
  148. * @return true if reset to another HEAD is considered SAFE
  149. */
  150. public abstract boolean canResetHead();
  151. /**
  152. * @return a human readable description of the state.
  153. */
  154. public abstract String getDescription();
  155. }