@matheusbsbs / matheus-bagliano / commits / abc0267016
Fork 0

checkout -m: fix read-tree invocation

When we updated "read-tree -m -u" to be careful about not removing untracked working tree files, we broke "checkout -m" to switch between branches. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jun 28, 2006 at 11:47 UTC abc02670169cee9541793a86324a014272ca8ed5
2 files changed +73 -2
git-checkout.sh
+1 -2
@@ -150,8 +150,7 @@ else
150 # Match the index to the working tree, and do a three-way.
151 git diff-files --name-only | git update-index --remove --stdin &&
152 work=`git write-tree` &&
153 - git read-tree --reset $new &&
154 - git checkout-index -f -u -q -a &&
153 + git read-tree --reset -u $new &&
154 git read-tree -m -u --aggressive $old $new $work || exit
155
156 if result=`git write-tree 2>/dev/null`
t/t7201-co.sh new
+72
@@ -0,0 +1,72 @@
1 +#!/bin/sh
2 +#
3 +# Copyright (c) 2006 Junio C Hamano
4 +#
5 +
6 +test_description='git-checkout tests.'
7 +
8 +. ./test-lib.sh
9 +
10 +fill () {
11 + for i
12 + do
13 + echo "$i"
14 + done
15 +}
16 +
17 +test_expect_success setup '
18 +
19 + fill 1 2 3 4 5 >one &&
20 + fill a b c d e >two &&
21 + git add one two &&
22 + git commit -m "Initial A one, A two" &&
23 +
24 + git checkout -b side &&
25 + fill 1 2 3 >one &&
26 + fill A B C D E >three &&
27 + rm -f two &&
28 + git update-index --add --remove one two three &&
29 + git commit -m "Side M one, D two, A three" &&
30 +
31 + git checkout master
32 +'
33 +
34 +test_expect_success "checkout with dirty tree without -m" '
35 +
36 + fill 0 1 2 3 4 5 >one &&
37 + if git checkout side
38 + then
39 + echo Not happy
40 + false
41 + else
42 + echo "happy - failed correctly"
43 + fi
44 +
45 +'
46 +
47 +test_expect_success "checkout -m with dirty tree" '
48 +
49 + git checkout -f master &&
50 + git clean &&
51 +
52 + fill 0 1 2 3 4 5 >one &&
53 + git checkout -m side &&
54 +
55 + fill " master" "* side" >expect.branch &&
56 + git branch >current.branch &&
57 + diff expect.branch current.branch &&
58 +
59 + fill "M one" "A three" "D two" >expect.master &&
60 + git diff --name-status master >current.master &&
61 + diff expect.master current.master &&
62 +
63 + fill "M one" >expect.side &&
64 + git diff --name-status side >current.side &&
65 + diff expect.side current.side &&
66 +
67 + : >expect.index &&
68 + git diff --cached >current.index &&
69 + diff expect.index current.index
70 +'
71 +
72 +test_done