Skip to content

Commit 3326f34

Browse files
committed
index: Checkout exception now contains information about the reason of the failure as well, one per failed file
1 parent f6102b3 commit 3326f34

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/git/index.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@ class CheckoutError( Exception ):
3131
The .failed_files attribute contains a list of relative paths that failed
3232
to be checked out as they contained changes that did not exist in the index.
3333
34+
The .failed_reasons attribute contains a string informing about the actual
35+
cause of the issue.
36+
3437
The .valid_files attribute contains a list of relative paths to files that
3538
were checked out successfully and hence match the version stored in the
3639
index"""
37-
def __init__(self, message, failed_files, valid_files):
40+
def __init__(self, message, failed_files, valid_files, failed_reasons):
3841
Exception.__init__(self, message)
3942
self.failed_files = failed_files
43+
self.failed_reasons = failed_reasons
4044
self.valid_files = valid_files
4145

4246
def __str__(self):
@@ -1101,6 +1105,7 @@ def handle_stderr(proc, iter_checked_out_files):
11011105
# line contents:
11021106
# git-checkout-index: this already exists
11031107
failed_files = list()
1108+
failed_reasons = list()
11041109
unknown_lines = list()
11051110
endings = (' already exists', ' is not in the cache', ' does not exist at stage', ' is unmerged')
11061111
for line in stderr.splitlines():
@@ -1109,8 +1114,10 @@ def handle_stderr(proc, iter_checked_out_files):
11091114
unlink_issue = "unable to unlink old '"
11101115
if line.endswith(is_a_dir):
11111116
failed_files.append(line[:-len(is_a_dir)])
1117+
failed_reasons.append(is_a_dir)
11121118
elif line.startswith(unlink_issue):
11131119
failed_files.append(line[len(unlink_issue):line.rfind("'")])
1120+
failed_reasons.append(unlink_issue)
11141121
else:
11151122
unknown_lines.append(line)
11161123
continue
@@ -1119,6 +1126,7 @@ def handle_stderr(proc, iter_checked_out_files):
11191126
for e in endings:
11201127
if line.endswith(e):
11211128
failed_files.append(line[20:-len(e)])
1129+
failed_reasons.append(e)
11221130
break
11231131
# END if ending matches
11241132
# END for each possible ending
@@ -1127,7 +1135,7 @@ def handle_stderr(proc, iter_checked_out_files):
11271135
raise GitCommandError(("git-checkout-index", ), 128, stderr)
11281136
if failed_files:
11291137
valid_files = list(set(iter_checked_out_files) - set(failed_files))
1130-
raise CheckoutError("Some files could not be checked out from the index due to local modifications", failed_files, valid_files)
1138+
raise CheckoutError("Some files could not be checked out from the index due to local modifications", failed_files, valid_files, failed_reasons)
11311139
# END stderr handler
11321140

11331141

test/git/test_index.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ def test_index_file_diffing(self, rw_repo):
302302
index.checkout(test_file)
303303
except CheckoutError, e:
304304
assert len(e.failed_files) == 1 and e.failed_files[0] == os.path.basename(test_file)
305+
assert (len(e.failed_files) == len(e.failed_reasons)) and isinstance(e.failed_reasons[0], basestring)
305306
assert len(e.valid_files) == 0
306307
assert open(test_file).read().endswith(append_data)
307308
else:

0 commit comments

Comments
 (0)