diff options
-rw-r--r-- | lib/git/cmd.py | 14 | ||||
-rw-r--r-- | lib/git/index/base.py | 4 | ||||
-rw-r--r-- | lib/git/refs.py | 25 | ||||
-rw-r--r-- | test/git/test_refs.py | 11 |
4 files changed, 45 insertions, 9 deletions
diff --git a/lib/git/cmd.py b/lib/git/cmd.py index cd848e05..60887f5d 100644 --- a/lib/git/cmd.py +++ b/lib/git/cmd.py @@ -337,16 +337,18 @@ class Git(object): proc.stdout.close() proc.stderr.close() - if with_exceptions and status != 0: - raise GitCommandError(command, status, stderr_value) - if GIT_PYTHON_TRACE == 'full': + cmdstr = " ".join(command) if stderr_value: - print "%s -> %d: '%s' !! '%s'" % (command, status, stdout_value, stderr_value) + print "%s -> %d; stdout: '%s'; stderr: '%s'" % (cmdstr, status, stdout_value, stderr_value) elif stdout_value: - print "%s -> %d: '%s'" % (command, status, stdout_value) + print "%s -> %d; stdout: '%s'" % (cmdstr, status, stdout_value) else: - print "%s -> %d" % (command, status) + print "%s -> %d" % (cmdstr, status) + # END handle debug printing + + if with_exceptions and status != 0: + raise GitCommandError(command, status, stderr_value) # Allow access to the command's status code if with_extended_output: diff --git a/lib/git/index/base.py b/lib/git/index/base.py index 86160990..a28374b0 100644 --- a/lib/git/index/base.py +++ b/lib/git/index/base.py @@ -1059,6 +1059,9 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): :param head: If True, the head will be set to the given commit. This is False by default, but if True, this method behaves like HEAD.reset. + + :param paths: if given as an iterable of absolute or repository-relative paths, + only these will be reset to their state at the given commit'ish :param kwargs: Additional keyword arguments passed to git-reset @@ -1080,6 +1083,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): else: # what we actually want to do is to merge the tree into our existing # index, which is what git-read-tree does + # TODO: incorporate the given paths ! new_inst = type(self).from_tree(self.repo, commit) self.entries = new_inst.entries self.write() diff --git a/lib/git/refs.py b/lib/git/refs.py index 03b80690..be6ec5e3 100644 --- a/lib/git/refs.py +++ b/lib/git/refs.py @@ -29,6 +29,7 @@ from gitdb.util import ( hex_to_bin ) +from exc import GitCommandError __all__ = ("SymbolicReference", "Reference", "HEAD", "Head", "TagReference", "RemoteReference", "Tag" ) @@ -646,16 +647,36 @@ class HEAD(SymbolicReference): :return: self""" mode = "--soft" + add_arg = None if index: mode = "--mixed" + # it appears, some git-versions declare mixed and paths deprecated + # see http://github.com/Byron/GitPython/issues#issue/2 + if paths: + mode = None + # END special case + # END handle index + if working_tree: mode = "--hard" if not index: - raise ValueError( "Cannot reset the working tree if the index is not reset as well") + raise ValueError( "Cannot reset the working tree if the index is not reset as well") + # END working tree handling - self.repo.git.reset(mode, commit, paths, **kwargs) + if paths: + add_arg = "--" + # END nicely separate paths from rest + + try: + self.repo.git.reset(mode, commit, add_arg, paths, **kwargs) + except GitCommandError, e: + # git nowadays may use 1 as status to indicate there are still unstaged + # modifications after the reset + if e.status != 1: + raise + # END handle exception return self diff --git a/test/git/test_refs.py b/test/git/test_refs.py index b73d574b..99a66fc2 100644 --- a/test/git/test_refs.py +++ b/test/git/test_refs.py @@ -89,6 +89,7 @@ class TestRefs(TestBase): @with_rw_repo('0.1.6') def test_head_reset(self, rw_repo): cur_head = rw_repo.head + old_head_commit = cur_head.commit new_head_commit = cur_head.ref.commit.parents[0] cur_head.reset(new_head_commit, index=True) # index only assert cur_head.reference.commit == new_head_commit @@ -98,8 +99,16 @@ class TestRefs(TestBase): cur_head.reset(new_head_commit, index=True, working_tree=True) # index + wt assert cur_head.reference.commit == new_head_commit - # paths + # paths - make sure we have something to do + rw_repo.index.reset(old_head_commit.parents[0]) + cur_head.reset(cur_head, paths = "test") cur_head.reset(new_head_commit, paths = "lib") + # hard resets with paths don't work, its all or nothing + self.failUnlessRaises(GitCommandError, cur_head.reset, new_head_commit, working_tree=True, paths = "lib") + + # we can do a mixed reset, and then checkout from the index though + cur_head.reset(new_head_commit) + rw_repo.index.checkout(["lib"], force=True)# # now that we have a write write repo, change the HEAD reference - its |