summaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit
diff options
context:
space:
mode:
authorShawn Pearce <sop@google.com>2014-11-24 16:40:54 -0800
committerShawn Pearce <spearce@spearce.org>2014-11-29 10:49:04 -0800
commitd1b627ed834097ec468491905879b7fca3e2f5fb (patch)
treed224415086a3da1b6450fe8dece3c1803c6b9917 /org.eclipse.jgit
parent485b751b2fb74b5ea11582787d859c6cd59b65d2 (diff)
downloadjgit-d1b627ed834097ec468491905879b7fca3e2f5fb.tar.gz
jgit-d1b627ed834097ec468491905879b7fca3e2f5fb.zip
Honor git-core meaning of receive.denyDeletes allowing tag deletion
receive.denyDeletes parameter refers only to branch: http://thread.gmane.org/gmane.comp.version-control.git/99746 Bug: 412640 Change-Id: Ief3fa6abc0c9a18ba0a671ff9854432cec480c4f
Diffstat (limited to 'org.eclipse.jgit')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java46
1 files changed, 36 insertions, 10 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
index 83d063e4a6..0475d2792a 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/transport/BaseReceivePack.java
@@ -168,7 +168,8 @@ public abstract class BaseReceivePack {
private boolean allowCreates;
/** Should an incoming transfer permit delete requests? */
- private boolean allowDeletes;
+ private boolean allowAnyDeletes;
+ private boolean allowBranchDeletes;
/** Should an incoming transfer permit non-fast-forward requests? */
private boolean allowNonFastForwards;
@@ -258,7 +259,8 @@ public abstract class BaseReceivePack {
final ReceiveConfig cfg = db.getConfig().get(ReceiveConfig.KEY);
objectChecker = cfg.newObjectChecker();
allowCreates = cfg.allowCreates;
- allowDeletes = cfg.allowDeletes;
+ allowAnyDeletes = true;
+ allowBranchDeletes = cfg.allowDeletes;
allowNonFastForwards = cfg.allowNonFastForwards;
allowOfsDelta = cfg.allowOfsDelta;
advertiseRefsHook = AdvertiseRefsHook.DEFAULT;
@@ -541,7 +543,7 @@ public abstract class BaseReceivePack {
/** @return true if the client can request refs to be deleted. */
public boolean isAllowDeletes() {
- return allowDeletes;
+ return allowAnyDeletes;
}
/**
@@ -549,7 +551,25 @@ public abstract class BaseReceivePack {
* true to permit delete ref commands to be processed.
*/
public void setAllowDeletes(final boolean canDelete) {
- allowDeletes = canDelete;
+ allowAnyDeletes = canDelete;
+ }
+
+ /**
+ * @return true if the client can delete from {@code refs/heads/}.
+ * @since 3.6
+ */
+ public boolean isAllowBranchDeletes() {
+ return allowBranchDeletes;
+ }
+
+ /**
+ * @param canDelete
+ * true to permit deletion of branches from the
+ * {@code refs/heads/} namespace.
+ * @since 3.6
+ */
+ public void setAllowBranchDeletes(boolean canDelete) {
+ allowBranchDeletes = canDelete;
}
/**
@@ -1143,12 +1163,18 @@ public abstract class BaseReceivePack {
if (cmd.getResult() != Result.NOT_ATTEMPTED)
continue;
- if (cmd.getType() == ReceiveCommand.Type.DELETE
- && !isAllowDeletes()) {
- // Deletes are not supported on this repository.
- //
- cmd.setResult(Result.REJECTED_NODELETE);
- continue;
+ if (cmd.getType() == ReceiveCommand.Type.DELETE) {
+ if (!isAllowDeletes()) {
+ // Deletes are not supported on this repository.
+ cmd.setResult(Result.REJECTED_NODELETE);
+ continue;
+ }
+ if (!isAllowBranchDeletes()
+ && ref.getName().startsWith(Constants.R_HEADS)) {
+ // Branches cannot be deleted, but other refs can.
+ cmd.setResult(Result.REJECTED_NODELETE);
+ continue;
+ }
}
if (cmd.getType() == ReceiveCommand.Type.CREATE) {