# HG changeset patch # User Alexis S. L. Carvalho # Date 1171000110 7200 # Node ID 165abe554c80fcd4b1f2fa4db1ad15ab56ce67ea # Parent 961ccb615cf7b6280a1cb51091c51efbb4a7a563 mq: qinit -c creates a repo even after a regular qinit diff --git a/hgext/mq.py b/hgext/mq.py --- a/hgext/mq.py +++ b/hgext/mq.py @@ -1082,9 +1082,13 @@ class queue: 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 @@ def init(ui, repo, **opts): 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): diff --git a/tests/test-mq b/tests/test-mq --- a/tests/test-mq +++ b/tests/test-mq @@ -40,6 +40,40 @@ echo % qnew implies add 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; ; 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 diff --git a/tests/test-mq.out b/tests/test-mq.out --- a/tests/test-mq.out +++ b/tests/test-mq.out @@ -60,6 +60,26 @@ A series A .hgignore A series A test.patch +% qinit; qinit -c + .hgignore: +syntax: glob +status +guards + series: +abort: repository already exists! +% qinit; ; 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