annotate treepkg/git.py @ 526:4a56ebc53ada

tag_pkg_parameters is also used in enterprise tags recipe
author Bjoern Ricks <bricks@intevation.de>
date Mon, 15 Nov 2010 14:41:03 +0000
parents e73a4bbc35e7
children 8138df69a32e
rev   line source
501
fd52f1e231ba Fix typo in a comment
Andre Heinecke <aheinecke@intevation.de>
parents: 447
diff changeset
1 # Copyright (C) 2010 by Intevation GmbH
321
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
2 # Authors:
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
3 # Andre Heinecke <aheinecke@intevation.de>
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
4 #
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
5 # This program is free software under the GPL (>=v2)
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
6 # Read the file COPYING coming with the software for details.
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
7
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
8 """Collection of Git utility code"""
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
9
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
10 import os
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
11 import shutil
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
12 import re
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
13 import StringIO
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
14
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
15 import run
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
16 from cmdexpand import cmdexpand
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
17 from util import extract_value_for_key
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
18
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
19
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
20 class GitError(Exception):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
21
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
22 """Base class for Git specific errors raised by TreePKG"""
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
23
519
0365b2c7ac00 don't checkout master branch by default for local branch. local would point to the local master and not to origin/master.
Bjoern Ricks <bricks@intevation.de>
parents: 509
diff changeset
24 def checkout(url, localdir, branch=None):
321
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
25 """Clones the repository at url into the localdir"""
509
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
26 run.call(cmdexpand("git clone -q $url $localdir", **locals()))
321
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
27 if branch:
509
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
28 run.call(cmdexpand("git checkout -q --track -b local $branch",
323
ef983263b875 Changed command calls to use cwd and fixed line length
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
29 **locals()), cwd=localdir)
321
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
30
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
31 def update(localdir, revision=None):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
32 """Runs git pull on the localdir."""
323
ef983263b875 Changed command calls to use cwd and fixed line length
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
33 run.call(cmdexpand("git pull -q"), cwd=localdir)
321
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
34
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
35 def export(src, dest):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
36 """Exports the local branch from src to dest"""
446
bee2e5f6cf8d Ignore redundancy of trailing slashes while ensuring to have at least one.
Andre Heinecke <aheinecke@intevation.de>
parents: 444
diff changeset
37 dest = dest + os.sep
323
ef983263b875 Changed command calls to use cwd and fixed line length
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
38 run.call(cmdexpand("git checkout-index -a -f --prefix=$dest", **locals()),
ef983263b875 Changed command calls to use cwd and fixed line length
Andre Heinecke <aheinecke@intevation.de>
parents: 321
diff changeset
39 cwd=src)
321
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
40
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
41 def last_changed_revision(git_working_copy):
328
dd2bd0ccd674 Revisions are now handled as strings
Andre Heinecke <aheinecke@intevation.de>
parents: 324
diff changeset
42 """Return the SHA1 sum of the latest commit"""
dd2bd0ccd674 Revisions are now handled as strings
Andre Heinecke <aheinecke@intevation.de>
parents: 324
diff changeset
43 output = run.capture_output(cmdexpand("git rev-parse HEAD"),
dd2bd0ccd674 Revisions are now handled as strings
Andre Heinecke <aheinecke@intevation.de>
parents: 324
diff changeset
44 cwd=git_working_copy)
321
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
45 if output is None:
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
46 raise GitError("Cannot determine last changed revision for %r"
328
dd2bd0ccd674 Revisions are now handled as strings
Andre Heinecke <aheinecke@intevation.de>
parents: 324
diff changeset
47 % git_working_copy)
dd2bd0ccd674 Revisions are now handled as strings
Andre Heinecke <aheinecke@intevation.de>
parents: 324
diff changeset
48 return output.strip()
321
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
49
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
50 class GitRepository(object):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
51
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
52 """Describes a git repository"""
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
53
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
54 def __init__(self, url, branch=None):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
55 """Initialize the git repository description
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
56 Parameters:
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
57 url -- The url of the repository
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
58
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
59 branch -- The name of the remote Branch to track
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
60 defaults to master
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
61 """
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
62 self.url = url
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
63 self.branch = branch
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
64
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
65 def checkout(self, localdir):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
66 """Checks out the repository into localdir."""
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
67 checkout(self.url , localdir, self.branch)
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
68
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
69 def export(self, localdir, destdir):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
70 """Exports the working copy in localdir to destdir"""
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
71 export(localdir, destdir)
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
72
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
73 def last_changed_revision(self, localdir):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
74 """Returns the last changed revision of the working copy in localdir"""
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
75 return last_changed_revision(localdir)
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
76
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
77 def check_working_copy(self, localdir):
447
1d16e4844f98 Cleanup misplaced whitespace
Andre Heinecke <aheinecke@intevation.de>
parents: 446
diff changeset
78 """FIXME STUB: Not implemented for git"""
1d16e4844f98 Cleanup misplaced whitespace
Andre Heinecke <aheinecke@intevation.de>
parents: 446
diff changeset
79 return None
321
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
80
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
81 class GitWorkingCopy(object):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
82
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
83 """Represents a checkout of a git repository"""
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
84
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
85 def __init__(self, repository, localdir, logger=None):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
86 """
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
87 Initialize the working copy.
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
88 Parameters:
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
89 repository -- The GitRepository instance describing the
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
90 repository
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
91 localdir -- The directory for the working copy
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
92 logger -- logging object to use for some info/debug messages
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
93 """
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
94 self.repository = repository
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
95 self.localdir = localdir
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
96 self.logger = logger
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
97
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
98 def log_info(self, *args):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
99 if self.logger is not None:
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
100 self.logger.info(*args)
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
101
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
102 def update_or_checkout(self, revision=0):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
103 """Updates the working copy or creates by checking out the repository.
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
104 Revision number included for compatibility
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
105 """
509
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
106 gitdir = os.path.join(self.localdir, ".git")
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
107 if os.path.exists(gitdir):
321
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
108 self.log_info("Updating the working copy in %r", self.localdir)
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
109 update(self.localdir, self.repository.branch)
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
110 else:
519
0365b2c7ac00 don't checkout master branch by default for local branch. local would point to the local master and not to origin/master.
Bjoern Ricks <bricks@intevation.de>
parents: 509
diff changeset
111 # TODO: better check if localdir contains files
520
5802cec2b071 fixed typo
Bjoern Ricks <bricks@intevation.de>
parents: 519
diff changeset
112 if os.path.exists(self.localdir):
519
0365b2c7ac00 don't checkout master branch by default for local branch. local would point to the local master and not to origin/master.
Bjoern Ricks <bricks@intevation.de>
parents: 509
diff changeset
113 raise GitError("Working copy dir %s already exists. " \
0365b2c7ac00 don't checkout master branch by default for local branch. local would point to the local master and not to origin/master.
Bjoern Ricks <bricks@intevation.de>
parents: 509
diff changeset
114 " files. Can't checkout from %s" % (self.localdir,
0365b2c7ac00 don't checkout master branch by default for local branch. local would point to the local master and not to origin/master.
Bjoern Ricks <bricks@intevation.de>
parents: 509
diff changeset
115 self.repository.url))
321
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
116 self.log_info("The working copy in %r doesn't exist yet."
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
117 " Checking out from %r",
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
118 self.localdir, self.repository.url)
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
119 self.repository.checkout(self.localdir)
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
120
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
121 def export(self, destdir):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
122 """Exports the working copy to destdir"""
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
123 self.repository.export(self.localdir, destdir)
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
124
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
125 def last_changed_revision(self):
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
126 """Returns the last changed rev of the working copy"""
092925ff75d7 Added basic Git support, configuration options:
Andre Heinecke <aheinecke@intevation.de>
parents:
diff changeset
127 return self.repository.last_changed_revision(self.localdir)
508
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
128
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
129 def list_tags(self, pattern):
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
130 output = run.capture_output(cmdexpand("git tag -l $pattern",
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
131 pattern=pattern), cwd=self.localdir)
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
132 return output.splitlines()
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
133
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
134 def get_revision(self, refname="HEAD"):
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
135 """Return the SHA1 sum of the latest commit"""
509
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
136 output = run.capture_output(cmdexpand("git rev-parse $refname",
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
137 refname=refname), cwd=self.localdir)
508
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
138 if output is None:
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
139 raise GitError("Cannot determine revision for %r"
509
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
140 % self.localdir)
508
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
141 return output.strip()
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
142
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
143 class TagDetector:
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
144
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
145 """Class to detect tags from a git repository
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
146
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
147 The tags are found using the parameters:
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
148 url -- The url of the git repository to use
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
149 pattern -- A regular expression matching the tags
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
150 """
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
151
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
152 def __init__(self, url, pattern, localdir):
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
153 self.url = url
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
154 self.pattern = pattern
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
155 repo = GitRepository(url)
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
156 self.workingcopy = GitWorkingCopy(repo, localdir)
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
157
509
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
158 def list_tags(self):
508
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
159 self.workingcopy.update_or_checkout()
509
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
160 tags = self.workingcopy.list_tags(self.pattern)
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
161 return sorted(tags)
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
162
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
163 def newest_tag_revision(self):
c4288095887f update git tag detector and add test
Bjoern Ricks <bricks@intevation.de>
parents: 508
diff changeset
164 candidates = self.list_tags()
508
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
165 urlrev = (None, None)
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
166 if candidates:
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
167 newest = candidates[-1]
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
168 try:
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
169 rev = self.workingcopy.get_revision(newest)
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
170 urlrev = (newest, rev)
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
171 except GitError:
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
172 pass
29f6d1f5cc53 add a tag detector for git
Bjoern Ricks <bricks@intevation.de>
parents: 501
diff changeset
173 return urlrev
525
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
174
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
175 def tag_pkg_parameters(self, tag_name):
526
4a56ebc53ada tag_pkg_parameters is also used in enterprise tags recipe
Bjoern Ricks <bricks@intevation.de>
parents: 525
diff changeset
176 # FIXME: Don't hardcore regex
525
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
177 #match = re.search(r"enterprise[^.]*\.[^.]*\."
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
178 match = re.search(r"enterprise[^.]*"
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
179 r"(?P<date>[0-9]{8})",
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
180 tag_name)
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
181 if match:
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
182 date = match.group("date")
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
183 return (date, 1)
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
184 else:
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
185 raise GitError("Cannot determine tag parameters from %s"
e73a4bbc35e7 tag_pkg_parameters depends on scm therefore move this method to the
Bjoern Ricks <bricks@intevation.de>
parents: 520
diff changeset
186 % tag_name)
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)