comparison treepkg/git.py @ 568:bf8114a76224

Add more debug output
author Bjoern Ricks <bricks@intevation.de>
date Fri, 02 Sep 2011 11:19:03 +0000
parents e188e780977b
children aaeca9cf0143
comparison
equal deleted inserted replaced
567:9d44d4da3411 568:bf8114a76224
25 25
26 class GitRepository(object): 26 class GitRepository(object):
27 27
28 """Describes a git repository""" 28 """Describes a git repository"""
29 29
30 def __init__(self, url, branch=None): 30 def __init__(self, url, branch=None, logger=None):
31 """Initialize the git repository description 31 """Initialize the git repository description
32 Parameters: 32 Parameters:
33 url -- The url of the repository 33 url -- The url of the repository
34 34
35 branch -- The name of the remote Branch to track 35 branch -- The name of the remote Branch to track
36 defaults to master 36 defaults to master
37 """ 37 """
38 self.url = url 38 self.url = url
39 self.log = logger
39 if not branch: 40 if not branch:
40 # as default track master as local-master 41 # as default track master as local-master
41 self.local_branch = "local-master" 42 self.local_branch = "local-master"
42 self.branch = "master" 43 self.branch = "master"
43 else: 44 else:
49 self.branch = branches[1] 50 self.branch = branches[1]
50 51
51 def checkout(self, localdir): 52 def checkout(self, localdir):
52 """Clones the repository at url into the localdir""" 53 """Clones the repository at url into the localdir"""
53 run.call(cmdexpand("git clone -q $url $localdir", **locals())) 54 run.call(cmdexpand("git clone -q $url $localdir", **locals()))
54 if branch: 55 if self.branch:
55 self.checkout_branch(localdir) 56 self.checkout_branch(localdir)
56 57
57 def checkout_branch(self, localdir): 58 def checkout_branch(self, localdir):
59 self.log_info("Switching to local branch '%s' for branch '%s'" %\
60 (self.local_branch, self.branch))
58 run.call(cmdexpand("git checkout -q --track -b $local $branch", 61 run.call(cmdexpand("git checkout -q --track -b $local $branch",
59 branch=self.branch, local=self.local_branch), cwd=localdir) 62 branch=self.branch, local=self.local_branch), cwd=localdir)
60 63
61 64
62 def export(self, localdir, destdir): 65 def export(self, localdir, destdir):
82 cur_branch = tbranch[2:] 85 cur_branch = tbranch[2:]
83 tbranch = cur_branch 86 tbranch = cur_branch
84 all_branches.append(tbranch) 87 all_branches.append(tbranch)
85 if not self.local_branch in all_branches: 88 if not self.local_branch in all_branches:
86 self.checkout_branch(localdir) 89 self.checkout_branch(localdir)
90 self.log_info("Current branch is '%s'" % cur_branch)
87 # TODO: check if self.local_branch is curbranch 91 # TODO: check if self.local_branch is curbranch
88 # doesn't hurt if a checkout is done on the current branch 92 # doesn't hurt if a checkout is done on the current branch
89 if self.branch: 93 if self.branch:
94 self.log_info("Switching to local branch '%s'" % self.local_branch)
90 run.call(cmdexpand("git checkout -q $branch", branch=self.local_branch), 95 run.call(cmdexpand("git checkout -q $branch", branch=self.local_branch),
91 cwd=localdir) 96 cwd=localdir)
92 97
98 def log_info(self, *args):
99 if self.logger is not None:
100 self.logger.info(*args)
93 101
94 def last_changed_revision(self, localdir): 102 def last_changed_revision(self, localdir):
95 """Returns the SHA1 sum of the latest commit in the working copy in localdir""" 103 """Returns the SHA1 sum of the latest commit in the working copy in localdir"""
96 output = run.capture_output(cmdexpand("git rev-parse HEAD"), 104 output = run.capture_output(cmdexpand("git rev-parse HEAD"),
97 cwd=localdir) 105 cwd=localdir)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)