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

Use merge-recursive in git-checkout -m (branch switching)

This allows "git checkout -m <other-branch>" to notice renames and carry local changes in the working tree forward. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jan 16, 2007 at 20:46 UTC c1a4278ee3f99ca9db94bd032b047b3d19ac6e5f
2 files changed +36 -10
git-checkout.sh
+3 -2
@@ -201,8 +201,9 @@ else
201 git diff-files --name-only | git update-index --remove --stdin &&
202 work=`git write-tree` &&
203 git read-tree --reset -u $new &&
204 - git read-tree -m -u --aggressive --exclude-per-directory=.gitignore $old $new $work ||
205 - exit
204 + eval GITHEAD_$new=${new_name:-${branch:-$new}} GITHEAD_$work=local &&
205 + export GITHEAD_$new GITHEAD_$work &&
206 + git merge-recursive $old -- $new $work || exit
207
208 if result=`git write-tree 2>/dev/null`
209 then
t/t7201-co.sh
+33 -8
@@ -14,15 +14,23 @@ fill () {
14 done
15 }
16
17 +
18 test_expect_success setup '
19
19 - fill 1 2 3 4 5 >one &&
20 + fill 1 2 3 4 5 6 7 8 >one &&
21 fill a b c d e >two &&
22 git add one two &&
23 git commit -m "Initial A one, A two" &&
24
24 - git checkout -b side &&
25 - fill 1 2 3 >one &&
25 + git checkout -b renamer &&
26 + rm -f one &&
27 + fill 1 3 4 5 6 7 8 >uno &&
28 + git add uno &&
29 + fill a b c d e f >two &&
30 + git commit -a -m "Renamer R one->uno, M two" &&
31 +
32 + git checkout -b side master &&
33 + fill 1 2 3 4 5 6 7 >one &&
34 fill A B C D E >three &&
35 rm -f two &&
36 git update-index --add --remove one two three &&
@@ -42,7 +50,7 @@ test_expect_success "checkout from non-existing branch" '
50
51 test_expect_success "checkout with dirty tree without -m" '
52
45 - fill 0 1 2 3 4 5 >one &&
53 + fill 0 1 2 3 4 5 6 7 8 >one &&
54 if git checkout side
55 then
56 echo Not happy
@@ -58,12 +66,10 @@ test_expect_success "checkout -m with dirty tree" '
66 git checkout -f master &&
67 git clean &&
68
61 - fill 0 1 2 3 4 5 >one &&
69 + fill 0 1 2 3 4 5 6 7 8 >one &&
70 git checkout -m side &&
71
64 - fill " master" "* side" >expect.branch &&
65 - git branch >current.branch &&
66 - diff expect.branch current.branch &&
72 + test "$(git symbolic-ref HEAD)" = "refs/heads/side" &&
73
74 fill "M one" "A three" "D two" >expect.master &&
75 git diff --name-status master >current.master &&
@@ -78,4 +84,23 @@ test_expect_success "checkout -m with dirty tree" '
84 diff expect.index current.index
85 '
86
87 +test_expect_success "checkout -m with dirty tree, renamed" '
88 +
89 + git checkout -f master && git clean &&
90 +
91 + fill 1 2 3 4 5 7 8 >one &&
92 + if git checkout renamer
93 + then
94 + echo Not happy
95 + false
96 + else
97 + echo "happy - failed correctly"
98 + fi &&
99 +
100 + git checkout -m renamer &&
101 + fill 1 3 4 5 7 8 >expect &&
102 + diff expect uno &&
103 + ! test -f one
104 +'
105 +
106 test_done