git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH] Detect repository states according to post Git 1.5

From
Robin Rosenberg <robin.rosenberg.lists@dewire.com>
Date
Oct 21, 2008, 20:13 UTC
Message-ID
<200810212213.42294.robin.rosenberg.lists@dewire.com>
In-Reply-To
<f299b4f30810211109q7f2919f2r1d5cd8faf0048154@mail.gmail.com>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
---

Seems we need this patch too in order to detect repository states. The new resolution is more granular that before, though I suggest that one should be restrictive when interpreting the state and not assume that these states are the only ones. The methods on RepositoryState are the /only/ valid ways of deciding what to, or not to, do. This implies we need to extend this class somewhat, but I'm no hurry yet so we can think about what methods we need.

 .../src/org/spearce/jgit/lib/Repository.java       |   17 +++++++++++++
 .../src/org/spearce/jgit/lib/RepositoryState.java  |   25 +++++++++++++++++++-
 2 files changed, 41 insertions(+), 1 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
index dfce1b8..26748e2 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/Repository.java
@@ -1017,14 +1017,31 @@ public GitIndex getIndex() throws IOException {
 	 * @return an important state
 	 */
 	public RepositoryState getRepositoryState() {
+		// Pre Git-1.6 logic
 		if (new File(getWorkDir(), ".dotest").exists())
 			return RepositoryState.REBASING;
 		if (new File(gitDir,".dotest-merge").exists())
 			return RepositoryState.REBASING_INTERACTIVE;
+
+		// From 1.6 onwards
+		if (new File(getDirectory(),"rebase-apply/rebasing").exists())
+			return RepositoryState.REBASING_REBASING;
+		if (new File(getDirectory(),"rebase-apply/applying").exists())
+			return RepositoryState.APPLY;
+		if (new File(getDirectory(),"rebase-apply").exists())
+			return RepositoryState.REBASING;
+
+		if (new File(getDirectory(),"rebase-merge/interactive").exists())
+			return RepositoryState.REBASING_INTERACTIVE;
+		if (new File(getDirectory(),"rebase-merge").exists())
+			return RepositoryState.REBASING_MERGE;
+
+		// Both versions
 		if (new File(gitDir,"MERGE_HEAD").exists())
 			return RepositoryState.MERGING;
 		if (new File(gitDir,"BISECT_LOG").exists())
 			return RepositoryState.BISECTING;
+
 		return RepositoryState.SAFE;
 	}
 
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryState.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryState.java
index c32c381..a916924 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryState.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RepositoryState.java
@@ -40,6 +40,9 @@
 /**
  * Important state of the repository that affects what can and cannot bed
  * done. This is things like unhandled conflicted merges and unfinished rebase.
+ *
+ * The granularity and set of states are somewhat arbitrary. The methods
+ * on the state are the only supported means of deciding what to do.
  */
 public enum RepositoryState {
 	/**
@@ -62,7 +65,7 @@
 	},
 
 	/**
-	 * An unfinished rebase. Must resolve, skip or abort before normal work can take place
+	 * An unfinished rebase or am. Must resolve, skip or abort before normal work can take place
 	 */
 	REBASING {
 		public boolean canCheckout() { return false; }
@@ -72,6 +75,26 @@
 	},
 
 	/**
+	 * An unfinished rebase. Must resolve, skip or abort before normal work can take place
+	 */
+	REBASING_REBASING {
+		public boolean canCheckout() { return false; }
+		public boolean canResetHead() { return false; }
+		public boolean canCommit() { return true; }
+		public String getDescription() { return "Rebase"; }
+	},
+
+	/**
+	 * An unfinished apply. Must resolve, skip or abort before normal work can take place
+	 */
+	APPLY {
+		public boolean canCheckout() { return false; }
+		public boolean canResetHead() { return false; }
+		public boolean canCommit() { return true; }
+		public String getDescription() { return "Apply mailbox"; }
+	},
+
+	/**
 	 * An unfinished rebase with merge. Must resolve, skip or abort before normal work can take place
 	 */
 	REBASING_MERGE {
-- 
1.6.0.2.308.gef4a
Previous: Robin Rosenberg
Message 6 of 6 in “git property page for project properties.”
  1. git property page for project properties.Tomi Pakarinen, Oct 20, 2008
  2. Robin RosenbergOct 21, 2008
  3. Robin RosenbergOct 21, 2008
  4. Tomi PakarinenOct 21, 2008
  5. Robin RosenbergOct 21, 2008
  6. Detect repository states according to post Git 1.5Robin Rosenberg, Oct 21, 2008

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.