Skip to content

Commit 283c4d4

Browse files
committed
Repair crash when attempting to export empty patch
When using git apply to generate a diffstat the diff must not be empty otherwise git exits with a failure that cascades to stg export also failing. Also repair importing an empty patch. There was a regression when splitting the diff from the description which would cause stg import to fail. The message/diff separator is now removed from the diff string. Fixes #112 Signed-off-by: Peter Grayson <[email protected]>
1 parent 311caea commit 283c4d4

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

stgit/commands/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ def __split_descr_diff(string):
343343

344344
if m:
345345
desc = string[: m.start()]
346-
diff = string[m.start() :]
346+
diff = string.split(m.group(), 1)[1]
347347
else:
348348
desc = string
349349
diff = b''

stgit/lib/git/iw.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,13 +320,16 @@ def apply(self, patch_bytes, quiet, reject=False, strip=None, context_lines=None
320320
raise MergeException('Patch does not apply cleanly')
321321

322322
def diffstat(self, diff):
323-
return (
324-
self.run(['git', 'apply', '--stat', '--summary'])
325-
.encoding(None)
326-
.raw_input(diff)
327-
.decoding('utf-8')
328-
.raw_output()
329-
)
323+
if diff:
324+
return (
325+
self.run(['git', 'apply', '--stat', '--summary'])
326+
.encoding(None)
327+
.raw_input(diff)
328+
.decoding('utf-8')
329+
.raw_output()
330+
)
331+
else:
332+
return ''
330333

331334
def changed_files(self, tree, pathlimits=()):
332335
"""Find files changed in worktree with respect to a tree.

t/t4300-export.sh

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,12 @@ test_expect_success 'Export numbered patches with custom extension' '
6666
grep -e "02-patch-2\.mydiff" export5/series
6767
'
6868

69+
test_expect_success 'Export series with empty patch' '
70+
stg new -m patch-6 &&
71+
stg export -d export6 &&
72+
test_path_is_file export6/patch-6 &&
73+
stg delete $(stg series --noprefix) &&
74+
stg import -s export6/series
75+
'
76+
6977
test_done

0 commit comments

Comments
 (0)