Thread (9 messages) flat view 9 messages, 3 authors, 2016-06-15
DORMANTno replies

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

From: Charles O'Farrell <hidden>
Date: 2016-06-15 22:45:12
Subsystem: the rest · Maintainer: Linus Torvalds

If attempted it will return a REJECTED_CURRENT_BRANCH Result.

Signed-off-by: Charles O'Farrell <redacted>
---
 .../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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help