fix git support for v1.5.3 (or higher) by setting "--work-tree"
[translate_toolkit.git] / storage / versioncontrol / hg.py
blob1a94f1ce1899ca28a8999f9f8815935960835c9c
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright 2004-2008 Zuza Software Foundation
5 #
6 # This file is part of translate.
8 # translate is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
13 # translate is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with translate; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 from translate.storage.versioncontrol import run_command
24 from translate.storage.versioncontrol import GenericRevisionControlSystem
26 class hg(GenericRevisionControlSystem):
27 """Class to manage items under revision control of mercurial."""
29 RCS_METADIR = ".hg"
30 SCAN_PARENTS = True
32 def update(self, revision=None):
33 """Does a clean update of the given path
35 @param revision: ignored for hg
36 """
37 # revert local changes (avoids conflicts)
38 command = ["hg", "-R", self.root_dir, "revert",
39 "--all", self.location_abs]
40 exitcode, output_revert, error = run_command(command)
41 if exitcode != 0:
42 raise IOError("[Mercurial] error running '%s': %s" % (command, error))
43 # pull new patches
44 command = ["hg", "-R", self.root_dir, "pull"]
45 exitcode, output_pull, error = run_command(command)
46 if exitcode != 0:
47 raise IOError("[Mercurial] error running '%s': %s" % (command, error))
48 # update working directory
49 command = ["hg", "-R", self.root_dir, "update"]
50 exitcode, output_update, error = run_command(command)
51 if exitcode != 0:
52 raise IOError("[Mercurial] error running '%s': %s" % (command, error))
53 return output_revert + output_pull + output_update
55 def commit(self, message=None):
56 """Commits the file and supplies the given commit message if present"""
57 if message is None:
58 message = ""
59 # commit changes
60 command = ["hg", "-R", self.root_dir, "commit", "-m", message,
61 self.location_abs]
62 exitcode, output_commit, error = run_command(command)
63 if exitcode != 0:
64 raise IOError("[Mercurial] Error running '%s': %s" \
65 % (command, error))
66 # push changes
67 command = ["hg", "-R", self.root_dir, "push"]
68 exitcode, output_push, error = run_command(command)
69 if exitcode != 0:
70 raise IOError("[Mercurial] Error running '%s': %s" \
71 % (command, error))
72 return output_commit + output_push
74 def getcleanfile(self, revision=None):
75 """Get a clean version of a file from the hg repository"""
76 # run hg cat
77 command = ["hg", "-R", self.root_dir, "cat",
78 self.location_abs]
79 exitcode, output, error = run_command(command)
80 if exitcode != 0:
81 raise IOError("[Mercurial] Error running '%s': %s" \
82 % (command, error))
83 return output