From 22229dd738ae3d0752b293cca1cf948c1d154cfa Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 18 Jun 2019 15:25:28 -0500 Subject: [PATCH] Only report success after successful push Otherwise git core will update the namespaced refs, and show success to the user, even in the case of a crash. Signed-off-by: Felipe Contreras --- git-remote-hg | 31 ++++++++++++++++++++++--------- test/main.t | 27 ++++++++++++--------------- 2 files changed, 34 insertions(+), 24 deletions(-) diff --git a/git-remote-hg b/git-remote-hg index 071be43..9162953 100755 --- a/git-remote-hg +++ b/git-remote-hg @@ -1198,6 +1198,7 @@ def bookmark_is_fake(bmark, real_bmarks): def do_export(parser): p_bmarks = [] p_revs = {} + ok_refs = [] parser.next() @@ -1236,7 +1237,7 @@ def do_export(parser): continue p_revs[bnode] = ref - print("ok %s" % ref) + ok_refs.append(ref) elif ref.startswith('refs/heads/'): g_bmark = ref[len('refs/heads/'):] bmark = g_bmark.encode() @@ -1246,8 +1247,9 @@ def do_export(parser): if old == new: continue - print("ok %s" % ref) - if not bookmark_is_fake(bmark, parser.repo._bookmarks): + if bookmark_is_fake(bmark, parser.repo._bookmarks): + ok_refs.append(ref) + else: p_bmarks.append((ref, bmark, old, new)) if peer: @@ -1261,7 +1263,7 @@ def do_export(parser): p_revs[bnode] = ref elif ref.startswith('refs/tags/'): if dry_run: - print("ok %s" % ref) + ok_refs.append(ref) continue tag = ref[len('refs/tags/'):] tag = hgref(tag) @@ -1280,7 +1282,7 @@ def do_export(parser): fp.write(b'%s %s\n' % (node, tag)) fp.close() p_revs[bnode] = ref - print("ok %s" % ref) + ok_refs.append(ref) else: # transport-helper/fast-export bugs continue @@ -1290,8 +1292,11 @@ def do_export(parser): return if dry_run: - if peer: - checkheads(parser.repo, peer, p_revs) + if not peer or checkheads(parser.repo, peer, p_revs): + for ref, bmark, old, new in p_bmarks: + print("ok %s" % ref) + for ref in ok_refs: + print("ok %s" % ref) print("") return @@ -1306,14 +1311,22 @@ def do_export(parser): for ref, bmark, old, new in p_bmarks: if force_push: old = remote_bmarks.get(bmark, b'') - if not peer.pushkey(b'bookmarks', bmark, old, new): + if peer.pushkey(b'bookmarks', bmark, old, new): + print("ok %s" % ref) + else: print("error %s" % ref) else: # update local bookmarks for ref, bmark, old, new in p_bmarks: - if not bookmarks.pushbookmark(parser.repo, bmark, old, new): + if bookmarks.pushbookmark(parser.repo, bmark, old, new): + print("ok %s" % ref) + else: print("error %s" % ref) + # update rest of the refs + for ref in ok_refs: + print("ok %s" % ref) + print("") def do_option(parser): diff --git a/test/main.t b/test/main.t index a3c48bd..249ae39 100755 --- a/test/main.t +++ b/test/main.t @@ -607,17 +607,14 @@ test_expect_success 'remote big push' ' cd gitrepo && check_push 1 --all <<-\EOF - master - good_bmark - branches/good_branch - new_bmark:new - branches/new_branch:new bad_bmark1:non-fast-forward bad_bmark2:non-fast-forward branches/bad_branch:non-fast-forward EOF ) && + check gitrepo origin/master one && + check gitrepo hg/origin/bookmarks/master one && check_branch hgrepo default one && check_branch hgrepo good_branch "good branch" && check_branch hgrepo bad_branch "bad branch" && @@ -645,8 +642,6 @@ test_expect_success 'remote big push fetch first' ' cd gitrepo && check_push 1 --all <<-\EOF && - master - good_bmark bad_bmark1:fetch-first branches/bad_branch:fetch-first EOF @@ -654,12 +649,13 @@ test_expect_success 'remote big push fetch first' ' git fetch && check_push 1 --all <<-\EOF - master - good_bmark bad_bmark1:non-fast-forward branches/bad_branch:non-fast-forward EOF - ) + ) && + + check gitrepo origin/master one && + check gitrepo hg/origin/bookmarks/master one ' test_expect_success 'remote big push force' ' @@ -682,6 +678,8 @@ test_expect_success 'remote big push force' ' EOF ) && + check gitrepo origin/master two && + check gitrepo hg/origin/bookmarks/master two && check_branch hgrepo default four && check_branch hgrepo good_branch eight && check_branch hgrepo bad_branch nine && @@ -701,11 +699,6 @@ test_expect_success 'remote big push dry-run' ' cd gitrepo && check_push 1 --dry-run --all <<-\EOF && - master - good_bmark - branches/good_branch - new_bmark:new - branches/new_branch:new bad_bmark1:non-fast-forward bad_bmark2:non-fast-forward branches/bad_branch:non-fast-forward @@ -720,6 +713,8 @@ test_expect_success 'remote big push dry-run' ' EOF ) && + check gitrepo origin/master one && + check gitrepo hg/origin/bookmarks/master one && check_branch hgrepo default one && check_branch hgrepo good_branch "good branch" && check_branch hgrepo bad_branch "bad branch" && @@ -750,6 +745,8 @@ test_expect_success 'remote big push force dry-run' ' EOF ) && + check gitrepo origin/master one && + check gitrepo hg/origin/bookmarks/master one && check_branch hgrepo default one && check_branch hgrepo good_branch "good branch" && check_branch hgrepo bad_branch "bad branch" &&