Merge pull request #5141 from kisielk/hg
hg module: Don't modify hgrc when running purge
This commit is contained in:
commit
a2489ac83c
1 changed files with 6 additions and 42 deletions
|
@ -59,9 +59,7 @@ options:
|
||||||
choices: [ "yes", "no" ]
|
choices: [ "yes", "no" ]
|
||||||
purge:
|
purge:
|
||||||
description:
|
description:
|
||||||
- Deletes untracked files. Runs C(hg purge). Note this requires C(purge) extension to
|
- Deletes untracked files. Runs C(hg purge).
|
||||||
be enabled if C(purge=yes). This module will modify hgrc file on behalf of the user
|
|
||||||
and undo the changes before exiting the task.
|
|
||||||
required: false
|
required: false
|
||||||
default: "no"
|
default: "no"
|
||||||
choices: [ "yes", "no" ]
|
choices: [ "yes", "no" ]
|
||||||
|
@ -85,36 +83,6 @@ EXAMPLES = '''
|
||||||
- hg: repo=https://bitbucket.org/user/repo1 dest=/home/user/repo1 revision=stable purge=yes
|
- hg: repo=https://bitbucket.org/user/repo1 dest=/home/user/repo1 revision=stable purge=yes
|
||||||
'''
|
'''
|
||||||
|
|
||||||
def _set_hgrc(hgrc, vals):
|
|
||||||
parser = ConfigParser.SafeConfigParser()
|
|
||||||
parser.read(hgrc)
|
|
||||||
|
|
||||||
# val is a list of triple-tuple of the form [(section, option, value),...]
|
|
||||||
for each in vals:
|
|
||||||
(section, option, value) = each
|
|
||||||
if not parser.has_section(section):
|
|
||||||
parser.add_section(section)
|
|
||||||
parser.set(section, option, value)
|
|
||||||
|
|
||||||
f = open(hgrc, 'w')
|
|
||||||
parser.write(f)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
def _undo_hgrc(hgrc, vals):
|
|
||||||
parser = ConfigParser.SafeConfigParser()
|
|
||||||
parser.read(hgrc)
|
|
||||||
|
|
||||||
for each in vals:
|
|
||||||
(section, option, value) = each
|
|
||||||
if parser.has_section(section):
|
|
||||||
parser.remove_option(section, option)
|
|
||||||
|
|
||||||
f = open(hgrc, 'w')
|
|
||||||
parser.write(f)
|
|
||||||
f.close()
|
|
||||||
|
|
||||||
|
|
||||||
class Hg(object):
|
class Hg(object):
|
||||||
|
|
||||||
def __init__(self, module, dest, repo, revision, hg_path):
|
def __init__(self, module, dest, repo, revision, hg_path):
|
||||||
|
@ -129,7 +97,8 @@ class Hg(object):
|
||||||
return (rc, out, err)
|
return (rc, out, err)
|
||||||
|
|
||||||
def _list_untracked(self):
|
def _list_untracked(self):
|
||||||
return self._command(['purge', '-R', self.dest, '--print'])
|
args = ['purge', '--config', 'extensions.purge=', '-R', self.dest, '--print']
|
||||||
|
return self._command(args)
|
||||||
|
|
||||||
def get_revision(self):
|
def get_revision(self):
|
||||||
"""
|
"""
|
||||||
|
@ -168,10 +137,6 @@ class Hg(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def purge(self):
|
def purge(self):
|
||||||
hgrc = os.path.join(self.dest, '.hg/hgrc')
|
|
||||||
purge_option = [('extensions', 'purge', '')]
|
|
||||||
_set_hgrc(hgrc, purge_option) # enable purge extension
|
|
||||||
|
|
||||||
# before purge, find out if there are any untracked files
|
# before purge, find out if there are any untracked files
|
||||||
(rc1, out1, err1) = self._list_untracked()
|
(rc1, out1, err1) = self._list_untracked()
|
||||||
if rc1 != 0:
|
if rc1 != 0:
|
||||||
|
@ -179,10 +144,9 @@ class Hg(object):
|
||||||
|
|
||||||
# there are some untrackd files
|
# there are some untrackd files
|
||||||
if out1 != '':
|
if out1 != '':
|
||||||
(rc2, out2, err2) = self._command(['purge', '-R', self.dest])
|
args = ['purge', '--config', 'extensions.purge=', '-R', self.dest]
|
||||||
if rc2 == 0:
|
(rc2, out2, err2) = self._command(args)
|
||||||
_undo_hgrc(hgrc, purge_option)
|
if rc2 != 0:
|
||||||
else:
|
|
||||||
self.module.fail_json(msg=err2)
|
self.module.fail_json(msg=err2)
|
||||||
return True
|
return True
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in a new issue