2008-05-14 17:03:59 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2008 Johannes Schindelin
|
|
|
|
#
|
|
|
|
|
2013-02-01 03:26:21 +00:00
|
|
|
test_description='Test rebasing, stashing, etc. with submodules'
|
2008-05-14 17:03:59 +00:00
|
|
|
|
2023-02-06 19:08:08 +00:00
|
|
|
TEST_PASSES_SANITIZE_LEAK=true
|
2008-05-14 17:03:59 +00:00
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
test_expect_success setup '
|
|
|
|
|
|
|
|
echo file > file &&
|
|
|
|
git add file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m initial &&
|
|
|
|
git clone . submodule &&
|
|
|
|
git add submodule &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m submodule &&
|
|
|
|
echo second line >> file &&
|
|
|
|
(cd submodule && git pull) &&
|
|
|
|
test_tick &&
|
2013-02-01 03:26:21 +00:00
|
|
|
git commit -m file-and-submodule -a &&
|
|
|
|
git branch added-submodule
|
2008-05-14 17:03:59 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase with a dirty submodule' '
|
|
|
|
|
|
|
|
(cd submodule &&
|
|
|
|
echo 3rd line >> file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m fork -a) &&
|
|
|
|
echo unrelated >> file2 &&
|
|
|
|
git add file2 &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m unrelated file2 &&
|
|
|
|
echo other line >> file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m update file &&
|
|
|
|
CURRENT=$(cd submodule && git rev-parse HEAD) &&
|
|
|
|
EXPECTED=$(git rev-parse HEAD~2:submodule) &&
|
|
|
|
GIT_TRACE=1 git rebase --onto HEAD~2 HEAD^ &&
|
|
|
|
STORED=$(git rev-parse HEAD:submodule) &&
|
|
|
|
test $EXPECTED = $STORED &&
|
|
|
|
test $CURRENT = $(cd submodule && git rev-parse HEAD)
|
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
cat > fake-editor.sh << \EOF
|
|
|
|
#!/bin/sh
|
|
|
|
echo $EDITOR_TEXT
|
|
|
|
EOF
|
|
|
|
chmod a+x fake-editor.sh
|
|
|
|
|
|
|
|
test_expect_success 'interactive rebase with a dirty submodule' '
|
|
|
|
|
2023-02-06 22:44:31 +00:00
|
|
|
echo submodule >expect &&
|
|
|
|
git diff --name-only >actual &&
|
|
|
|
test_cmp expect actual &&
|
2008-05-14 17:03:59 +00:00
|
|
|
HEAD=$(git rev-parse HEAD) &&
|
|
|
|
GIT_EDITOR="\"$(pwd)/fake-editor.sh\"" EDITOR_TEXT="pick $HEAD" \
|
|
|
|
git rebase -i HEAD^ &&
|
2023-02-06 22:44:31 +00:00
|
|
|
echo submodule >expect &&
|
|
|
|
git diff --name-only >actual &&
|
|
|
|
test_cmp expect actual
|
2008-05-14 17:03:59 +00:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'rebase with dirty file and submodule fails' '
|
|
|
|
|
|
|
|
echo yet another line >> file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m next file &&
|
|
|
|
echo rewrite > file &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m rewrite file &&
|
|
|
|
echo dirty > file &&
|
2008-07-12 15:47:52 +00:00
|
|
|
test_must_fail git rebase --onto HEAD~2 HEAD^
|
2008-05-14 17:03:59 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'stash with a dirty submodule' '
|
|
|
|
|
|
|
|
echo new > file &&
|
|
|
|
CURRENT=$(cd submodule && git rev-parse HEAD) &&
|
|
|
|
git stash &&
|
|
|
|
test new != $(cat file) &&
|
2023-02-06 22:44:30 +00:00
|
|
|
echo submodule >expect &&
|
|
|
|
git diff --name-only >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
|
|
|
|
echo "$CURRENT" >expect &&
|
|
|
|
git -C submodule rev-parse HEAD >actual &&
|
|
|
|
test_cmp expect actual &&
|
|
|
|
|
2008-05-14 17:03:59 +00:00
|
|
|
git stash apply &&
|
|
|
|
test new = $(cat file) &&
|
2023-02-06 22:44:30 +00:00
|
|
|
echo "$CURRENT" >expect &&
|
|
|
|
git -C submodule rev-parse HEAD >actual &&
|
|
|
|
test_cmp expect actual
|
2008-05-14 17:03:59 +00:00
|
|
|
|
|
|
|
'
|
|
|
|
|
2013-02-01 03:26:21 +00:00
|
|
|
test_expect_success 'rebasing submodule that should conflict' '
|
|
|
|
git reset --hard &&
|
|
|
|
git checkout added-submodule &&
|
|
|
|
git add submodule &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m third &&
|
|
|
|
(
|
|
|
|
cd submodule &&
|
|
|
|
git commit --allow-empty -m extra
|
|
|
|
) &&
|
|
|
|
git add submodule &&
|
|
|
|
test_tick &&
|
|
|
|
git commit -m fourth &&
|
|
|
|
|
2022-08-04 19:51:05 +00:00
|
|
|
test_must_fail git rebase --onto HEAD^^ HEAD^ HEAD^0 >actual_output &&
|
2013-02-01 03:26:21 +00:00
|
|
|
git ls-files -s submodule >actual &&
|
|
|
|
(
|
|
|
|
cd submodule &&
|
|
|
|
echo "160000 $(git rev-parse HEAD^) 1 submodule" &&
|
|
|
|
echo "160000 $(git rev-parse HEAD^^) 2 submodule" &&
|
|
|
|
echo "160000 $(git rev-parse HEAD) 3 submodule"
|
|
|
|
) >expect &&
|
2022-08-04 19:51:05 +00:00
|
|
|
test_cmp expect actual &&
|
|
|
|
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
|
|
|
|
then
|
|
|
|
sub_expect="go to submodule (submodule), and either merge commit $(git -C submodule rev-parse --short HEAD^0)" &&
|
|
|
|
grep "$sub_expect" actual_output
|
|
|
|
fi
|
2013-02-01 03:26:21 +00:00
|
|
|
'
|
|
|
|
|
2008-05-14 17:03:59 +00:00
|
|
|
test_done
|