transport-helper: add no-private-update capability

Since 664059fb (transport-helper: update remote helper namespace, 2013-04-17), a 'push' operation on a remote helper updates the private ref by default. This is often a good thing, but it can also be desirable to disable this update to force the next 'pull' to re-import the pushed revisions. Allow remote-helpers to disable the automatic update by introducing a new capability. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matthieu Moy committed Sep 3, 2013 at 17:45 UTC 597b831afb25303218ac60115ac86dd8879e3ce3
4 files changed +22 -2
Documentation/gitremote-helpers.txt
+5
@@ -120,6 +120,11 @@ connecting (see the 'connect' command under COMMANDS).
120 When choosing between 'push' and 'export', Git prefers 'push'.
121 Other frontends may have some other order of preference.
122
123 +'no-private-update'::
124 + When using the 'refspec' capability, git normally updates the
125 + private ref on successful push. This update is disabled when
126 + the remote-helper declares the capability 'no-private-update'.
127 +
128
129 Capabilities for Fetching
130 ^^^^^^^^^^^^^^^^^^^^^^^^^
git-remote-testgit.sh
+1
@@ -38,6 +38,7 @@ do
38 echo "*export-marks $gitmarks"
39 fi
40 test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags"
41 + test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update"
42 echo
43 ;;
44 list)
t/t5801-remote-helpers.sh
+11
@@ -182,6 +182,17 @@ test_expect_success 'push update refs' '
182 )
183 '
184
185 +test_expect_success 'push update refs disabled by no-private-update' '
186 + (cd local &&
187 + echo more-update >>file &&
188 + git commit -a -m more-update &&
189 + git rev-parse --verify testgit/origin/heads/update >expect &&
190 + GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE=t git push origin update &&
191 + git rev-parse --verify testgit/origin/heads/update >actual &&
192 + test_cmp expect actual
193 + )
194 +'
195 +
196 test_expect_success 'push update refs failure' '
197 (cd local &&
198 git checkout update &&
transport-helper.c
+5 -2
@@ -27,7 +27,8 @@ struct helper_data {
27 push : 1,
28 connect : 1,
29 signed_tags : 1,
30 - no_disconnect_req : 1;
30 + no_disconnect_req : 1,
31 + no_private_update : 1;
32 char *export_marks;
33 char *import_marks;
34 /* These go from remote name (as in "list") to private name */
@@ -205,6 +206,8 @@ static struct child_process *get_helper(struct transport *transport)
206 strbuf_addstr(&arg, "--import-marks=");
207 strbuf_addstr(&arg, capname + strlen("import-marks "));
208 data->import_marks = strbuf_detach(&arg, NULL);
209 + } else if (!prefixcmp(capname, "no-private-update")) {
210 + data->no_private_update = 1;
211 } else if (mandatory) {
212 die("Unknown mandatory capability %s. This remote "
213 "helper probably needs newer version of Git.",
@@ -723,7 +726,7 @@ static void push_update_refs_status(struct helper_data *data,
726 if (push_update_ref_status(&buf, &ref, remote_refs))
727 continue;
728
726 - if (!data->refspecs)
729 + if (!data->refspecs || data->no_private_update)
730 continue;
731
732 /* propagate back the update to the remote namespace */