summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChangcheng Xiao <xchangcheng@google.com>2017-10-09 09:15:42 +0200
committerDave Borowitz <dborowitz@google.com>2017-10-09 15:08:40 +0000
commit733976750f61b696226fe9175ac3fe46301f24d6 (patch)
tree76255d16797be4db188089a06d90f01394429576
parent4d598b33428689932f82e83dfc4f8be0ebbce673 (diff)
Keep "refs/publish/*" as a synonym of "refs/for/*"
There are some tools, e.g. git-review, which are depending on this magic branch. We have to treat "refs/publish/*" as a synonym of "refs/for/*" in 2.15. See the corresponding change in master for details on further work. Change-Id: Ifcd35dfdc8eefe78e7173386ae6b8a8b2efa158d (cherry picked from commit 732e075ce860df57bcda239c08315e137011ede8)
-rw-r--r--gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/AbstractPushForReview.java10
-rw-r--r--gerrit-server/src/main/java/com/google/gerrit/server/git/receive/ReceiveCommits.java8
-rw-r--r--gerrit-server/src/main/java/com/google/gerrit/server/util/MagicBranch.java18
3 files changed, 34 insertions, 2 deletions
diff --git a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/AbstractPushForReview.java b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/AbstractPushForReview.java
index 95e4e16efd..928cd7ed7c 100644
--- a/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/AbstractPushForReview.java
+++ b/gerrit-acceptance-tests/src/test/java/com/google/gerrit/acceptance/git/AbstractPushForReview.java
@@ -1852,6 +1852,16 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest {
.isEqualTo(Iterables.getLast(commits).name());
}
+ @Test
+ public void pushToPublishMagicBranchIsAllowed() throws Exception {
+ // Push to "refs/publish/*" will be a synonym of "refs/for/*".
+ createChange("refs/publish/master");
+ PushOneCommit.Result result = pushTo("refs/publish/master");
+ result.assertOkStatus();
+ assertThat(result.getMessage())
+ .endsWith("Pushing to refs/publish/* is deprecated, use refs/for/* instead.\n");
+ }
+
private DraftInput newDraft(String path, int line, String message) {
DraftInput d = new DraftInput();
d.path = path;
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/receive/ReceiveCommits.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/receive/ReceiveCommits.java
index b7aa416c1f..3b27c06835 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/git/receive/ReceiveCommits.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/receive/ReceiveCommits.java
@@ -669,6 +669,11 @@ class ReceiveCommits {
}
addMessage("");
}
+
+ // TODO(xchangcheng): remove after migrating tools which are using this magic branch.
+ if (magicBranch != null && magicBranch.publish) {
+ addMessage("Pushing to refs/publish/* is deprecated, use refs/for/* instead.");
+ }
}
private void insertChangesAndPatchSets() {
@@ -1165,6 +1170,8 @@ class ReceiveCommits {
)
boolean draft;
+ boolean publish;
+
@Option(name = "--private", usage = "mark new/updated change as private")
boolean isPrivate;
@@ -1289,6 +1296,7 @@ class ReceiveCommits {
NotesMigration notesMigration) {
this.cmd = cmd;
this.draft = cmd.getRefName().startsWith(MagicBranch.NEW_DRAFT_CHANGE);
+ this.publish = cmd.getRefName().startsWith(MagicBranch.NEW_PUBLISH_CHANGE);
this.labelTypes = labelTypes;
this.notesMigration = notesMigration;
GeneralPreferencesInfo prefs = user.getAccount().getGeneralPreferencesInfo();
diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/util/MagicBranch.java b/gerrit-server/src/main/java/com/google/gerrit/server/util/MagicBranch.java
index 2088409ef5..e757d77a63 100644
--- a/gerrit-server/src/main/java/com/google/gerrit/server/util/MagicBranch.java
+++ b/gerrit-server/src/main/java/com/google/gerrit/server/util/MagicBranch.java
@@ -27,21 +27,27 @@ public final class MagicBranch {
private static final Logger log = LoggerFactory.getLogger(MagicBranch.class);
public static final String NEW_CHANGE = "refs/for/";
- // TODO: remove after 'repo' supports private/wip changes.
+ // TODO(xchangcheng): remove after 'repo' supports private/wip changes.
public static final String NEW_DRAFT_CHANGE = "refs/drafts/";
+ // TODO(xchangcheng): remove after migrating tools which are using this magic branch.
+ public static final String NEW_PUBLISH_CHANGE = "refs/publish/";
/** Extracts the destination from a ref name */
public static String getDestBranchName(String refName) {
String magicBranch = NEW_CHANGE;
if (refName.startsWith(NEW_DRAFT_CHANGE)) {
magicBranch = NEW_DRAFT_CHANGE;
+ } else if (refName.startsWith(NEW_PUBLISH_CHANGE)) {
+ magicBranch = NEW_PUBLISH_CHANGE;
}
return refName.substring(magicBranch.length());
}
/** Checks if the supplied ref name is a magic branch */
public static boolean isMagicBranch(String refName) {
- return refName.startsWith(NEW_DRAFT_CHANGE) || refName.startsWith(NEW_CHANGE);
+ return refName.startsWith(NEW_DRAFT_CHANGE)
+ || refName.startsWith(NEW_PUBLISH_CHANGE)
+ || refName.startsWith(NEW_CHANGE);
}
/** Returns the ref name prefix for a magic branch, {@code null} if the branch is not magic */
@@ -49,6 +55,9 @@ public final class MagicBranch {
if (refName.startsWith(NEW_DRAFT_CHANGE)) {
return NEW_DRAFT_CHANGE;
}
+ if (refName.startsWith(NEW_PUBLISH_CHANGE)) {
+ return NEW_PUBLISH_CHANGE;
+ }
if (refName.startsWith(NEW_CHANGE)) {
return NEW_CHANGE;
}
@@ -72,6 +81,11 @@ public final class MagicBranch {
if (result != Capable.OK) {
return result;
}
+ result = checkMagicBranchRef(NEW_PUBLISH_CHANGE, repo, project);
+ if (result != Capable.OK) {
+ return result;
+ }
+
return Capable.OK;
}