diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-11-04 19:36:29 +0100 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-11-04 19:41:01 +0100 |
commit | ace1fed6321bb8dd6d38b2f58d7cf815fa16db7a (patch) | |
tree | 3878d5e0282531596d42505d8725482dde002c20 /lib/git/refs.py | |
parent | f1e9df152219e85798d78284beeda88f6baa9ec7 (diff) | |
download | gitpython-ace1fed6321bb8dd6d38b2f58d7cf815fa16db7a.tar.gz |
head.checkout method added including test
Diffstat (limited to 'lib/git/refs.py')
-rw-r--r-- | lib/git/refs.py | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/lib/git/refs.py b/lib/git/refs.py index 1900c6ce..5b94ea07 100644 --- a/lib/git/refs.py +++ b/lib/git/refs.py @@ -517,7 +517,39 @@ class Head(Reference): self.path = "%s/%s" % (self._common_path_default, new_path) return self - + def checkout(self, force=False, **kwargs): + """ + Checkout this head by setting the HEAD to this reference, by updating the index + to reflect the tree we point to and by updating the working tree to reflect + the latest index. + + The command will fail if changed working tree files would be overwritten. + + ``force`` + If True, changes to the index and the working tree will be discarded. + If False, GitCommandError will be raised in that situation. + + ``**kwargs`` + Additional keyword arguments to be passed to git checkout, i.e. + b='new_branch' to create a new branch at the given spot. + + Returns + The active branch after the checkout operation, usually self unless + a new branch has been created. + + Note + By default it is only allowed to checkout heads - everything else + will leave the HEAD detached which is allowed and possible, but remains + a special state that some tools might not be able to handle. + """ + args = list() + kwargs['f'] = force + if kwargs['f'] == False: + kwargs.pop('f') + + self.repo.git.checkout(self, **kwargs) + return self.repo.active_branch + class TagReference(Reference): """ |