Ignore dirty submodule states during rebase and stash
When rebasing or stashing, chances are that you do not care about dirty submodules, since they are not updated by those actions anyway. So ignore the submodules' states. Note: the submodule states -- as committed in the superproject -- will still be stashed and rebased, it is _just_ the state of the submodule in the working tree which is ignored. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Schindelin committed
May 14, 2008 at 18:03 UTC
6848d58c60b7af365ce54cf3e3b274a2f9da2e7e
4 files changed
+105
-12
git-rebase--interactive.sh
+6
-5
@@ -56,9 +56,9 @@ output () {
56
require_clean_work_tree () {
57
# test if working tree is dirty
58
git rev-parse --verify HEAD > /dev/null &&
59
- git update-index --refresh &&
60
- git diff-files --quiet &&
61
- git diff-index --cached --quiet HEAD -- ||
59
+ git update-index --ignore-submodules --refresh &&
60
+ git diff-files --quiet --ignore-submodules &&
61
+ git diff-index --cached --quiet HEAD --ignore-submodules -- ||
62
die "Working tree is dirty"
63
}
64
@@ -377,11 +377,12 @@ do
377
# Sanity check
378
git rev-parse --verify HEAD >/dev/null ||
379
die "Cannot read HEAD"
380
- git update-index --refresh && git diff-files --quiet ||
380
+ git update-index --ignore-submodules --refresh &&
381
+ git diff-files --quiet --ignore-submodules ||
382
die "Working tree is dirty"
383
384
# do we have anything to commit?
384
- if git diff-index --cached --quiet HEAD --
385
+ if git diff-index --cached --quiet --ignore-submodules HEAD --
386
then
387
: Nothing to commit -- skip this
388
else
git-rebase.sh
+4
-4
@@ -60,7 +60,7 @@ continue_merge () {
60
fi
61
62
cmt=`cat "$dotest/current"`
63
- if ! git diff-index --quiet HEAD --
63
+ if ! git diff-index --quiet --ignore-submodules HEAD --
64
then
65
if ! git commit --no-verify -C "$cmt"
66
then
@@ -150,7 +150,7 @@ while test $# != 0
150
do
151
case "$1" in
152
--continue)
153
- git diff-files --quiet || {
153
+ git diff-files --quiet --ignore-submodules || {
154
echo "You must edit all merge conflicts and then"
155
echo "mark them as resolved using git add"
156
exit 1
@@ -282,8 +282,8 @@ else
282
fi
283
284
# The tree must be really really clean.
285
-git update-index --refresh || exit
286
-diff=$(git diff-index --cached --name-status -r HEAD --)
285
+git update-index --ignore-submodules --refresh || exit
286
+diff=$(git diff-index --cached --name-status -r --ignore-submodules HEAD --)
287
case "$diff" in
288
?*) echo "cannot rebase: your index is not up-to-date"
289
echo "$diff"
git-stash.sh
+3
-3
@@ -15,8 +15,8 @@ trap 'rm -f "$TMP-*"' 0
15
ref_stash=refs/stash
16
17
no_changes () {
18
- git diff-index --quiet --cached HEAD -- &&
19
- git diff-files --quiet
18
+ git diff-index --quiet --cached HEAD --ignore-submodules -- &&
19
+ git diff-files --quiet --ignore-submodules
20
}
21
22
clear_stash () {
@@ -130,7 +130,7 @@ show_stash () {
130
}
131
132
apply_stash () {
133
- git diff-files --quiet ||
133
+ git diff-files --quiet --ignore-submodules ||
134
die 'Cannot restore on top of a dirty state'
135
136
unstash_index=
t/t7402-submodule-rebase.sh
new
+92
@@ -0,0 +1,92 @@
1
+#!/bin/sh
2
+#
3
+# Copyright (c) 2008 Johannes Schindelin
4
+#
5
+
6
+test_description='Test rebasing and stashing with dirty submodules'
7
+
8
+. ./test-lib.sh
9
+
10
+test_expect_success setup '
11
+
12
+ echo file > file &&
13
+ git add file &&
14
+ test_tick &&
15
+ git commit -m initial &&
16
+ git clone . submodule &&
17
+ git add submodule &&
18
+ test_tick &&
19
+ git commit -m submodule &&
20
+ echo second line >> file &&
21
+ (cd submodule && git pull) &&
22
+ test_tick &&
23
+ git commit -m file-and-submodule -a
24
+
25
+'
26
+
27
+test_expect_success 'rebase with a dirty submodule' '
28
+
29
+ (cd submodule &&
30
+ echo 3rd line >> file &&
31
+ test_tick &&
32
+ git commit -m fork -a) &&
33
+ echo unrelated >> file2 &&
34
+ git add file2 &&
35
+ test_tick &&
36
+ git commit -m unrelated file2 &&
37
+ echo other line >> file &&
38
+ test_tick &&
39
+ git commit -m update file &&
40
+ CURRENT=$(cd submodule && git rev-parse HEAD) &&
41
+ EXPECTED=$(git rev-parse HEAD~2:submodule) &&
42
+ GIT_TRACE=1 git rebase --onto HEAD~2 HEAD^ &&
43
+ STORED=$(git rev-parse HEAD:submodule) &&
44
+ test $EXPECTED = $STORED &&
45
+ test $CURRENT = $(cd submodule && git rev-parse HEAD)
46
+
47
+'
48
+
49
+cat > fake-editor.sh << \EOF
50
+#!/bin/sh
51
+echo $EDITOR_TEXT
52
+EOF
53
+chmod a+x fake-editor.sh
54
+
55
+test_expect_success 'interactive rebase with a dirty submodule' '
56
+
57
+ test submodule = $(git diff --name-only) &&
58
+ HEAD=$(git rev-parse HEAD) &&
59
+ GIT_EDITOR="\"$(pwd)/fake-editor.sh\"" EDITOR_TEXT="pick $HEAD" \
60
+ git rebase -i HEAD^ &&
61
+ test submodule = $(git diff --name-only)
62
+
63
+'
64
+
65
+test_expect_success 'rebase with dirty file and submodule fails' '
66
+
67
+ echo yet another line >> file &&
68
+ test_tick &&
69
+ git commit -m next file &&
70
+ echo rewrite > file &&
71
+ test_tick &&
72
+ git commit -m rewrite file &&
73
+ echo dirty > file &&
74
+ ! git rebase --onto HEAD~2 HEAD^
75
+
76
+'
77
+
78
+test_expect_success 'stash with a dirty submodule' '
79
+
80
+ echo new > file &&
81
+ CURRENT=$(cd submodule && git rev-parse HEAD) &&
82
+ git stash &&
83
+ test new != $(cat file) &&
84
+ test submodule = $(git diff --name-only) &&
85
+ test $CURRENT = $(cd submodule && git rev-parse HEAD) &&
86
+ git stash apply &&
87
+ test new = $(cat file) &&
88
+ test $CURRENT = $(cd submodule && git rev-parse HEAD)
89
+
90
+'
91
+
92
+test_done