From 004eac7c7c6298b9f1c5e9cc1b6e6dea61433b57 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Fri, 28 Oct 2011 13:54:51 +0200 Subject: GitRepository: add head property to return the current HEAD --- gbp-pq | 3 +-- gbp/git.py | 5 +++++ git-dch | 7 +------ tests/test_GitRepository.py | 8 +++++++- 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/gbp-pq b/gbp-pq index 1b04642..092c628 100755 --- a/gbp-pq +++ b/gbp-pq @@ -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) diff --git a/gbp/git.py b/gbp/git.py index 43e5388..55039ed 100644 --- a/gbp/git.py +++ b/gbp/git.py @@ -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): """ diff --git a/git-dch b/git-dch index 17c2e15..819762e 100755 --- a/git-dch +++ b/git-dch @@ -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 1aa98a1..34b9660 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 """ -- cgit v1.2.3