From 20c34a929a8b2871edd4fd44a38688e8977a4be6 Mon Sep 17 00:00:00 2001 From: Sebastian Thiel Date: Thu, 22 Oct 2009 17:40:04 +0200 Subject: =?UTF-8?q?Added=20reset=20method=20to=20Head=20-=20its=20a=20clas?= =?UTF-8?q?s=20method=20due=20to=20the=20very=20general=20nature=20of=20th?= =?UTF-8?q?e=20command.=20Yet=20I=20don't=20really=20like=20the=20way=20yo?= =?UTF-8?q?u=20have=20to=20call=20it=20as=20repo=20has=20to=20be=20?= =?UTF-8?q?=E1=B9=95assed=20as=20first=20arg?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/git/refs.py | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'lib/git/refs.py') 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): """ -- cgit v1.2.1