If committing a patch in the middle of a series, the resulting stack
doesn't have any patches applied. The trans.pop_patches() function only
returns the additional patches that had to be popped rather than all
popped patches. The patch also adds some tests for the 'commit' command.
Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
Reported-by: Jeenu Viswambharan <Jeenu.Viswambharan@arm.com>
Cc: Karl Hasselström <kha@treskal.com>
for i in xrange(min(len(stack.patchorder.applied), len(patches))):
if stack.patchorder.applied[i] == patches[i]:
common_prefix += 1
+ else:
+ break
if common_prefix < len(patches):
- to_push = trans.pop_patches(
- lambda pn: pn in stack.patchorder.applied[common_prefix:])
+ to_push = [pn for pn in stack.patchorder.applied[common_prefix:]
+ if pn not in patches[common_prefix:]]
+ # this pops all the applied patches from common_prefix
+ trans.pop_patches(lambda pn: pn in to_push)
for pn in patches[common_prefix:]:
trans.push_patch(pn, iw)
else:
stg init
'
+test_expect_success 'Commit middle patch' '
+ stg new -m p1 &&
+ stg new -m p2 &&
+ stg new -m p3 &&
+ stg new -m p4 &&
+ stg pop &&
+ stg commit p2 &&
+ test "$(echo $(stg series))" = "+ p1 > p3 - p4"
+'
+
+test_expect_success 'Commit first patch' '
+ stg commit &&
+ test "$(echo $(stg series))" = "> p3 - p4"
+'
+
+test_expect_success 'Commit all patches' '
+ stg push &&
+ stg commit -a &&
+ test "$(echo $(stg series))" = ""
+'
+
# stg commit with top != head should not succeed, since the committed
# patches are poptentially lost.
test_expect_success 'Commit when top != head (should fail)' '