aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gbp/git.py9
-rw-r--r--tests/test_GitRepository.py31
2 files changed, 40 insertions, 0 deletions
diff --git a/gbp/git.py b/gbp/git.py
index 66aec401..dbf918a2 100644
--- a/gbp/git.py
+++ b/gbp/git.py
@@ -633,6 +633,15 @@ class GitRepository(object):
return sha[0].strip()
#{ Trees
+ def checkout(self, treeish):
+ """
+ Checkout treeish
+
+ @param treeish: the treeish to check out
+ @type treeish: C{str}
+ """
+ self._git_command("checkout", ["--quiet", treeish])
+
def has_treeish(self, treeish):
"""
Check if the repository has the treeish object I{treeish}.
diff --git a/tests/test_GitRepository.py b/tests/test_GitRepository.py
index f7e5e97a..235c758d 100644
--- a/tests/test_GitRepository.py
+++ b/tests/test_GitRepository.py
@@ -368,6 +368,37 @@ def test_create_bare():
(True, '')
"""
+def test_checkout():
+ """
+ Checkout treeishs
+
+ Methods tested:
+ - L{gbp.git.GitRepository.checkout}
+ - L{gbp.git.GitRepository.get_branch}
+ - L{gbp.git.GitRepository.set_branch}
+ - L{gbp.git.GitRepository.rev_parse}
+
+ Properties tested:
+ - L{gbp.git.GitRepository.branch}
+ - L{gbp.git.GitRepository.tags}
+
+ >>> import gbp.git
+ >>> repo = gbp.git.GitRepository(repo_dir)
+ >>> repo.checkout('master')
+ >>> repo.branch
+ 'master'
+ >>> sha1 = repo.rev_parse('master')
+ >>> repo.checkout(sha1)
+ >>> repo.branch
+ >>> repo.get_branch()
+ Traceback (most recent call last):
+ ...
+ GitRepositoryError: Currently not on a branch
+ >>> tag = repo.tags[0]
+ >>> repo.checkout(tag)
+ >>> repo.branch
+ """
+
def test_teardown():
"""
Perform the teardown