Skip to content

Commit 0f49327

Browse files
committed
Revert "rebase: allow starting from a dirty tree."
This reverts commit 6c9ad16. Allowing rebase to start in a dirty tree might have been a worthy goal, but it is not necessarily always wanted (some people prefer to be reminded that the state is dirty, and think about the next action that may not be to stash and proceed). Furthermore, depending on the nature of local changes, unstashing the dirty state on top of the rebased result is not always desirable. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6c9ad16 commit 0f49327

File tree

1 file changed

+14
-58
lines changed

1 file changed

+14
-58
lines changed

git-rebase.sh

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -116,30 +116,10 @@ call_merge () {
116116
}
117117

118118
finish_rb_merge () {
119-
if test -f "$dotest/stash"
120-
then
121-
stash=$(cat "$dotest/stash")
122-
git stash apply --index "$stash"
123-
fi
124119
rm -r "$dotest"
125120
echo "All done."
126121
}
127122

128-
read_stash () {
129-
if test -f "$1"
130-
then
131-
cat "$1"
132-
fi
133-
}
134-
unstash_and_exit () {
135-
err=$?
136-
if test -f "$1" && test $err = 0
137-
then
138-
git stash apply --index "$1"
139-
fi
140-
exit $err
141-
}
142-
143123
is_interactive () {
144124
test -f "$dotest"/interactive ||
145125
while case $#,"$1" in 0,|*,-i|*,--interactive) break ;; esac
@@ -174,9 +154,8 @@ do
174154
finish_rb_merge
175155
exit
176156
fi
177-
stash=$(read_stash ".dotest/stash")
178157
git am --resolved --3way --resolvemsg="$RESOLVEMSG"
179-
unstash_and_exit "$stash"
158+
exit
180159
;;
181160
--skip)
182161
if test -d "$dotest"
@@ -195,31 +174,21 @@ do
195174
finish_rb_merge
196175
exit
197176
fi
198-
stash=$(read_stash ".dotest/stash")
199177
git am -3 --skip --resolvemsg="$RESOLVEMSG"
200-
unstash_and_exit "$stash"
178+
exit
201179
;;
202180
--abort)
203181
git rerere clear
204182
if test -d "$dotest"
205183
then
206-
if test -f "$dotest/stash"
207-
then
208-
stash=$(cat "$dotest/stash")
209-
fi
210184
rm -r "$dotest"
211185
elif test -d .dotest
212186
then
213-
if test -f ".dotest/stash"
214-
then
215-
stash=$(cat ".dotest/stash")
216-
fi
217187
rm -r .dotest
218188
else
219189
die "No rebase in progress?"
220190
fi
221191
git reset --hard ORIG_HEAD
222-
test -z "$stash" || git stash apply --index "$stash"
223192
exit
224193
;;
225194
--onto)
@@ -285,6 +254,16 @@ else
285254
fi
286255
fi
287256

257+
# The tree must be really really clean.
258+
git update-index --refresh || exit
259+
diff=$(git diff-index --cached --name-status -r HEAD)
260+
case "$diff" in
261+
?*) echo "cannot rebase: your index is not up-to-date"
262+
echo "$diff"
263+
exit 1
264+
;;
265+
esac
266+
288267
# The upstream head must be given. Make sure it is valid.
289268
upstream_name="$1"
290269
upstream=`git rev-parse --verify "${upstream_name}^0"` ||
@@ -294,19 +273,11 @@ upstream=`git rev-parse --verify "${upstream_name}^0"` ||
294273
onto_name=${newbase-"$upstream_name"}
295274
onto=$(git rev-parse --verify "${onto_name}^0") || exit
296275

297-
# The tree must be clean enough for us to create a stash
298-
stash=$(git stash create) || exit
299-
if test -n "$stash"
300-
then
301-
echo >&2 "Stashed away your working tree changes"
302-
fi
303-
304276
# If a hook exists, give it a chance to interrupt
305277
if test -x "$GIT_DIR/hooks/pre-rebase"
306278
then
307279
"$GIT_DIR/hooks/pre-rebase" ${1+"$@"} || {
308280
echo >&2 "The pre-rebase hook refused to rebase."
309-
test -z "$stash" || git stash apply --index "$stash"
310281
exit 1
311282
}
312283
fi
@@ -315,10 +286,7 @@ fi
315286
case "$#" in
316287
2)
317288
branch_name="$2"
318-
git-checkout "$2" || {
319-
test -z "$stash" || git stash apply --index "$stash"
320-
usage
321-
}
289+
git-checkout "$2" || usage
322290
;;
323291
*)
324292
if branch_name=`git symbolic-ref -q HEAD`
@@ -341,7 +309,6 @@ if test "$upstream" = "$onto" && test "$mb" = "$onto" &&
341309
! git rev-list --parents "$onto".."$branch" | grep " .* " > /dev/null
342310
then
343311
echo >&2 "Current branch $branch_name is up to date."
344-
test -z "$stash" || git stash apply --index "$stash"
345312
exit 0
346313
fi
347314

@@ -361,24 +328,14 @@ git-reset --hard "$onto"
361328
if test "$mb" = "$branch"
362329
then
363330
echo >&2 "Fast-forwarded $branch_name to $onto_name."
364-
test -z "$stash" || git stash apply --index "$stash"
365331
exit 0
366332
fi
367333

368334
if test -z "$do_merge"
369335
then
370336
git format-patch -k --stdout --full-index --ignore-if-in-upstream "$upstream"..ORIG_HEAD |
371337
git am $git_am_opt --binary -3 -k --resolvemsg="$RESOLVEMSG"
372-
err=$?
373-
374-
if test $err = 0
375-
then
376-
test -z "$stash" || git stash apply --index "$stash"
377-
exit
378-
else
379-
test -z "$stash" || echo "$stash" >.dotest/stash
380-
exit $err
381-
fi
338+
exit $?
382339
fi
383340

384341
# start doing a rebase with git-merge
@@ -389,7 +346,6 @@ echo "$onto" > "$dotest/onto"
389346
echo "$onto_name" > "$dotest/onto_name"
390347
prev_head=`git rev-parse HEAD^0`
391348
echo "$prev_head" > "$dotest/prev_head"
392-
test -z "$stash" || echo "$stash" >"$dotest/stash"
393349

394350
msgnum=0
395351
for cmt in `git rev-list --reverse --no-merges "$upstream"..ORIG_HEAD`

0 commit comments

Comments
 (0)