Package translate :: Package storage :: Package versioncontrol :: Module git
[hide private]
[frames] | no frames]

Source Code for Module translate.storage.versioncontrol.git

 1  #!/usr/bin/env python 
 2  # -*- coding: utf-8 -*- 
 3  #  
 4  # Copyright 2004-2007 Zuza Software Foundation 
 5  #  
 6  # This file is part of translate. 
 7  # 
 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. 
12  #  
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. 
17  # 
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 
21   
22   
23  from translate.storage.versioncontrol import run_command 
24  from translate.storage.versioncontrol import GenericRevisionControlSystem 
25   
26 -class git(GenericRevisionControlSystem):
27 """Class to manage items under revision control of git.""" 28 29 RCS_METADIR = ".git" 30 SCAN_PARENTS = True 31
32 - def _get_git_dir(self):
33 """git requires the git metadata directory for every operation 34 """ 35 import os 36 return os.path.join(self.root_dir, self.RCS_METADIR)
37
38 - def update(self, revision=None):
39 """Does a clean update of the given path""" 40 # git checkout 41 command = ["git", "--git-dir", self._get_git_dir(), 42 "checkout", self.location_rel] 43 exitcode, output_checkout, error = run_command(command) 44 if exitcode != 0: 45 raise IOError("[GIT] checkout failed (%s): %s" % (command, error)) 46 # pull changes 47 command = ["git", "--git-dir", self._get_git_dir(), "pull"] 48 exitcode, output_pull, error = run_command(command) 49 if exitcode != 0: 50 raise IOError("[GIT] pull failed (%s): %s" % (command, error)) 51 return output_checkout + output_pull
52
53 - def commit(self, message=None):
54 """Commits the file and supplies the given commit message if present""" 55 # add the file 56 command = ["git", "--git-dir", self._get_git_dir(), 57 "add", self.location_rel] 58 exitcode, output_add, error = run_command(command) 59 if exitcode != 0: 60 raise IOError("[GIT] add of ('%s', '%s') failed: %s" \ 61 % (self.root_dir, self.location_rel, error)) 62 # commit file 63 command = ["git", "--git-dir", self._get_git_dir(), "commit"] 64 if message: 65 command.extend(["-m", message]) 66 exitcode, output_commit, error = run_command(command) 67 if exitcode != 0: 68 raise IOError("[GIT] commit of ('%s', '%s') failed: %s" \ 69 % (self.root_dir, self.location_rel, error)) 70 # push changes 71 command = ["git", "--git-dir", self._get_git_dir(), "push"] 72 exitcode, output_push, error = run_command(command) 73 if exitcode != 0: 74 raise IOError("[GIT] push of ('%s', '%s') failed: %s" \ 75 % (self.root_dir, self.location_rel, error)) 76 return output_add + output_commit + output_push
77
78 - def getcleanfile(self, revision=None):
79 """Get a clean version of a file from the git repository""" 80 # run git-show 81 command = ["git", "--git-dir", self._get_git_dir(), "show", 82 "HEAD:%s" % self.location_rel] 83 exitcode, output, error = run_command(command) 84 if exitcode != 0: 85 raise IOError("[GIT] 'show' failed for ('%s', %s): %s" \ 86 % (self.root_dir, self.location_rel, error)) 87 return output
88