Skip to contentSkip to conversation

rebase -i squashes submodule changes into unrelated commit

Bug New Junio C Hamano 2 participants 3 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Attempting to rebase three-commit series (two regular changes, followed by one commit that changes what commit is bound for a submodule path) to squash the first two results in a failure; not just the first two commits squashed, but the change to the submodule is also included in the result.

This failure causes the subsequent step to "pick" the change that actually changes the submodule to be applied, because there is no change left to be applied.

---
 t/t3404-rebase-interactive.sh |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
t/t3404-rebase-interactive.sh +26 -0
index 2cc8e7a..6ffb9ad 100755
@@ -462,4 +462,30 @@ test_expect_success 'do "noop" when there is nothing to cherry-pick' '
 
 '
 
+test_expect_success 'submodule rebase setup' '
+	git checkout A &&
+	mkdir sub &&
+	(
+		cd sub && git init && >elif &&
+		git add elif && git commit -m "submodule initial"
+	) &&
+	echo 1 >file1 &&
+	git add file1 sub
+	test_tick &&
+	git commit -m "One" &&
+	echo 2 >file1 &&
+	test_tick &&
+	git commit -a -m "Two" &&
+	(
+		cd sub && echo 3 >elif &&
+		git commit -a -m "submodule second"
+	) &&
+	test_tick &&
+	git commit -a -m "Three changes submodule"
+'
+
+test_expect_failure 'submodule rebase -i' '
+	FAKE_LINES="1 squash 2 3" git rebase -i A
+'
+
 test_done
#1 lore raw
Quoted 8 lines · Junio C Hamano

Attempting to rebase three-commit series (two regular changes, followed by one commit that changes what commit is bound for a submodule path) to squash the first two results in a failure; not just the first two commits squashed, but the change to the submodule is also included in the result.

This failure causes the subsequent step to "pick" the change that actually changes the submodule to be applied, because there is no change left to be applied.

Sorry, an obvious typo is here: s/to be applied,/to fail,/;

#2 lore raw

PATCH 1/1 Fix submodule squashing into unrelated commit

In reply to Junio C Hamano

Actually, I think the issue is pretty independent of submodules; when "git commit" gets an empty parameter, it misinterprets it as a file.

So avoid passing an empty parameter to "git commit".

Actually, this is a nice cleanup, as MSG_FILE and EDIT_COMMIT were mutually exclusive; use one variable instead

---

We might want to safeguard "git commit", too.

 git-rebase--interactive.sh    |    9 ++++-----
 t/t3404-rebase-interactive.sh |    2 +-
 2 files changed, 5 insertions(+), 6 deletions(-)
git-rebase--interactive.sh +4 -5
index 002929e..3ac7162 100755
@@ -373,17 +373,15 @@ do_next () {
 		pick_one -n $sha1 || failed=t
 		case "$(peek_next_command)" in
 		squash|s)
-			EDIT_COMMIT=
 			USE_OUTPUT=output
 			MSG_OPT=-F
-			MSG_FILE="$MSG"
+			EDIT_OR_FILE="$MSG"
 			cp "$MSG" "$SQUASH_MSG"
 			;;
 		*)
-			EDIT_COMMIT=-e
 			USE_OUTPUT=
 			MSG_OPT=
-			MSG_FILE=
+			EDIT_OR_FILE=-e
 			rm -f "$SQUASH_MSG" || exit
 			cp "$MSG" "$GIT_DIR"/SQUASH_MSG
 			rm -f "$GIT_DIR"/MERGE_MSG || exit
@@ -397,7 +395,8 @@ do_next () {
 			GIT_AUTHOR_NAME="$GIT_AUTHOR_NAME" \
 			GIT_AUTHOR_EMAIL="$GIT_AUTHOR_EMAIL" \
 			GIT_AUTHOR_DATE="$GIT_AUTHOR_DATE" \
-			$USE_OUTPUT git commit --no-verify $MSG_OPT "$MSG_FILE" $EDIT_COMMIT || failed=t
+			$USE_OUTPUT git commit --no-verify \
+				$MSG_OPT "$EDIT_OR_FILE" || failed=t
 		fi
 		if test $failed = t
 		then
t/t3404-rebase-interactive.sh +1 -1
index 6ffb9ad..4becc55 100755
@@ -484,7 +484,7 @@ test_expect_success 'submodule rebase setup' '
 	git commit -a -m "Three changes submodule"
 '
 
-test_expect_failure 'submodule rebase -i' '
+test_expect_success 'submodule rebase -i' '
 	FAKE_LINES="1 squash 2 3" git rebase -i A
 '
 
Signature · 1 line
1.6.1.482.g7d54be