diff options
author | Ryan S. Arnold <ryan.arnold@linaro.org> | 2016-08-20 01:04:53 -0500 |
---|---|---|
committer | Ryan S. Arnold <ryan.arnold@linaro.org> | 2016-08-20 01:04:53 -0500 |
commit | 737c797232f444acee6462df4deb41ad06be7021 (patch) | |
tree | a2297998b694298f167d14724077cbaabfafc508 /linaropy/git/gitrepo.py | |
parent | 9dac4d48397f5f805e78523f2ee2214b1f09facf (diff) |
Add support for generating 'release' release notes using tags.
This required quite a bit of refactoring.
Added series_from_tag functions and corresponding tests, as
well as series_from_branch input tests that test input
conformance.
Removed unnecessary CandidateRN, SnapshotRN, and ReleaseRN
classes to shallow the topology.
Diffstat (limited to 'linaropy/git/gitrepo.py')
-rw-r--r-- | linaropy/git/gitrepo.py | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/linaropy/git/gitrepo.py b/linaropy/git/gitrepo.py index 99b2573..b9f2c03 100644 --- a/linaropy/git/gitrepo.py +++ b/linaropy/git/gitrepo.py @@ -45,6 +45,7 @@ class GitRepo(object): raise TypeError('proj input parameter is not of type Proj') def branchexists(self, branch): + logging.info("Checking to see if branch %s exists" % branch) with cd(self.repodir): try: # Quote the branchname because it might have strange @@ -52,6 +53,7 @@ class GitRepo(object): br="%s" % branch git("rev-parse", "--verify", br) except ErrorReturnCode_128: + logging.info("Couldn't find branch %s" % branch) return False return True @@ -63,6 +65,11 @@ class GitRepo(object): raise EnvironmentError("Unable to get the current branch") return branch + # TODO make this a bit more sophisticated because the user might not be + # using 'origin' as their remote name. + def remote_branchname(self, branchname): + return "remotes/origin/" + branchname + # TODO: Fully test this. # Stash current changes and change to new branch. # Return to previous branch when context is exited. @@ -125,18 +132,23 @@ class GitRepo(object): # TODO: Write a unit test for this. # TODO: fix the default def commit(self, message="default"): - print "Committing changes." + logging.info("Attempting to commit changes to %s" % self.repodir ) try: with cd(self.repodir): # Git commit first with a boiler plate message and then allow the user # to amend. if git("status", "--porcelain"): - # print git("commit", "-m", '%s' % message, _err_to_out=True) + # using python sh will suppress the git editor subprocess.call(["git", "commit", "-m", message]) - # using python sh will suppress the git editor subprocess.call(["git", "commit", "--amend"]) + else: + logging.info("Nothing to commit.") + return False except ErrorReturnCode: raise EnvironmentError("Unable to git commit ") + return False + # Something was committed. + return True def log(self, number): try: @@ -146,7 +158,7 @@ class GitRepo(object): raise EnvironmentError("Unable to git add " + filetogitadd) # TODO: Does this need to 'cd' first? - def editFile(self, toedit): + def edit(self, toedit): editor = os.getenv('EDITOR') if not editor: editor='/usr/bin/vim' @@ -169,6 +181,17 @@ class GitRepo(object): except ErrorReturnCode: raise EnvironmentError("Unable to push branch %s to %s" % (branch, tobranch)) + def tag_exists(self, tag): + try: + with cd(self.repodir): + print("testing tag %s on repo %s" % (tag, self.repodir)) + tagref="refs/tags/%s" % tag + git("rev-parse", "-q", "--verify", tagref) + except ErrorReturnCode_128: + logging.info("Couldn't find tag %s" % tag) + return False + return True + def __str__(self): return self.repodir @@ -212,8 +235,10 @@ class TestGitRepo(unittest.TestCase): # TODO: Create a test-branch in the repo so it's always there. - def test_branchexists(self): - self.assertTrue(self.dgr.branchexists("remotes/origin/releases/linaro-4.9-2015.05")) + def test_tag_exists(self): + with cd(self.dgr.repodir): + git("tag", "-a", "linaro-99.9-2099.08-rc1", "-m", "This is a test tag") + self.assertTrue(self.dgr.tag_exists("linaro-99.9-2099.08-rc1")) def test_not_branchexists(self): self.assertFalse(self.dgr.branchexists("foobar")) |