diff options
author | Michael Drake <michael.drake@codethink.co.uk> | 2015-04-13 14:17:29 +0000 |
---|---|---|
committer | Michael Drake <michael.drake@codethink.co.uk> | 2015-04-14 10:02:53 +0000 |
commit | f2384463316e7bd53dc8bb4f52febbf8b4973c30 (patch) | |
tree | 276b417f827919d5926a18c16f41c3bf9c4475af | |
parent | f0a31086d816d0a90fdcfaaa4ea58e122a6d99b3 (diff) | |
download | morph-f2384463316e7bd53dc8bb4f52febbf8b4973c30.tar.gz |
Add version guessing funtion to gitdir and cached repo.
Change-Id: I1c79ce68a7a7534d36a9e83210e18a58e7b648e8
-rw-r--r-- | morphlib/cachedrepo.py | 9 | ||||
-rw-r--r-- | morphlib/gitdir.py | 6 |
2 files changed, 15 insertions, 0 deletions
diff --git a/morphlib/cachedrepo.py b/morphlib/cachedrepo.py index b41ba86f..db2d4e23 100644 --- a/morphlib/cachedrepo.py +++ b/morphlib/cachedrepo.py @@ -143,6 +143,15 @@ class CachedRepo(object): ''' return self._gitdir.branches_containing_sha1(ref) + def version_guess(self, ref): + '''Guess version number using `git describe --tags` + + Raises a gitdir.InvalidRefError if the ref is not found in the + repository. + + ''' + return self._gitdir.version_guess(ref) + def list_files(self, ref, recurse=True): # pragma: no cover '''Return filenames found in the tree pointed to by the given ref. diff --git a/morphlib/gitdir.py b/morphlib/gitdir.py index 1c286720..9ec38865 100644 --- a/morphlib/gitdir.py +++ b/morphlib/gitdir.py @@ -707,6 +707,12 @@ class GitDirectory(object): args = ['branch', '--contains', ref] return self._gitcmd_output_list(*args) + def version_guess(self, ref): + self._check_ref_exists(ref) + + args = ['describe', '--tags', '--always', ref] + return morphlib.git.gitcmd(self._runcmd, *args).strip() + def _update_ref(self, ref_args, message): args = ['update-ref'] # No test coverage, since while this functionality is useful, |