From 817a9a9c5eac1927c19799b6173e8982c28489ac Mon Sep 17 00:00:00 2001 From: sumpfralle Date: Wed, 2 Jul 2008 23:48:06 +0000 Subject: [PATCH] fix git support for v1.5.3 (or higher) by setting "--work-tree" this patch was contributed by Miklos Vajna git-svn-id: http://translate.svn.sourceforge.net/svnroot/translate/src/trunk/translate@7710 54714841-351b-0410-a198-e36a94b762f5 --- storage/versioncontrol/git.py | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/storage/versioncontrol/git.py b/storage/versioncontrol/git.py index d85f925..4e61874 100644 --- a/storage/versioncontrol/git.py +++ b/storage/versioncontrol/git.py @@ -39,17 +39,23 @@ class git(GenericRevisionControlSystem): """ import os return os.path.join(self.root_dir, self.RCS_METADIR) + + def _get_git_command(self, args): + """prepends generic git arguments to conrete ones + """ + command = ["git", "--git-dir", self._get_git_dir(), "--work-tree", self.root_dir] + command.extend(args) + return command def update(self, revision=None): """Does a clean update of the given path""" # git checkout - command = ["git", "--git-dir", self._get_git_dir(), - "checkout", self.location_rel] + command = self._get_git_command(["checkout", self.location_rel]) exitcode, output_checkout, error = run_command(command) if exitcode != 0: raise IOError("[GIT] checkout failed (%s): %s" % (command, error)) # pull changes - command = ["git", "--git-dir", self._get_git_dir(), "pull"] + command = self._get_git_command(["pull"]) exitcode, output_pull, error = run_command(command) if exitcode != 0: raise IOError("[GIT] pull failed (%s): %s" % (command, error)) @@ -58,22 +64,25 @@ class git(GenericRevisionControlSystem): def commit(self, message=None): """Commits the file and supplies the given commit message if present""" # add the file - command = ["git", "--git-dir", self._get_git_dir(), - "add", self.location_rel] + command = self._get_git_command(["add", self.location_rel]) exitcode, output_add, error = run_command(command) if exitcode != 0: raise IOError("[GIT] add of ('%s', '%s') failed: %s" \ % (self.root_dir, self.location_rel, error)) # commit file - command = ["git", "--git-dir", self._get_git_dir(), "commit"] + command = self._get_git_command(["commit"]) if message: command.extend(["-m", message]) exitcode, output_commit, error = run_command(command) if exitcode != 0: + if len(error): + msg = error + else: + msg = output_commit raise IOError("[GIT] commit of ('%s', '%s') failed: %s" \ - % (self.root_dir, self.location_rel, error)) + % (self.root_dir, self.location_rel, msg)) # push changes - command = ["git", "--git-dir", self._get_git_dir(), "push"] + command = self._get_git_command(["push"]) exitcode, output_push, error = run_command(command) if exitcode != 0: raise IOError("[GIT] push of ('%s', '%s') failed: %s" \ @@ -83,8 +92,7 @@ class git(GenericRevisionControlSystem): def getcleanfile(self, revision=None): """Get a clean version of a file from the git repository""" # run git-show - command = ["git", "--git-dir", self._get_git_dir(), "show", - "HEAD:%s" % self.location_rel] + command = self._get_git_command(["show", "HEAD:%s" % self.location_rel]) exitcode, output, error = run_command(command) if exitcode != 0: raise IOError("[GIT] 'show' failed for ('%s', %s): %s" \ -- 2.11.4.GIT