[PATCH] export: clobber files with -o (bc) (issue3652)
Augie Fackler
raf at durin42.com
Fri Oct 5 18:52:00 CDT 2012
# HG changeset patch
# User Augie Fackler <raf at durin42.com>
# Date 1349480822 18000
# Node ID d227c19ce93985d21a20ba006367a41995ddeab6
# Parent fa714f3ed2989aff64c267c9935251d9fc4f31ee
export: clobber files with -o (bc) (issue3652)
This violated user expectation. Updated the code to clobber files, but
preserve the behavior of appending multiple patches requested in a
single export. Includes tests.
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -537,6 +537,7 @@
total = len(revs)
revwidth = max([len(str(rev)) for rev in revs])
+ mode = ['wb']
def single(rev, seqno, fp):
ctx = repo[rev]
@@ -552,7 +553,8 @@
desc_lines = ctx.description().rstrip().split('\n')
desc = desc_lines[0] #Commit always has a first line.
fp = makefileobj(repo, template, node, desc=desc, total=total,
- seqno=seqno, revwidth=revwidth, mode='ab')
+ seqno=seqno, revwidth=revwidth, mode=mode[0])
+ mode[0] = 'ab'
if fp != template:
shouldclose = True
if fp and fp != sys.stdout and util.safehasattr(fp, 'name'):
diff --git a/tests/test-export.t b/tests/test-export.t
--- a/tests/test-export.t
+++ b/tests/test-export.t
@@ -97,7 +97,12 @@
$ grep HG export_internal | wc -l
\s*4 (re)
-Exporting 4 changesets to a file:
+Doing it again clobbers the file rather than appending:
+ $ hg export -o export_internal 1 2 3 4
+ $ grep HG export_internal | wc -l
+ \s*4 (re)
+
+Exporting 4 changesets to stdout:
$ hg export 1 2 3 4 | grep HG | wc -l
\s*4 (re)
More information about the Mercurial-devel
mailing list