--- a/hgext/mq.py Fri Feb 09 03:48:28 2007 -0200
+++ b/hgext/mq.py Fri Feb 09 03:48:30 2007 -0200
@@ -1082,9 +1082,13 @@
self.push(repo, force=True, wlock=wlock)
def init(self, repo, create=False):
- if os.path.isdir(self.path):
+ if not create and os.path.isdir(self.path):
raise util.Abort(_("patch queue directory already exists"))
- os.mkdir(self.path)
+ try:
+ os.mkdir(self.path)
+ except OSError, inst:
+ if inst.errno != errno.EEXIST or not create:
+ raise
if create:
return self.qrepo(create=True)
@@ -1467,13 +1471,16 @@
r = q.init(repo, create=opts['create_repo'])
q.save_dirty()
if r:
- fp = r.wopener('.hgignore', 'w')
- print >> fp, 'syntax: glob'
- print >> fp, 'status'
- print >> fp, 'guards'
- fp.close()
- r.wopener('series', 'w').close()
+ if not os.path.exists(r.wjoin('.hgignore')):
+ fp = r.wopener('.hgignore', 'w')
+ fp.write('syntax: glob\n')
+ fp.write('status\n')
+ fp.write('guards\n')
+ fp.close()
+ if not os.path.exists(r.wjoin('series')):
+ r.wopener('series', 'w').close()
r.add(['.hgignore', 'series'])
+ commands.add(ui, r)
return 0
def clone(ui, source, dest=None, **opts):
--- a/tests/test-mq Fri Feb 09 03:48:28 2007 -0200
+++ b/tests/test-mq Fri Feb 09 03:48:30 2007 -0200
@@ -40,6 +40,40 @@
hg -R c qnew test.patch
hg -R c/.hg/patches st
+echo '% qinit; qinit -c'
+hg init d
+cd d
+hg qinit
+hg qinit -c
+# qinit -c should create both files if they don't exist
+echo ' .hgignore:'
+cat .hg/patches/.hgignore
+echo ' series:'
+cat .hg/patches/series
+hg qinit -c 2>&1 | sed -e 's/repository.*already/repository already/'
+cd ..
+
+echo '% qinit; <stuff>; qinit -c'
+hg init e
+cd e
+hg qnew A
+echo foo > foo
+hg add foo
+hg qrefresh
+hg qnew B
+echo >> foo
+hg qrefresh
+echo status >> .hg/patches/.hgignore
+echo bleh >> .hg/patches/.hgignore
+hg qinit -c
+hg -R .hg/patches status
+# qinit -c shouldn't touch these files if they already exist
+echo ' .hgignore:'
+cat .hg/patches/.hgignore
+echo ' series:'
+cat .hg/patches/series
+cd ..
+
cd a
echo % qnew -m
--- a/tests/test-mq.out Fri Feb 09 03:48:28 2007 -0200
+++ b/tests/test-mq.out Fri Feb 09 03:48:30 2007 -0200
@@ -60,6 +60,26 @@
A .hgignore
A series
A test.patch
+% qinit; qinit -c
+ .hgignore:
+syntax: glob
+status
+guards
+ series:
+abort: repository already exists!
+% qinit; <stuff>; qinit -c
+adding A
+adding B
+A .hgignore
+A A
+A B
+A series
+ .hgignore:
+status
+bleh
+ series:
+A
+B
% qnew -m
foo bar
% qrefresh