1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
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
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
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
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
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
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
79 """Get a clean version of a file from the git repository"""
80
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