From a21455ae664c1a29c157e2bc5ea3abe8e2699eca Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 31 Oct 2013 03:36:29 -0600 Subject: transport-helper: mismerge fix Commit 9c51558 (transport-helper: trivial code shuffle) moved these lines above, but 99d9ec0 (Merge branch 'fc/transport-helper-no-refspec') had a wrong merge conflict and readded them. Reported-by: Richard Hansen Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- transport-helper.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/transport-helper.c b/transport-helper.c index b32e2d64d..985eeea59 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -874,9 +874,6 @@ static int push_refs_with_export(struct transport *transport, } free(private); - if (ref->deletion) - die("remote-helpers do not support ref deletion"); - if (ref->peer_ref) { if (strcmp(ref->peer_ref->name, ref->name)) die("remote-helpers do not support old:new syntax"); -- cgit v1.2.1 From 5a75353fe381b344a33d7a89f7803e4a24d2ddcf Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Thu, 31 Oct 2013 03:36:37 -0600 Subject: transport-helper: don't update refs in dry-run The remote helper namespace should not be updated. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- transport-helper.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/transport-helper.c b/transport-helper.c index 985eeea59..d05fc7c27 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -727,7 +727,8 @@ static int push_update_ref_status(struct strbuf *buf, } static void push_update_refs_status(struct helper_data *data, - struct ref *remote_refs) + struct ref *remote_refs, + int flags) { struct strbuf buf = STRBUF_INIT; struct ref *ref = remote_refs; @@ -741,7 +742,7 @@ static void push_update_refs_status(struct helper_data *data, if (push_update_ref_status(&buf, &ref, remote_refs)) continue; - if (!data->refspecs || data->no_private_update) + if (flags & TRANSPORT_PUSH_DRY_RUN || !data->refspecs || data->no_private_update) continue; /* propagate back the update to the remote namespace */ @@ -832,7 +833,7 @@ static int push_refs_with_push(struct transport *transport, sendline(data, &buf); strbuf_release(&buf); - push_update_refs_status(data, remote_refs); + push_update_refs_status(data, remote_refs, flags); return 0; } @@ -886,7 +887,7 @@ static int push_refs_with_export(struct transport *transport, if (finish_command(&exporter)) die("Error while running fast-export"); - push_update_refs_status(data, remote_refs); + push_update_refs_status(data, remote_refs, flags); return 0; } -- cgit v1.2.1 From 510fa6f5188d715050899eee221c739f1c0a8b12 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 12 Nov 2013 14:56:56 -0600 Subject: transport-helper: add 'force' to 'export' helpers Otherwise they cannot know when to force the push or not (other than hacks). Tests-by: Richard Hansen Documentation-by: Richard Hansen Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- Documentation/gitremote-helpers.txt | 4 ++++ git-remote-testgit.sh | 18 ++++++++++++++++++ t/t5801-remote-helpers.sh | 13 +++++++++++++ transport-helper.c | 5 +++++ 4 files changed, 40 insertions(+) diff --git a/Documentation/gitremote-helpers.txt b/Documentation/gitremote-helpers.txt index f1f4ca972..e75699ce1 100644 --- a/Documentation/gitremote-helpers.txt +++ b/Documentation/gitremote-helpers.txt @@ -437,6 +437,10 @@ set by Git if the remote helper has the 'option' capability. 'option check-connectivity' \{'true'|'false'\}:: Request the helper to check connectivity of a clone. +'option force' \{'true'|'false'\}:: + Request the helper to perform a force update. Defaults to + 'false'. + SEE ALSO -------- linkgit:git-remote[1] diff --git a/git-remote-testgit.sh b/git-remote-testgit.sh index 6d2f282d3..1c006a051 100755 --- a/git-remote-testgit.sh +++ b/git-remote-testgit.sh @@ -15,6 +15,8 @@ test -z "$refspec" && prefix="refs" export GIT_DIR="$url/.git" +force= + mkdir -p "$dir" if test -z "$GIT_REMOTE_TESTGIT_NO_MARKS" @@ -39,6 +41,7 @@ do fi test -n "$GIT_REMOTE_TESTGIT_SIGNED_TAGS" && echo "signed-tags" test -n "$GIT_REMOTE_TESTGIT_NO_PRIVATE_UPDATE" && echo "no-private-update" + echo 'option' echo ;; list) @@ -93,6 +96,7 @@ do before=$(git for-each-ref --format=' %(refname) %(objectname) ') git fast-import \ + ${force:+--force} \ ${testgitmarks:+"--import-marks=$testgitmarks"} \ ${testgitmarks:+"--export-marks=$testgitmarks"} \ --quiet @@ -115,6 +119,20 @@ do echo ;; + option\ *) + read cmd opt val <<-EOF + $line + EOF + case $opt in + force) + test $val = "true" && force="true" || force= + echo "ok" + ;; + *) + echo "unsupported" + ;; + esac + ;; '') exit ;; diff --git a/t/t5801-remote-helpers.sh b/t/t5801-remote-helpers.sh index 613f69a25..c33cc2580 100755 --- a/t/t5801-remote-helpers.sh +++ b/t/t5801-remote-helpers.sh @@ -94,6 +94,19 @@ test_expect_failure 'push new branch with old:new refspec' ' compare_refs local HEAD server refs/heads/new-refspec ' +test_expect_success 'forced push' ' + (cd local && + git checkout -b force-test && + echo content >> file && + git commit -a -m eight && + git push origin force-test && + echo content >> file && + git commit -a --amend -m eight-modified && + git push --force origin force-test + ) && + compare_refs local refs/heads/force-test server refs/heads/force-test +' + test_expect_success 'cloning without refspec' ' GIT_REMOTE_TESTGIT_REFSPEC="" \ git clone "testgit::${PWD}/server" local2 2>error && diff --git a/transport-helper.c b/transport-helper.c index d05fc7c27..bcf5469bc 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -854,6 +854,11 @@ static int push_refs_with_export(struct transport *transport, die("helper %s does not support dry-run", data->name); } + if (flags & TRANSPORT_PUSH_FORCE) { + if (set_helper_option(transport, "force", "true") != 0) + warning("helper %s does not support 'force'", data->name); + } + helper = get_helper(transport); write_constant(helper->in, "export\n"); -- cgit v1.2.1 From f9e3c6bebb89de12f2dfdaa1899cb22e9ef32542 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 12 Nov 2013 14:56:57 -0600 Subject: transport-helper: check for 'forced update' message So the remote-helpers can tell us when a forced push was needed. Signed-off-by: Felipe Contreras Signed-off-by: Junio C Hamano --- transport-helper.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/transport-helper.c b/transport-helper.c index bcf5469bc..abe4c3c2c 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -643,7 +643,7 @@ static int push_update_ref_status(struct strbuf *buf, struct ref *remote_refs) { char *refname, *msg; - int status; + int status, forced = 0; if (!prefixcmp(buf->buf, "ok ")) { status = REF_STATUS_OK; @@ -701,6 +701,11 @@ static int push_update_ref_status(struct strbuf *buf, free(msg); msg = NULL; } + else if (!strcmp(msg, "forced update")) { + forced = 1; + free(msg); + msg = NULL; + } } if (*ref) @@ -722,6 +727,7 @@ static int push_update_ref_status(struct strbuf *buf, } (*ref)->status = status; + (*ref)->forced_update = forced; (*ref)->remote_status = msg; return !(status == REF_STATUS_OK); } -- cgit v1.2.1 From cf31f70c088a314a9d11a4106d2fe1036051890a Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 21 Feb 2014 10:55:59 +0100 Subject: transport-helper.c: do not overwrite forced bit If the the transport helper says it was a forced update, then it is a forced update. It is however possible that an update is forced without the transport-helper knowing about it, namely because some higher up code had objections to the update and needed forcing in order to let it through to the transport helper. In other words, it does not necessarily mean the update was *not* forced, when the helper did not say "forced update". Signed-off-by: Max Horn Signed-off-by: Junio C Hamano --- transport-helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/transport-helper.c b/transport-helper.c index abe4c3c2c..705dce7e0 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -727,7 +727,7 @@ static int push_update_ref_status(struct strbuf *buf, } (*ref)->status = status; - (*ref)->forced_update = forced; + (*ref)->forced_update |= forced; (*ref)->remote_status = msg; return !(status == REF_STATUS_OK); } -- cgit v1.2.1 From fdec195f893ac81298b4e108f787172ad0c19a55 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 12 Nov 2013 14:56:59 -0600 Subject: test-hg.sh: tests are now expected to pass Signed-off-by: Richard Hansen Signed-off-by: Junio C Hamano --- contrib/remote-helpers/test-hg.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/remote-helpers/test-hg.sh b/contrib/remote-helpers/test-hg.sh index 72f745d63..aacd8a952 100755 --- a/contrib/remote-helpers/test-hg.sh +++ b/contrib/remote-helpers/test-hg.sh @@ -599,7 +599,7 @@ test_expect_success 'remote big push fetch first' ' ) ' -test_expect_failure 'remote big push force' ' +test_expect_success 'remote big push force' ' test_when_finished "rm -rf hgrepo gitrepo*" && setup_big_push @@ -629,7 +629,7 @@ test_expect_failure 'remote big push force' ' check_bookmark hgrepo new_bmark six ' -test_expect_failure 'remote big push dry-run' ' +test_expect_success 'remote big push dry-run' ' test_when_finished "rm -rf hgrepo gitrepo*" && setup_big_push -- cgit v1.2.1 From a7cb1276cc263446b19b43d3a7784cbc72f84e28 Mon Sep 17 00:00:00 2001 From: Richard Hansen Date: Tue, 12 Nov 2013 02:03:28 -0500 Subject: remote-bzr: support the new 'force' option Signed-off-by: Richard Hansen Acked-by: Felipe Contreras Signed-off-by: Junio C Hamano --- contrib/remote-helpers/git-remote-bzr | 31 ++++++++++++++++++++++++++++++- contrib/remote-helpers/test-bzr.sh | 22 +++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/contrib/remote-helpers/git-remote-bzr b/contrib/remote-helpers/git-remote-bzr index 054161ae2..f1ba477fb 100755 --- a/contrib/remote-helpers/git-remote-bzr +++ b/contrib/remote-helpers/git-remote-bzr @@ -685,7 +685,8 @@ def do_export(parser): peer = bzrlib.branch.Branch.open(peers[name], possible_transports=transports) try: - peer.bzrdir.push_branch(branch, revision_id=revid) + peer.bzrdir.push_branch(branch, revision_id=revid, + overwrite=force) except bzrlib.errors.DivergedBranches: print "error %s non-fast forward" % ref continue @@ -719,8 +720,32 @@ def do_capabilities(parser): print "*import-marks %s" % path print "*export-marks %s" % path + print "option" print +class InvalidOptionValue(Exception): + pass + +def get_bool_option(val): + if val == 'true': + return True + elif val == 'false': + return False + else: + raise InvalidOptionValue() + +def do_option(parser): + global force + opt, val = parser[1:3] + try: + if opt == 'force': + force = get_bool_option(val) + print 'ok' + else: + print 'unsupported' + except InvalidOptionValue: + print "error '%s' is not a valid value for option '%s'" % (val, opt) + def ref_is_valid(name): return not True in [c in name for c in '~^: \\'] @@ -883,6 +908,7 @@ def main(args): global is_tmp global branches, peers global transports + global force alias = args[1] url = args[2] @@ -896,6 +922,7 @@ def main(args): branches = {} peers = {} transports = [] + force = False if alias[5:] == url: is_tmp = True @@ -931,6 +958,8 @@ def main(args): do_import(parser) elif parser.check('export'): do_export(parser) + elif parser.check('option'): + do_option(parser) else: die('unhandled command: %s' % line) sys.stdout.flush() diff --git a/contrib/remote-helpers/test-bzr.sh b/contrib/remote-helpers/test-bzr.sh index 5c5025178..ae26dbb2e 100755 --- a/contrib/remote-helpers/test-bzr.sh +++ b/contrib/remote-helpers/test-bzr.sh @@ -65,13 +65,33 @@ test_expect_success 'pushing' ' test_cmp expected actual ' +test_expect_success 'forced pushing' ' + ( + cd gitrepo && + echo three-new >content && + git commit -a --amend -m three-new && + git push -f + ) && + + ( + cd bzrrepo && + # the forced update overwrites the bzr branch but not the bzr + # working directory (it tries to merge instead) + bzr revert + ) && + + echo three-new >expected && + cat bzrrepo/content >actual && + test_cmp expected actual +' + test_expect_success 'roundtrip' ' ( cd gitrepo && git pull && git log --format="%s" -1 origin/master >actual ) && - echo three >expected && + echo three-new >expected && test_cmp expected actual && (cd gitrepo && git push && git pull) && -- cgit v1.2.1