diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2009-10-22 17:40:04 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2009-10-22 17:40:04 +0200 |
commit | 20c34a929a8b2871edd4fd44a38688e8977a4be6 (patch) | |
tree | d4dc6dd2207ddc6b9ad3253468f843849f5dc14a /lib/git/refs.py | |
parent | 3c658c16f3437ed7e78f6072b6996cb423a8f504 (diff) | |
download | gitpython-20c34a929a8b2871edd4fd44a38688e8977a4be6.tar.gz |
Added reset method to Head - its a class method due to the very general nature of the command. Yet I don't really like the way you have to call it as repo has to be ṕassed as first arg
Diffstat (limited to 'lib/git/refs.py')
-rw-r--r-- | lib/git/refs.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/lib/git/refs.py b/lib/git/refs.py index 8c9d6672..9a03b6f5 100644 --- a/lib/git/refs.py +++ b/lib/git/refs.py @@ -174,6 +174,52 @@ class Head(Reference): """ return self.object + @classmethod + def reset(cls, repo, commit='HEAD', index=True, working_tree = False, + paths=None, **kwargs): + """ + Reset the current head to the given commit optionally synchronizing + the index and working tree. + + ``repo`` + Repository containing commit + + ``commit`` + Commit object, Reference Object or string identifying a revision + + ``index`` + If True, the index will be set to match the given commit. Otherwise + it will not be touched. + + ``working_tree`` + If True, the working tree will be forcefully adjusted to match the given + commit, possibly overwriting uncommitted changes without warning. + If working_tree is True, index must be true as well + + ``paths`` + Single path or list of paths relative to the git root directory + that are to be reset. This allow to partially reset individual files. + + ``kwargs`` + Additional arguments passed to git-reset. + + Returns + Head pointing to the specified commit + """ + mode = "--soft" + if index: + mode = "--mixed" + + if working_tree: + mode = "--hard" + if not index: + raise ValueError( "Cannot reset the working tree if the index is not reset as well") + # END working tree handling + + repo.git.reset(mode, commit, paths, **kwargs) + + # we always point to the active branch as it is the one changing + return repo.active_branch class TagReference(Head): """ |