Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit2c0b92e

Browse files
committed
cmd: improved error handling and debug printing
head.reset: will now handle resets with paths much better, especially in the --mixed case, seehttp://github.com/Byron/GitPython/issues#issue/2
1 parent97ab197 commit2c0b92e

File tree

4 files changed

+45
-9
lines changed

4 files changed

+45
-9
lines changed

‎lib/git/cmd.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -337,16 +337,18 @@ def execute(self, command,
337337
proc.stdout.close()
338338
proc.stderr.close()
339339

340-
ifwith_exceptionsandstatus!=0:
341-
raiseGitCommandError(command,status,stderr_value)
342-
343340
ifGIT_PYTHON_TRACE=='full':
341+
cmdstr=" ".join(command)
344342
ifstderr_value:
345-
print"%s -> %d: '%s' !! '%s'"% (command,status,stdout_value,stderr_value)
343+
print"%s -> %d; stdout: '%s'; stderr: '%s'"% (cmdstr,status,stdout_value,stderr_value)
346344
elifstdout_value:
347-
print"%s -> %d: '%s'"% (command,status,stdout_value)
345+
print"%s -> %d; stdout: '%s'"% (cmdstr,status,stdout_value)
348346
else:
349-
print"%s -> %d"% (command,status)
347+
print"%s -> %d"% (cmdstr,status)
348+
# END handle debug printing
349+
350+
ifwith_exceptionsandstatus!=0:
351+
raiseGitCommandError(command,status,stderr_value)
350352

351353
# Allow access to the command's status code
352354
ifwith_extended_output:

‎lib/git/index/base.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,6 +1059,9 @@ def reset(self, commit='HEAD', working_tree=False, paths=None, head=False, **kwa
10591059
:param head:
10601060
If True, the head will be set to the given commit. This is False by default,
10611061
but if True, this method behaves like HEAD.reset.
1062+
1063+
:param paths: if given as an iterable of absolute or repository-relative paths,
1064+
only these will be reset to their state at the given commit'ish
10621065
10631066
:param kwargs:
10641067
Additional keyword arguments passed to git-reset
@@ -1080,6 +1083,7 @@ def reset(self, commit='HEAD', working_tree=False, paths=None, head=False, **kwa
10801083
else:
10811084
# what we actually want to do is to merge the tree into our existing
10821085
# index, which is what git-read-tree does
1086+
# TODO: incorporate the given paths !
10831087
new_inst=type(self).from_tree(self.repo,commit)
10841088
self.entries=new_inst.entries
10851089
self.write()

‎lib/git/refs.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
hex_to_bin
3030
)
3131

32+
fromexcimportGitCommandError
3233

3334
__all__= ("SymbolicReference","Reference","HEAD","Head","TagReference",
3435
"RemoteReference","Tag" )
@@ -646,16 +647,36 @@ def reset(self, commit='HEAD', index=True, working_tree = False,
646647
647648
:return: self"""
648649
mode="--soft"
650+
add_arg=None
649651
ifindex:
650652
mode="--mixed"
651653

654+
# it appears, some git-versions declare mixed and paths deprecated
655+
# see http://github.com/Byron/GitPython/issues#issue/2
656+
ifpaths:
657+
mode=None
658+
# END special case
659+
# END handle index
660+
652661
ifworking_tree:
653662
mode="--hard"
654663
ifnotindex:
655-
raiseValueError("Cannot reset the working tree if the index is not reset as well")
664+
raiseValueError("Cannot reset the working tree if the index is not reset as well")
665+
656666
# END working tree handling
657667

658-
self.repo.git.reset(mode,commit,paths,**kwargs)
668+
ifpaths:
669+
add_arg="--"
670+
# END nicely separate paths from rest
671+
672+
try:
673+
self.repo.git.reset(mode,commit,add_arg,paths,**kwargs)
674+
exceptGitCommandError,e:
675+
# git nowadays may use 1 as status to indicate there are still unstaged
676+
# modifications after the reset
677+
ife.status!=1:
678+
raise
679+
# END handle exception
659680

660681
returnself
661682

‎test/git/test_refs.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ def test_is_valid(self):
8989
@with_rw_repo('0.1.6')
9090
deftest_head_reset(self,rw_repo):
9191
cur_head=rw_repo.head
92+
old_head_commit=cur_head.commit
9293
new_head_commit=cur_head.ref.commit.parents[0]
9394
cur_head.reset(new_head_commit,index=True)# index only
9495
assertcur_head.reference.commit==new_head_commit
@@ -98,8 +99,16 @@ def test_head_reset(self, rw_repo):
9899
cur_head.reset(new_head_commit,index=True,working_tree=True)# index + wt
99100
assertcur_head.reference.commit==new_head_commit
100101

101-
# paths
102+
# paths - make sure we have something to do
103+
rw_repo.index.reset(old_head_commit.parents[0])
104+
cur_head.reset(cur_head,paths="test")
102105
cur_head.reset(new_head_commit,paths="lib")
106+
# hard resets with paths don't work, its all or nothing
107+
self.failUnlessRaises(GitCommandError,cur_head.reset,new_head_commit,working_tree=True,paths="lib")
108+
109+
# we can do a mixed reset, and then checkout from the index though
110+
cur_head.reset(new_head_commit)
111+
rw_repo.index.checkout(["lib"],force=True)#
103112

104113

105114
# now that we have a write write repo, change the HEAD reference - its

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp