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

[JGIT PATCH 1/4] Ensured that RefUpdate cannot delete current branch

From
Charles O'Farrell <charleso@charleso.org>
Date
Aug 22, 2008, 22:45 UTC
Message-ID
<1219445147-6801-2-git-send-email-charleso@charleso.org>
In-Reply-To
<1219445147-6801-1-git-send-email-charleso@charleso.org>
If attempted it will return a REJECTED_CURRENT_BRANCH Result.
Signed-off-by: Charles O'Farrell <charleso@charleso.org>
---
 .../src/org/spearce/jgit/lib/RefUpdate.java        |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java b/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
index ca77b75..aa2cecb 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/RefUpdate.java
@@ -110,6 +110,13 @@
 		REJECTED,
 
 		/**
+		 * Rejected because trying to delete the current branch.
+		 * <p>
+		 * Has no meaning for update.
+		 */
+		REJECTED_CURRENT_BRANCH,
+
+		/**
 		 * The ref was probably not updated because of I/O error.
 		 * <p>
 		 * Unexpected I/O error occurred when writing new ref. Such error may
@@ -323,6 +330,9 @@ public Result update(final RevWalk walk) throws IOException {
 	 * @throws IOException
 	 */
 	public Result delete() throws IOException {
+		if (name.substring(Constants.R_HEADS.length()).equals(
+				db.getRepository().getBranch()))
+			return Result.REJECTED_CURRENT_BRANCH;
 		try {
 			return updateImpl(new RevWalk(db.getRepository()),
 					new DeleteStore());
-- 
1.6.0.49.gea35
Previous: Charles O'FarrellNext: Charles O'Farrell
Message 2 of 9 in “Branch deletion testing and bug fixes”
  1. 0/4 Branch deletion testing and bug fixesCharles O'Farrell, Aug 22, 2008
  2. 1/4 Ensured that RefUpdate cannot delete current branchCharles O'Farrell, Aug 22, 2008
  3. 2/4 Fixed bug where RefUpdate didn't delete identical HEAD branchCharles O'Farrell, Aug 22, 2008
  4. 3/4 Added test for RefUpdate branch deletionCharles O'Farrell, Aug 22, 2008
  5. 4/4 Added extra javadoc for delete to significant RefUpdate resultsCharles O'Farrell, Aug 22, 2008
  6. Shawn O. PearceAug 22, 2008
  7. Robin RosenbergAug 22, 2008
  8. Shawn O. PearceAug 22, 2008
  9. Shawn O. PearceAug 22, 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.