From 3d4a5a6d7e7d59b48bb6bfe61e30c7f6ae1e2f06 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 18 Jun 2019 15:22:09 -0500 Subject: [PATCH 1/5] Trivial cleanup By adding a helper function the code is more understandable. No functional changes. Signed-off-by: Felipe Contreras --- git-remote-hg | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/git-remote-hg b/git-remote-hg index e3afa97..0fd487d 100755 --- a/git-remote-hg +++ b/git-remote-hg @@ -1146,6 +1146,10 @@ def check_tip(ref, kind, name, heads): else: return tip in heads +def bookmark_is_fake(bmark, real_bmarks): + return bmark == fake_bmark or \ + (bmark == 'master' and bmark not in real_bmarks) + def do_export(parser): p_bmarks = [] p_revs = {} @@ -1196,8 +1200,7 @@ def do_export(parser): continue print "ok %s" % ref - if bmark != fake_bmark and \ - not (bmark == 'master' and bmark not in parser.repo._bookmarks): + if not bookmark_is_fake(bmark, parser.repo._bookmarks): p_bmarks.append((ref, bmark, old, new)) if peer: From a030d603ac763eb63ba1e1fc239a177152f7d142 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 18 Jun 2019 18:11:05 -0500 Subject: [PATCH 2/5] test: main: cleanup check_push() Return immediately after a failure. Signed-off-by: Felipe Contreras --- test/main.t | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/test/main.t b/test/main.t index d51021c..5574771 100755 --- a/test/main.t +++ b/test/main.t @@ -91,13 +91,10 @@ check_push () { grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1 ;; esac - test $ref_ret -ne 0 && echo "match for '$branch' failed" && break + test $ref_ret -ne 0 && echo "match for '$branch' failed" && return 2 done - if test $expected_ret -ne $ret || test $ref_ret -ne 0 - then - return 1 - fi + test $expected_ret -ne $ret && return 1 return 0 } From 4d01165b1bfabfde97349e44ee251b59c0178e8a Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 18 Jun 2019 18:18:00 -0500 Subject: [PATCH 3/5] test: main: fix check_push() bug We were not checking the kind correctly. Add a new case switch to avoid these issues. Signed-off-by: Felipe Contreras --- test/main.t | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/test/main.t b/test/main.t index 5574771..5464f4c 100755 --- a/test/main.t +++ b/test/main.t @@ -90,6 +90,9 @@ check_push () { '') grep "^ [a-f0-9]*\.\.[a-f0-9]* *${branch} -> ${branch}$" error || ref_ret=1 ;; + *) + echo "BUG: wrong kind '$kind'" && return 3 + ;; esac test $ref_ret -ne 0 && echo "match for '$branch' failed" && return 2 done @@ -675,7 +678,7 @@ test_expect_success 'remote big push fetch first' ' master good_bmark bad_bmark:fetch-first - branches/bad_branch:festch-first + branches/bad_branch:fetch-first EOF git fetch && From d11509cab754e3d487aaed5f7a04825de42c5d15 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 18 Jun 2019 18:45:03 -0500 Subject: [PATCH 4/5] test: main: trivial cleanup Signed-off-by: Felipe Contreras --- test/main.t | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/main.t b/test/main.t index 5464f4c..700e4de 100755 --- a/test/main.t +++ b/test/main.t @@ -621,11 +621,11 @@ test_expect_success 'remote big push' ' check_branch hgrepo default one && check_branch hgrepo good_branch "good branch" && check_branch hgrepo bad_branch "bad branch" && - check_branch hgrepo new_branch '' && + check_branch hgrepo new_branch && check_bookmark hgrepo good_bmark one && check_bookmark hgrepo bad_bmark1 one && check_bookmark hgrepo bad_bmark2 one && - check_bookmark hgrepo new_bmark '' + check_bookmark hgrepo new_bmark ' test_expect_success 'remote big push fetch first' ' @@ -753,11 +753,11 @@ test_expect_success 'remote big push dry-run' ' check_branch hgrepo default one && check_branch hgrepo good_branch "good branch" && check_branch hgrepo bad_branch "bad branch" && - check_branch hgrepo new_branch '' && + check_branch hgrepo new_branch && check_bookmark hgrepo good_bmark one && check_bookmark hgrepo bad_bmark1 one && check_bookmark hgrepo bad_bmark2 one && - check_bookmark hgrepo new_bmark '' + check_bookmark hgrepo new_bmark ' test_expect_success 'remote double failed push' ' From b3cdbe8e96dc753610db4936385afa1de1aa39a6 Mon Sep 17 00:00:00 2001 From: Felipe Contreras Date: Tue, 18 Jun 2019 18:50:52 -0500 Subject: [PATCH 5/5] Allow --force --dry-run No reason for it not to work. Signed-off-by: Felipe Contreras --- git-remote-hg | 2 +- test/main.t | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/git-remote-hg b/git-remote-hg index 0fd487d..023bbb4 100755 --- a/git-remote-hg +++ b/git-remote-hg @@ -1243,7 +1243,7 @@ def do_export(parser): return if dry_run: - if peer and not force_push: + if peer: checkheads(parser.repo, peer, p_revs) print return diff --git a/test/main.t b/test/main.t index 700e4de..10456ee 100755 --- a/test/main.t +++ b/test/main.t @@ -760,6 +760,36 @@ test_expect_success 'remote big push dry-run' ' check_bookmark hgrepo new_bmark ' +test_expect_success 'remote big push force dry-run' ' + test_when_finished "rm -rf hgrepo gitrepo*" && + + setup_big_push + + ( + cd gitrepo && + + check_push 0 --force --dry-run --all <<-\EOF + master + good_bmark + branches/good_branch + new_bmark:new + branches/new_branch:new + bad_bmark1:forced-update + bad_bmark2:forced-update + branches/bad_branch:forced-update + EOF + ) && + + check_branch hgrepo default one && + check_branch hgrepo good_branch "good branch" && + check_branch hgrepo bad_branch "bad branch" && + check_branch hgrepo new_branch && + check_bookmark hgrepo good_bmark one && + check_bookmark hgrepo bad_bmark1 one && + check_bookmark hgrepo bad_bmark2 one && + check_bookmark hgrepo new_bmark +' + test_expect_success 'remote double failed push' ' test_when_finished "rm -rf hgrepo gitrepo*" &&