diff options
author | Diana Picus <diana.picus@linaro.org> | 2016-09-20 15:32:01 +0300 |
---|---|---|
committer | Diana Picus <diana.picus@linaro.org> | 2016-09-20 15:32:01 +0300 |
commit | 274d1555ebaba73d913d9ecf5aef2e454f536430 (patch) | |
tree | 0eb61acef5413390f9cbd9501ef204b5a440cfd7 | |
parent | 7f6dea61ec6b9f2ae41ccba3df95d3230b63e43e (diff) |
[Worktree] Catch attempts to track inexistent branches
-rw-r--r-- | linaropy/git/worktree.py | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/linaropy/git/worktree.py b/linaropy/git/worktree.py index a2ad241..1726b42 100644 --- a/linaropy/git/worktree.py +++ b/linaropy/git/worktree.py @@ -53,6 +53,11 @@ class Worktree(GitRepo): raise EnvironmentError( 'You must specify a local branch when creating a Worktree') + if not repo.branchexists(trackedBranch): + raise EnvironmentError( + 'Tracked branch %s does not exist in repo %s' % + (trackedBranch, repo.clonedir())) + try: with cd(repo.clonedir()): logging.info( @@ -113,7 +118,7 @@ class TestWorktree(unittest.TestCase): worktreeBranch, "Worktree is on the wrong branch") - def test_worktree_track(self): + def test_worktree_track_existing(self): worktreePath = str(os.path.join(self.proj.projdir, "worktreedir")) worktreeBranch = "worktreebranch" parentBranch = "parentbranch" @@ -134,6 +139,22 @@ class TestWorktree(unittest.TestCase): git("rev-parse", parentBranch), "Worktree branch is not based on the parent branch") + def test_worktree_track_new(self): + worktreePath = str(os.path.join(self.proj.projdir, "worktreedir")) + worktreeBranch = "worktreebranch" + parentBranch = "parentbranch" + + with self.assertRaises(EnvironmentError) as context: + self.worktree = Worktree( + self.proj, + self.repo, + worktreePath, + parentBranch, + worktreeBranch) + + self.assertEqual(context.exception.strerror, + "Tracked branch %s does not exist in repo %s" % + (parentBranch, self.repo.clonedir())) if __name__ == '__main__': # logging.basicConfig(level="INFO") |