2 # -*- coding: utf-8 -*-
4 # Copyright 2004-2007 Zuza Software Foundation
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 # Requires: git v.1.5.3
24 # For git v1.5.2 take a look at http://bugs.locamotion.org/show_bug.cgi?id=347
28 from translate
.storage
.versioncontrol
import run_command
29 from translate
.storage
.versioncontrol
import GenericRevisionControlSystem
31 class git(GenericRevisionControlSystem
):
32 """Class to manage items under revision control of git."""
37 def _get_git_dir(self
):
38 """git requires the git metadata directory for every operation
41 return os
.path
.join(self
.root_dir
, self
.RCS_METADIR
)
43 def _get_git_command(self
, args
):
44 """prepends generic git arguments to conrete ones
46 command
= ["git", "--git-dir", self
._get
_git
_dir
(), "--work-tree", self
.root_dir
]
50 def update(self
, revision
=None):
51 """Does a clean update of the given path"""
53 command
= self
._get
_git
_command
(["checkout", self
.location_rel
])
54 exitcode
, output_checkout
, error
= run_command(command
)
56 raise IOError("[GIT] checkout failed (%s): %s" % (command
, error
))
58 command
= self
._get
_git
_command
(["pull"])
59 exitcode
, output_pull
, error
= run_command(command
)
61 raise IOError("[GIT] pull failed (%s): %s" % (command
, error
))
62 return output_checkout
+ output_pull
64 def commit(self
, message
=None):
65 """Commits the file and supplies the given commit message if present"""
67 command
= self
._get
_git
_command
(["add", self
.location_rel
])
68 exitcode
, output_add
, error
= run_command(command
)
70 raise IOError("[GIT] add of ('%s', '%s') failed: %s" \
71 % (self
.root_dir
, self
.location_rel
, error
))
73 command
= self
._get
_git
_command
(["commit"])
75 command
.extend(["-m", message
])
76 exitcode
, output_commit
, error
= run_command(command
)
82 raise IOError("[GIT] commit of ('%s', '%s') failed: %s" \
83 % (self
.root_dir
, self
.location_rel
, msg
))
85 command
= self
._get
_git
_command
(["push"])
86 exitcode
, output_push
, error
= run_command(command
)
88 raise IOError("[GIT] push of ('%s', '%s') failed: %s" \
89 % (self
.root_dir
, self
.location_rel
, error
))
90 return output_add
+ output_commit
+ output_push
92 def getcleanfile(self
, revision
=None):
93 """Get a clean version of a file from the git repository"""
95 command
= self
._get
_git
_command
(["show", "HEAD:%s" % self
.location_rel
])
96 exitcode
, output
, error
= run_command(command
)
98 raise IOError("[GIT] 'show' failed for ('%s', %s): %s" \
99 % (self
.root_dir
, self
.location_rel
, error
))