diff options
author | Guido Günther <g.guenther@tarent.de> | 2011-10-28 13:54:51 +0200 |
---|---|---|
committer | Guido Günther <agx@sigxcpu.org> | 2011-10-28 18:55:49 +0200 |
commit | 004eac7c7c6298b9f1c5e9cc1b6e6dea61433b57 (patch) | |
tree | 1af1a131a386f7049ce73c5167dbea3254280172 | |
parent | 27a921eefd474dd7fed0abed8c3667aa4e1bcaa2 (diff) |
GitRepository: add head property to return the current HEAD
-rwxr-xr-x | gbp-pq | 3 | ||||
-rw-r--r-- | gbp/git.py | 5 | ||||
-rwxr-xr-x | git-dch | 7 | ||||
-rw-r--r-- | tests/test_GitRepository.py | 8 |
4 files changed, 14 insertions, 9 deletions
@@ -321,13 +321,12 @@ def apply_and_commit_patch(repo, patch, topic=None): else: gbp.log.warn("Patch %s has no authorship information") - head = repo.rev_parse('HEAD') repo.apply_patch(patch) tree = repo.write_tree() msg = "%s\n\n%s" % (header['subject'], body) if topic: msg += "\nGbp-Pq-Topic: %s" % topic - commit = repo.commit_tree(tree, msg, [head], author=header) + commit = repo.commit_tree(tree, msg, [repo.head], author=header) repo.update_ref('HEAD', commit, msg="gbp-pq import %s" % patch) @@ -215,6 +215,11 @@ class GitRepository(object): """The currently checked out branch""" return self.get_branch() + @property + def head(self): + """return the SHA1 of the current HEAD""" + return self.rev_parse('HEAD') + #{ Branches and Merging def create_branch(self, branch, rev=None): """ @@ -143,11 +143,6 @@ def fixup_trailer(repo, git_author, dch_options): spawn_dch(msg='', author=author, email=email, dch_options=dch_options) -def head_commit(repo): - """get the full sha1 of the last commit on HEAD""" - return repo.rev_parse('HEAD') - - def snapshot_version(version): """ get the current release and snapshot version @@ -216,7 +211,7 @@ def do_snapshot(changelog, repo, next_snapshot): Add new snapshot banner to most recent changelog section. The next snapshot number is calculated by eval()'ing next_snapshot """ - commit = head_commit(repo) + commit = repo.head cp = parse_changelog(filename=changelog) (release, snapshot) = snapshot_version(cp['Version']) diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py index 1aa98a19..34b96604 100644 --- a/tests/test_GitRepository.py +++ b/tests/test_GitRepository.py @@ -22,7 +22,7 @@ def test_create(): Methods tested: - L{gbp.git.GitRepository.create} - Propeties tested: + Properties tested: - L{gbp.git.GitRepository.path} - L{gbp.git.GitRepository.git_dir} @@ -63,6 +63,9 @@ def test_add_files(): - L{gbp.git.GitRepository.commit_all} - L{gbp.git.GitRepository.is_clean} + Properties tested: + - L{gbp.git.GitRepository.head} + >>> import gbp.git, shutil >>> repo = gbp.git.GitRepository(repo_dir) >>> shutil.copy(os.path.join(repo.path, ".git/HEAD"), \ @@ -73,6 +76,9 @@ def test_add_files(): >>> repo.commit_all(msg="foo") >>> repo.is_clean()[0] True + >>> h = repo.head + >>> len(h) + 40 """ |