Skip to content

Commit

Permalink
remote-hg: add support for --dry-run
Browse files Browse the repository at this point in the history
This needs a specific patch from Git not applied yet.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
  • Loading branch information
felipec committed May 21, 2013
1 parent 181a151 commit 6c3986b
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 2 deletions.
35 changes: 33 additions & 2 deletions contrib/remote-helpers/git-remote-hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,7 @@ def do_capabilities(parser):
if os.path.exists(path):
print "*import-marks %s" % path
print "*export-marks %s" % path
print "option"

print

Expand Down Expand Up @@ -727,6 +728,11 @@ def parse_commit(parser):
die('Unknown file command: %s' % line)
files[path] = f

# only export the commits if we are on an internal proxy repo
if dry_run and not peer:
parsed_refs[ref] = None
return

def getfilectx(repo, memctx, f):
of = files[f]
if 'deleted' in of:
Expand Down Expand Up @@ -812,7 +818,10 @@ def parse_reset(parser):
from_mark = parser.get_mark()
parser.next()

rev = mark_to_rev(from_mark)
try:
rev = mark_to_rev(from_mark)
except KeyError:
rev = None
parsed_refs[ref] = rev

def parse_tag(parser):
Expand Down Expand Up @@ -999,7 +1008,7 @@ def do_export(parser):
die('unhandled export command: %s' % line)

for ref, node in parsed_refs.iteritems():
bnode = hgbin(node)
bnode = hgbin(node) if node else None
if ref.startswith('refs/heads/branches'):
branch = ref[len('refs/heads/branches/'):]
if branch in branches and bnode in branches[branch]:
Expand All @@ -1022,6 +1031,9 @@ def do_export(parser):

p_revs[bnode] = ref
elif ref.startswith('refs/tags/'):
if dry_run:
print "ok %s" % ref
continue
tag = ref[len('refs/tags/'):]
tag = hgref(tag)
author, msg = parsed_tags.get(tag, (None, None))
Expand All @@ -1040,6 +1052,12 @@ def do_export(parser):
# transport-helper/fast-export bugs
continue

if dry_run:
if not force_push:
checkheads(parser.repo, peer, p_revs)
print
return

if peer:
if not push(parser.repo, peer, parsed_refs, p_revs):
# do not update bookmarks
Expand All @@ -1061,6 +1079,15 @@ def do_export(parser):

print

def do_option(parser):
global dry_run
_, key, value = parser.line.split(' ')
if key == 'dry-run':
dry_run = (value == 'true')
print 'ok'
else:
print 'unsupported'

def fix_path(alias, repo, orig_url):
url = urlparse.urlparse(orig_url, 'file')
if url.scheme != 'file' or os.path.isabs(url.path):
Expand All @@ -1077,6 +1104,7 @@ def main(args):
global parsed_tags
global filenodes
global fake_bmark, hg_version
global dry_run

alias = args[1]
url = args[2]
Expand Down Expand Up @@ -1115,6 +1143,7 @@ def main(args):
hg_version = tuple(int(e) for e in util.version().split('.'))
except:
hg_version = None
dry_run = False

repo = get_repo(url, alias)
prefix = 'refs/hg/%s' % alias
Expand All @@ -1139,6 +1168,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()
Expand Down
88 changes: 88 additions & 0 deletions contrib/remote-helpers/test-hg.t
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,94 @@ test_expect_success 'remote big push' '
check_bookmark hgrepo new_bmark ''
'

test_expect_success 'remote big push dry-run' '
test_when_finished "rm -rf hgrepo gitrepo*" &&
(
hg init hgrepo &&
cd hgrepo &&
echo zero > content &&
hg add content &&
hg commit -m zero &&
hg bookmark bad_bmark1 &&
echo one > content &&
hg commit -m one &&
hg bookmark bad_bmark2 &&
hg bookmark good_bmark &&
hg bookmark -i good_bmark &&
hg -q branch good_branch &&
echo "good branch" > content &&
hg commit -m "good branch" &&
hg -q branch bad_branch &&
echo "bad branch" > content &&
hg commit -m "bad branch"
) &&
git clone "hg::hgrepo" gitrepo &&
(
cd gitrepo &&
echo two > content &&
git commit -q -a -m two &&
git checkout -q good_bmark &&
echo three > content &&
git commit -q -a -m three &&
git checkout -q bad_bmark1 &&
git reset --hard HEAD^ &&
echo four > content &&
git commit -q -a -m four &&
git checkout -q bad_bmark2 &&
git reset --hard HEAD^ &&
echo five > content &&
git commit -q -a -m five &&
git checkout -q -b new_bmark master &&
echo six > content &&
git commit -q -a -m six &&
git checkout -q branches/good_branch &&
echo seven > content &&
git commit -q -a -m seven &&
echo eight > content &&
git commit -q -a -m eight &&
git checkout -q branches/bad_branch &&
git reset --hard HEAD^ &&
echo nine > content &&
git commit -q -a -m nine &&
git checkout -q -b branches/new_branch master &&
echo ten > content &&
git commit -q -a -m ten &&
test_expect_code 1 git push --dry-run origin master \
good_bmark bad_bmark1 bad_bmark2 new_bmark \
branches/good_branch branches/bad_branch \
branches/new_branch 2> error &&
grep "^ [a-f0-9]*\.\.[a-f0-9]* *master -> master$" error &&
grep "^ [a-f0-9]*\.\.[a-f0-9]* *good_bmark -> good_bmark$" error &&
grep "^ \* \[new branch\] *new_bmark -> new_bmark$" error &&
grep "^ ! \[rejected\] *bad_bmark2 -> bad_bmark2 (non-fast-forward)$" error &&
grep "^ ! \[rejected\] *bad_bmark1 -> bad_bmark1 (non-fast-forward)$" error &&
grep "^ [a-f0-9]*\.\.[a-f0-9]* *branches/good_branch -> branches/good_branch$" error &&
grep "^ ! \[rejected\] *branches/bad_branch -> branches/bad_branch (non-fast-forward)$" error &&
grep "^ \* \[new branch\] *branches/new_branch -> branches/new_branch$" error
) &&
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*" &&
Expand Down

0 comments on commit 6c3986b

Please sign in to comment.