3
# hg-update - pull and update a mercurial repository
5
# Copyright (C) 2007 Marco Barisione <marco@barisione.org>
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 2 of the License, or
10
# (at your option) any later version.
12
# This program is distributed in the hope that it will be useful,
13
# but WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
17
# You should have received a copy of the GNU General Public License
18
# along with this program; if not, write to the Free Software
19
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26
from subprocess import Popen, call, PIPE, STDOUT
27
except ImportError: # Python < 2.4 lacks subprocess module
28
sys.path.append(os.path.join(os.path.dirname(__file__), '..'))
29
from jhbuild.cut_n_paste import subprocess
30
sys.modules['subprocess'] = subprocess
31
from subprocess import Popen, call, PIPE, STDOUT
34
hg = Popen(['hg', 'parents', '--template', '{rev}'], stdout=PIPE)
36
return hg.stdout.read().split()[0]
38
# handle parentless revisions
42
ret = call(['hg', 'pull'])
46
env = dict(os.environ)
47
env['HGMERGE'] = '/bin/false'
49
hg = Popen(['hg', 'update', '--noninteractive'], stdout=PIPE,
50
stderr=STDOUT, env=env)
51
out = hg.communicate()[0]
52
if hg.returncode != 0:
53
# Use CVS-like format for conflicts.
54
out = re.sub('merging (.*) failed!', r'C \1', out)
55
index = out.find('You can redo the full merge using:')
56
# Remove the instructions to redo the full merge as we are
57
# going to revert the update.
61
return hg.returncode == 0
63
def undo_update(parent):
64
print 'Update failed, updating to parent revision'
65
env = dict(os.environ)
66
env['HGMERGE'] = 'false'
67
hg = call(['hg', 'update', '--noninteractive', '-q', parent], env=env)
69
def pull_and_update():
79
if __name__ == '__main__':
82
ret = pull_and_update()
84
print '%s: %s' % (sys.argv[0], e)