remote-hg: add support for --dry-run
This needs a specific patch from Git not applied yet. Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Felipe Contreras committed
May 24, 2013 at 21:30 UTC
e3751a1763112b301f2269dd268190900d7ddd29
2 files changed
+65
-2
contrib/remote-helpers/git-remote-hg
+27
-2
@@ -557,6 +557,7 @@ def do_capabilities(parser):
557
if os.path.exists(path):
558
print "*import-marks %s" % path
559
print "*export-marks %s" % path
560
+ print "option"
561
562
print
563
@@ -724,6 +725,11 @@ def parse_commit(parser):
725
die('Unknown file command: %s' % line)
726
files[path] = f
727
728
+ # only export the commits if we are on an internal proxy repo
729
+ if dry_run and not peer:
730
+ parsed_refs[ref] = None
731
+ return
732
+
733
def getfilectx(repo, memctx, f):
734
of = files[f]
735
if 'deleted' in of:
@@ -809,7 +815,10 @@ def parse_reset(parser):
815
from_mark = parser.get_mark()
816
parser.next()
817
812
- rev = mark_to_rev(from_mark)
818
+ try:
819
+ rev = mark_to_rev(from_mark)
820
+ except KeyError:
821
+ rev = None
822
parsed_refs[ref] = rev
823
824
def parse_tag(parser):
@@ -1007,7 +1016,7 @@ def do_export(parser):
1016
need_fetch = False
1017
1018
for ref, node in parsed_refs.iteritems():
1010
- bnode = hgbin(node)
1019
+ bnode = hgbin(node) if node else None
1020
if ref.startswith('refs/heads/branches'):
1021
branch = ref[len('refs/heads/branches/'):]
1022
if branch in branches and bnode in branches[branch]:
@@ -1048,6 +1057,9 @@ def do_export(parser):
1057
1058
p_revs[bnode] = ref
1059
elif ref.startswith('refs/tags/'):
1060
+ if dry_run:
1061
+ print "ok %s" % ref
1062
+ continue
1063
tag = ref[len('refs/tags/'):]
1064
tag = hgref(tag)
1065
author, msg = parsed_tags.get(tag, (None, None))
@@ -1097,6 +1109,15 @@ def do_export(parser):
1109
1110
print
1111
1112
+def do_option(parser):
1113
+ global dry_run
1114
+ _, key, value = parser.line.split(' ')
1115
+ if key == 'dry-run':
1116
+ dry_run = (value == 'true')
1117
+ print 'ok'
1118
+ else:
1119
+ print 'unsupported'
1120
+
1121
def fix_path(alias, repo, orig_url):
1122
url = urlparse.urlparse(orig_url, 'file')
1123
if url.scheme != 'file' or os.path.isabs(url.path):
@@ -1113,6 +1134,7 @@ def main(args):
1134
global parsed_tags
1135
global filenodes
1136
global fake_bmark, hg_version
1137
+ global dry_run
1138
1139
alias = args[1]
1140
url = args[2]
@@ -1151,6 +1173,7 @@ def main(args):
1173
hg_version = tuple(int(e) for e in util.version().split('.'))
1174
except:
1175
hg_version = None
1176
+ dry_run = False
1177
1178
repo = get_repo(url, alias)
1179
prefix = 'refs/hg/%s' % alias
@@ -1175,6 +1198,8 @@ def main(args):
1198
do_import(parser)
1199
elif parser.check('export'):
1200
do_export(parser)
1201
+ elif parser.check('option'):
1202
+ do_option(parser)
1203
else:
1204
die('unhandled command: %s' % line)
1205
sys.stdout.flush()
contrib/remote-helpers/test-hg.sh
+38
@@ -594,6 +594,44 @@ test_expect_success 'remote big push fetch first' '
594
)
595
'
596
597
+test_expect_failure 'remote big push dry-run' '
598
+ test_when_finished "rm -rf hgrepo gitrepo*" &&
599
+
600
+ setup_big_push
601
+
602
+ (
603
+ cd gitrepo &&
604
+
605
+ check_push 0 --dry-run --all <<-EOF
606
+ master
607
+ good_bmark
608
+ branches/good_branch
609
+ new_bmark:new
610
+ branches/new_branch:new
611
+ bad_bmark1:non-fast-forward
612
+ bad_bmark2:non-fast-forward
613
+ branches/bad_branch:non-fast-forward
614
+ EOF
615
+
616
+ check_push 0 --dry-run master good_bmark new_bmark branches/good_branch branches/new_branch <<-EOF
617
+ master
618
+ good_bmark
619
+ branches/good_branch
620
+ new_bmark:new
621
+ branches/new_branch:new
622
+ EOF
623
+ ) &&
624
+
625
+ check_branch hgrepo default one &&
626
+ check_branch hgrepo good_branch "good branch" &&
627
+ check_branch hgrepo bad_branch "bad branch" &&
628
+ check_branch hgrepo new_branch '' &&
629
+ check_bookmark hgrepo good_bmark one &&
630
+ check_bookmark hgrepo bad_bmark1 one &&
631
+ check_bookmark hgrepo bad_bmark2 one &&
632
+ check_bookmark hgrepo new_bmark ''
633
+'
634
+
635
test_expect_success 'remote double failed push' '
636
test_when_finished "rm -rf hgrepo gitrepo*" &&
637