From abc02670169cee9541793a86324a014272ca8ed5 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 28 Jun 2006 11:47:28 -0700 Subject: 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 --- t/t7201-co.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 t/t7201-co.sh (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh new file mode 100755 index 0000000000..b64e8b7d77 --- /dev/null +++ b/t/t7201-co.sh @@ -0,0 +1,72 @@ +#!/bin/sh +# +# Copyright (c) 2006 Junio C Hamano +# + +test_description='git-checkout tests.' + +. ./test-lib.sh + +fill () { + for i + do + echo "$i" + done +} + +test_expect_success setup ' + + fill 1 2 3 4 5 >one && + fill a b c d e >two && + git add one two && + git commit -m "Initial A one, A two" && + + git checkout -b side && + fill 1 2 3 >one && + fill A B C D E >three && + rm -f two && + git update-index --add --remove one two three && + git commit -m "Side M one, D two, A three" && + + git checkout master +' + +test_expect_success "checkout with dirty tree without -m" ' + + fill 0 1 2 3 4 5 >one && + if git checkout side + then + echo Not happy + false + else + echo "happy - failed correctly" + fi + +' + +test_expect_success "checkout -m with dirty tree" ' + + git checkout -f master && + git clean && + + fill 0 1 2 3 4 5 >one && + git checkout -m side && + + fill " master" "* side" >expect.branch && + git branch >current.branch && + diff expect.branch current.branch && + + fill "M one" "A three" "D two" >expect.master && + git diff --name-status master >current.master && + diff expect.master current.master && + + fill "M one" >expect.side && + git diff --name-status side >current.side && + diff expect.side current.side && + + : >expect.index && + git diff --cached >current.index && + diff expect.index current.index +' + +test_done -- cgit v1.2.3 From 5a03e7f25334a6bf1dbbfdb9830d41de5b8f0d7f Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Mon, 25 Sep 2006 01:24:38 -0400 Subject: Allow git-checkout when on a non-existant branch. I've seen some users get into situtations where their HEAD symbolic-ref is pointing at a non-existant ref. (Sometimes this happens during clone when the remote repository lacks a 'master' branch.) If this happens the user is unable to use git-checkout to switch branches as there is no prior commit to merge from. So instead of giving the user low-level errors about how HEAD can't be resolved and how not a single revision was given change the type of checkout to be a force and go through with the user's request anyway. Signed-off-by: Shawn O. Pearce Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index b64e8b7d77..085d4a096b 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -31,6 +31,15 @@ test_expect_success setup ' git checkout master ' +test_expect_success "checkout from non-existing branch" ' + + git checkout -b delete-me master && + rm .git/refs/heads/delete-me && + test refs/heads/delete-me = "$(git symbolic-ref HEAD)" && + git checkout master && + test refs/heads/master = "$(git symbolic-ref HEAD)" +' + test_expect_success "checkout with dirty tree without -m" ' fill 0 1 2 3 4 5 >one && -- cgit v1.2.3 From c1a4278ee3f99ca9db94bd032b047b3d19ac6e5f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 16 Jan 2007 20:46:39 -0800 Subject: Use merge-recursive in git-checkout -m (branch switching) This allows "git checkout -m " to notice renames and carry local changes in the working tree forward. Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 085d4a096b..315fa3564c 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -14,15 +14,23 @@ fill () { done } + test_expect_success setup ' - fill 1 2 3 4 5 >one && + fill 1 2 3 4 5 6 7 8 >one && fill a b c d e >two && git add one two && git commit -m "Initial A one, A two" && - git checkout -b side && - fill 1 2 3 >one && + git checkout -b renamer && + rm -f one && + fill 1 3 4 5 6 7 8 >uno && + git add uno && + fill a b c d e f >two && + git commit -a -m "Renamer R one->uno, M two" && + + git checkout -b side master && + fill 1 2 3 4 5 6 7 >one && fill A B C D E >three && rm -f two && git update-index --add --remove one two three && @@ -42,7 +50,7 @@ test_expect_success "checkout from non-existing branch" ' test_expect_success "checkout with dirty tree without -m" ' - fill 0 1 2 3 4 5 >one && + fill 0 1 2 3 4 5 6 7 8 >one && if git checkout side then echo Not happy @@ -58,12 +66,10 @@ test_expect_success "checkout -m with dirty tree" ' git checkout -f master && git clean && - fill 0 1 2 3 4 5 >one && + fill 0 1 2 3 4 5 6 7 8 >one && git checkout -m side && - fill " master" "* side" >expect.branch && - git branch >current.branch && - diff expect.branch current.branch && + test "$(git symbolic-ref HEAD)" = "refs/heads/side" && fill "M one" "A three" "D two" >expect.master && git diff --name-status master >current.master && @@ -78,4 +84,23 @@ test_expect_success "checkout -m with dirty tree" ' diff expect.index current.index ' +test_expect_success "checkout -m with dirty tree, renamed" ' + + git checkout -f master && git clean && + + fill 1 2 3 4 5 7 8 >one && + if git checkout renamer + then + echo Not happy + false + else + echo "happy - failed correctly" + fi && + + git checkout -m renamer && + fill 1 3 4 5 7 8 >expect && + diff expect uno && + ! test -f one +' + test_done -- cgit v1.2.3 From d7ebd53d371153f7a61c0fe9f384c9662b751bf6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 23 Jan 2007 16:51:22 -0800 Subject: git-checkout -m: fix merge case Commit c1a4278e switched the "merging checkout" implementation from 3-way read-tree to merge-recursive, but forgot that merge-recursive will signal an unmerged state with its own exit status code. This prevented the clean-up phase (paths cleanly merged should not be updated in the index) from running. Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 315fa3564c..867bbd26cb 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -100,7 +100,33 @@ test_expect_success "checkout -m with dirty tree, renamed" ' git checkout -m renamer && fill 1 3 4 5 7 8 >expect && diff expect uno && - ! test -f one + ! test -f one && + git diff --cached >current && + ! test -s current + +' + +test_expect_success 'checkout -m with merge conflict' ' + + git checkout -f master && git clean && + + fill 1 T 3 4 5 6 S 8 >one && + if git checkout renamer + then + echo Not happy + false + else + echo "happy - failed correctly" + fi && + + git checkout -m renamer && + + git diff master:one :3:uno | + sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current && + fill d2 aT d7 aS >expect && + diff current expect && + git diff --cached two >current && + ! test -s current ' test_done -- cgit v1.2.3 From 3e0318a3613ae8e89dcb1fc39d909145e64287b9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 29 Mar 2007 01:02:50 -0700 Subject: checkout: allow detaching to HEAD even when switching to the tip of a branch You cannot currently checkout the tip of an existing branch without moving to the branch. This allows you to detach your HEAD and place it at such a commit, with: $ git checkout master^0 Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 63 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 867bbd26cb..5fa6a45577 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -3,7 +3,20 @@ # Copyright (c) 2006 Junio C Hamano # -test_description='git-checkout tests.' +test_description='git-checkout tests. + +Creates master, forks renamer and side branches from it. +Test switching across them. + + ! [master] Initial A one, A two + * [renamer] Renamer R one->uno, M two + ! [side] Side M one, D two, A three + --- + + [side] Side M one, D two, A three + * [renamer] Renamer R one->uno, M two + +*+ [master] Initial A one, A two + +' . ./test-lib.sh @@ -129,4 +142,52 @@ test_expect_success 'checkout -m with merge conflict' ' ! test -s current ' +test_expect_success 'checkout to detach HEAD' ' + + git checkout -f renamer && git clean && + git checkout renamer^ && + H=$(git rev-parse --verify HEAD) && + M=$(git show-ref -s --verify refs/heads/master) && + test "z$H" = "z$M" && + if git symbolic-ref HEAD >/dev/null 2>&1 + then + echo "OOPS, HEAD is still symbolic???" + false + else + : happy + fi +' + +test_expect_success 'checkout to detach HEAD with branchname^' ' + + git checkout -f master && git clean && + git checkout renamer^ && + H=$(git rev-parse --verify HEAD) && + M=$(git show-ref -s --verify refs/heads/master) && + test "z$H" = "z$M" && + if git symbolic-ref HEAD >/dev/null 2>&1 + then + echo "OOPS, HEAD is still symbolic???" + false + else + : happy + fi +' + +test_expect_success 'checkout to detach HEAD with HEAD^0' ' + + git checkout -f master && git clean && + git checkout HEAD^0 && + H=$(git rev-parse --verify HEAD) && + M=$(git show-ref -s --verify refs/heads/master) && + test "z$H" = "z$M" && + if git symbolic-ref HEAD >/dev/null 2>&1 + then + echo "OOPS, HEAD is still symbolic???" + false + else + : happy + fi +' + test_done -- cgit v1.2.3 From 5035242c4785bd23c53827a1656b5f97394f724e Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 8 Jun 2007 01:19:13 -0700 Subject: checkout: do not get confused with ambiguous tag/branch names Although it is not advisable, we have always allowed a branch and a tag to have the same basename (i.e. it is not illegal to have refs/heads/frotz and refs/tags/frotz at the same time). When talking about a specific commit, the interpretation of 'frotz' has always been "use tag and then check branch", although we warn when ambiguities exist. However "git checkout $name" is defined to (1) first see if it matches the branch name, and if so switch to that branch; (2) otherwise it is an instruction to detach HEAD to point at the commit named by $name. We did not follow this definition when $name appeared under both refs/heads/ and refs/tags/ -- we switched to the branch but read the tree from the tagged commit, which was utterly bogus. Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 5fa6a45577..ed2e9ee3c6 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -190,4 +190,44 @@ test_expect_success 'checkout to detach HEAD with HEAD^0' ' fi ' +test_expect_success 'checkout with ambiguous tag/branch names' ' + + git tag both side && + git branch both master && + git reset --hard && + git checkout master && + + git checkout both && + H=$(git rev-parse --verify HEAD) && + M=$(git show-ref -s --verify refs/heads/master) && + test "z$H" = "z$M" && + name=$(git symbolic-ref HEAD 2>/dev/null) && + test "z$name" = zrefs/heads/both + +' + +test_expect_success 'checkout with ambiguous tag/branch names' ' + + git reset --hard && + git checkout master && + + git tag frotz side && + git branch frotz master && + git reset --hard && + git checkout master && + + git checkout tags/frotz && + H=$(git rev-parse --verify HEAD) && + S=$(git show-ref -s --verify refs/heads/side) && + test "z$H" = "z$S" && + if name=$(git symbolic-ref HEAD 2>/dev/null) + then + echo "Bad -- should have detached" + false + else + : happy + fi + +' + test_done -- cgit v1.2.3 From 562ca192f94496611583688beb3725603ce51f89 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 1 Nov 2007 17:32:04 -0700 Subject: clean: require -f to do damage by default This makes the clean.requireForce configuration default to true. Too many people are burned by typing "git clean" by mistake when they meant to say "make clean". Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index ed2e9ee3c6..55558aba8b 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -77,7 +77,7 @@ test_expect_success "checkout with dirty tree without -m" ' test_expect_success "checkout -m with dirty tree" ' git checkout -f master && - git clean && + git clean -f && fill 0 1 2 3 4 5 6 7 8 >one && git checkout -m side && @@ -99,7 +99,7 @@ test_expect_success "checkout -m with dirty tree" ' test_expect_success "checkout -m with dirty tree, renamed" ' - git checkout -f master && git clean && + git checkout -f master && git clean -f && fill 1 2 3 4 5 7 8 >one && if git checkout renamer @@ -121,7 +121,7 @@ test_expect_success "checkout -m with dirty tree, renamed" ' test_expect_success 'checkout -m with merge conflict' ' - git checkout -f master && git clean && + git checkout -f master && git clean -f && fill 1 T 3 4 5 6 S 8 >one && if git checkout renamer @@ -144,7 +144,7 @@ test_expect_success 'checkout -m with merge conflict' ' test_expect_success 'checkout to detach HEAD' ' - git checkout -f renamer && git clean && + git checkout -f renamer && git clean -f && git checkout renamer^ && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && @@ -160,7 +160,7 @@ test_expect_success 'checkout to detach HEAD' ' test_expect_success 'checkout to detach HEAD with branchname^' ' - git checkout -f master && git clean && + git checkout -f master && git clean -f && git checkout renamer^ && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && @@ -176,7 +176,7 @@ test_expect_success 'checkout to detach HEAD with branchname^' ' test_expect_success 'checkout to detach HEAD with HEAD^0' ' - git checkout -f master && git clean && + git checkout -f master && git clean -f && git checkout HEAD^0 && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && -- cgit v1.2.3 From c07c7bf630efd8ddcd41490036c1eefb01a39f98 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Sun, 9 Dec 2007 22:05:34 -0500 Subject: Add more checkout tests If you have local changes that don't conflict with the branch-switching changes, these should be kept, not cause errors even without -m, and be reported afterwards in name-status format. With -m, the changes carried across should be listed as well. And, for now, include the merge-recursive output from this process. Also test the detatched head message in at least one case. Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 46 +++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 43 insertions(+), 3 deletions(-) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 55558aba8b..73d8a00e2c 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -20,6 +20,8 @@ Test switching across them. . ./test-lib.sh +test_tick + fill () { for i do @@ -30,9 +32,10 @@ fill () { test_expect_success setup ' + fill x y z > same && fill 1 2 3 4 5 6 7 8 >one && fill a b c d e >two && - git add one two && + git add same one two && git commit -m "Initial A one, A two" && git checkout -b renamer && @@ -74,16 +77,44 @@ test_expect_success "checkout with dirty tree without -m" ' ' +test_expect_success "checkout with unrelated dirty tree without -m" ' + + git checkout -f master && + fill 0 1 2 3 4 5 6 7 8 >same && + cp same kept + git checkout side >messages && + git diff same kept + (cat > messages.expect <one && - git checkout -m side && + git checkout -m side > messages && test "$(git symbolic-ref HEAD)" = "refs/heads/side" && + (cat >expect.messages <expect.master && git diff --name-status master >current.master && diff expect.master current.master && @@ -145,7 +176,16 @@ test_expect_success 'checkout -m with merge conflict' ' test_expect_success 'checkout to detach HEAD' ' git checkout -f renamer && git clean -f && - git checkout renamer^ && + git checkout renamer^ 2>messages && + (cat >messages.expect < +HEAD is now at 7329388... Initial A one, A two +EOF +) && + git diff messages.expect messages && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && test "z$H" = "z$M" && -- cgit v1.2.3 From b1e9efa7c0153fd4e4ffc86c128262e4176e87af Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Sat, 2 Feb 2008 04:37:01 -0500 Subject: Test :/string form for checkout Signed-off-by: Daniel Barkalow Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 73d8a00e2c..dbf1ace29e 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -214,6 +214,22 @@ test_expect_success 'checkout to detach HEAD with branchname^' ' fi ' +test_expect_success 'checkout to detach HEAD with :/message' ' + + git checkout -f master && git clean -f && + git checkout ":/Initial" && + H=$(git rev-parse --verify HEAD) && + M=$(git show-ref -s --verify refs/heads/master) && + test "z$H" = "z$M" && + if git symbolic-ref HEAD >/dev/null 2>&1 + then + echo "OOPS, HEAD is still symbolic???" + false + else + : happy + fi +' + test_expect_success 'checkout to detach HEAD with HEAD^0' ' git checkout -f master && git clean -f && -- cgit v1.2.3 From 922d87f92f79d76ee1d9027d4a0f8a0cf36d5340 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Thu, 7 Feb 2008 11:40:11 -0500 Subject: Use diff -u instead of diff in t7201 If the test failed, it was giving really unclear ed script output. Instead, give a diff that sort of suggests the problem. Also replaces the use of "git diff" for this purpose with "diff -u". Signed-off-by: Daniel Barkalow --- t/t7201-co.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 73d8a00e2c..3d8e01c030 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -83,13 +83,13 @@ test_expect_success "checkout with unrelated dirty tree without -m" ' fill 0 1 2 3 4 5 6 7 8 >same && cp same kept git checkout side >messages && - git diff same kept + diff -u same kept (cat > messages.expect <expect.master && git diff --name-status master >current.master && - diff expect.master current.master && + diff -u expect.master current.master && fill "M one" >expect.side && git diff --name-status side >current.side && - diff expect.side current.side && + diff -u expect.side current.side && : >expect.index && git diff --cached >current.index && - diff expect.index current.index + diff -u expect.index current.index ' test_expect_success "checkout -m with dirty tree, renamed" ' @@ -143,7 +143,7 @@ test_expect_success "checkout -m with dirty tree, renamed" ' git checkout -m renamer && fill 1 3 4 5 7 8 >expect && - diff expect uno && + diff -u expect uno && ! test -f one && git diff --cached >current && ! test -s current @@ -168,7 +168,7 @@ test_expect_success 'checkout -m with merge conflict' ' git diff master:one :3:uno | sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current && fill d2 aT d7 aS >expect && - diff current expect && + diff -u current expect && git diff --cached two >current && ! test -s current ' @@ -185,7 +185,7 @@ If you want to create a new branch from this checkout, you may do so HEAD is now at 7329388... Initial A one, A two EOF ) && - git diff messages.expect messages && + diff -u messages.expect messages && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && test "z$H" = "z$M" && -- cgit v1.2.3 From 782c2d65c24066a5d83453efb52763bc34c10f81 Mon Sep 17 00:00:00 2001 From: Daniel Barkalow Date: Thu, 7 Feb 2008 11:40:23 -0500 Subject: Build in checkout The only differences in behavior should be: - git checkout -m with non-trivial merging won't print out merge-recursive messages (see the change in t7201-co.sh) - git checkout -- paths... will give a sensible error message if HEAD is invalid as a commit. - some intermediate states which were written to disk in the shell version (in particular, index states) are only kept in memory in this version, and therefore these can no longer be revealed by later write operations becoming impossible. - when we change branches, we discard MERGE_MSG, SQUASH_MSG, and rr-cache/MERGE_RR, like reset always has. I'm not 100% sure I got the merge recursive setup exactly right; the base for a non-trivial merge in the shell code doesn't seem theoretically justified to me, but I tried to match it anyway, and the tests all pass this way. Other than these items, the results should be identical to the shell version, so far as I can tell. [jc: squashed lock-file fix from Dscho in] Signed-off-by: Daniel Barkalow Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 7 ------- 1 file changed, 7 deletions(-) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 3d8e01c030..5492f21c7e 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -103,13 +103,6 @@ test_expect_success "checkout -m with dirty tree" ' test "$(git symbolic-ref HEAD)" = "refs/heads/side" && (cat >expect.messages < Date: Tue, 19 Feb 2008 11:24:37 -0500 Subject: branch: optionally setup branch.*.merge from upstream local branches "git branch" and "git checkout -b" now honor --track option even when the upstream branch is local. Previously --track was silently ignored when forking from a local branch. Also the command did not error out when --track was explicitly asked for but the forked point specified was not an existing branch (i.e. when there is no way to set up the tracking configuration), but now it correctly does. The configuration setting branch.autosetupmerge can now be set to "always", which is equivalent to using --track from the command line. Setting branch.autosetupmerge to "true" will retain the former behavior of only setting up branch.*.merge for remote upstream branches. Includes test cases for the new functionality. Signed-off-by: Jay Soffian Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 5492f21c7e..17cff8d515 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -263,4 +263,28 @@ test_expect_success 'checkout with ambiguous tag/branch names' ' ' +test_expect_success \ + 'checkout w/--track sets up tracking' ' + git config branch.autosetupmerge false && + git checkout master && + git checkout --track -b track1 && + test "$(git config branch.track1.remote)" && + test "$(git config branch.track1.merge)"' + +test_expect_success \ + 'checkout w/autosetupmerge=always sets up tracking' ' + git config branch.autosetupmerge always && + git checkout master && + git checkout -b track2 && + test "$(git config branch.track2.remote)" && + test "$(git config branch.track2.merge)" + git config branch.autosetupmerge false' + +test_expect_success \ + 'checkout w/--track from non-branch HEAD fails' ' + git checkout -b delete-me master && + rm .git/refs/heads/delete-me && + test refs/heads/delete-me = "$(git symbolic-ref HEAD)" && + !(git checkout --track -b track)' + test_done -- cgit v1.2.3 From 6010d2d957fb05838cd3ab887ac261752ff8ff87 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 20 Feb 2008 15:54:54 -0800 Subject: checkout: work from a subdirectory When switching branches from a subdirectory, checkout rewritten in C extracted the toplevel of the tree in there. This should fix it. Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 5492f21c7e..0fa94678ad 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -263,4 +263,38 @@ test_expect_success 'checkout with ambiguous tag/branch names' ' ' +test_expect_success 'switch branches while in subdirectory' ' + + git reset --hard && + git checkout master && + + mkdir subs && + ( + cd subs && + git checkout side + ) && + ! test -f subs/one && + rm -fr subs + +' + +test_expect_success 'checkout specific path while in subdirectory' ' + + git reset --hard && + git checkout side && + mkdir subs && + >subs/bero && + git add subs/bero && + git commit -m "add subs/bero" && + + git checkout master && + mkdir -p subs && + ( + cd subs && + git checkout side -- bero + ) && + test -f subs/bero + +' + test_done -- cgit v1.2.3 From 82ebb0b6ec7470cab96a013d3d719c109003ef83 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 12 Mar 2008 17:36:36 -0400 Subject: add test_cmp function for test scripts Many scripts compare actual and expected output using "diff -u". This is nicer than "cmp" because the output shows how the two differ. However, not all versions of diff understand -u, leading to unnecessary test failure. This adds a test_cmp function to the test scripts and switches all "diff -u" invocations to use it. The function uses the contents of "$GIT_TEST_CMP" to compare its arguments; the default is "diff -u". On systems with a less-capable diff, you can do: GIT_TEST_CMP=cmp make test Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 63915cd87b..3111baa9e3 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -83,13 +83,13 @@ test_expect_success "checkout with unrelated dirty tree without -m" ' fill 0 1 2 3 4 5 6 7 8 >same && cp same kept git checkout side >messages && - diff -u same kept + test_cmp same kept (cat > messages.expect <expect.master && git diff --name-status master >current.master && - diff -u expect.master current.master && + test_cmp expect.master current.master && fill "M one" >expect.side && git diff --name-status side >current.side && - diff -u expect.side current.side && + test_cmp expect.side current.side && : >expect.index && git diff --cached >current.index && - diff -u expect.index current.index + test_cmp expect.index current.index ' test_expect_success "checkout -m with dirty tree, renamed" ' @@ -136,7 +136,7 @@ test_expect_success "checkout -m with dirty tree, renamed" ' git checkout -m renamer && fill 1 3 4 5 7 8 >expect && - diff -u expect uno && + test_cmp expect uno && ! test -f one && git diff --cached >current && ! test -s current @@ -161,7 +161,7 @@ test_expect_success 'checkout -m with merge conflict' ' git diff master:one :3:uno | sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current && fill d2 aT d7 aS >expect && - diff -u current expect && + test_cmp current expect && git diff --cached two >current && ! test -s current ' @@ -178,7 +178,7 @@ If you want to create a new branch from this checkout, you may do so HEAD is now at 7329388... Initial A one, A two EOF ) && - diff -u messages.expect messages && + test_cmp messages.expect messages && H=$(git rev-parse --verify HEAD) && M=$(git show-ref -s --verify refs/heads/master) && test "z$H" = "z$M" && -- cgit v1.2.3 From 03b9dfb18ba451a2221601b740004befa7614c5b Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Tue, 22 Jul 2008 16:16:54 -0500 Subject: t3200,t7201: replace '!' with test_must_fail Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 3111baa9e3..9ad5d635a2 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -335,6 +335,6 @@ test_expect_success \ git checkout -b delete-me master && rm .git/refs/heads/delete-me && test refs/heads/delete-me = "$(git symbolic-ref HEAD)" && - !(git checkout --track -b track)' + test_must_fail git checkout --track -b track' test_done -- cgit v1.2.3 From bb0ceb6264fa1aea6e68e07cb13cd9a88473febb Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 9 Aug 2008 16:00:12 +0200 Subject: checkout --track: make up a sensible branch name if '-b' was omitted What does the user most likely want with this command? $ git checkout --track origin/next Exactly. A branch called 'next', that tracks origin's branch 'next'. Make it so. Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 9ad5d635a2..943dd57aac 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -337,4 +337,15 @@ test_expect_success \ test refs/heads/delete-me = "$(git symbolic-ref HEAD)" && test_must_fail git checkout --track -b track' +test_expect_success \ + 'checkout with --track fakes a sensible -b ' ' + git update-ref refs/remotes/origin/koala/bear renamer && + git checkout --track origin/koala/bear && + test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" && + test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)"' + +test_expect_success \ + 'checkout with --track, but without -b, fails with too short tracked name' ' + test_must_fail git checkout --track renamer' + test_done -- cgit v1.2.3 From 9188ed8962ed47c0f41c24eb1317aa07037da545 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Thu, 21 Aug 2008 19:23:20 +0200 Subject: Extend "checkout --track" DWIM to support more cases The code handles additionally "refs/remotes//name", "remotes//name", and "refs//name". Signed-off-by: Alex Riesen Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 943dd57aac..1dff84d2fd 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -340,9 +340,30 @@ test_expect_success \ test_expect_success \ 'checkout with --track fakes a sensible -b ' ' git update-ref refs/remotes/origin/koala/bear renamer && + git update-ref refs/new/koala/bear renamer && + git checkout --track origin/koala/bear && test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" && - test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)"' + test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" && + + git checkout master && git branch -D koala/bear && + + git checkout --track refs/remotes/origin/koala/bear && + test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" && + test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" && + + git checkout master && git branch -D koala/bear && + + git checkout --track remotes/origin/koala/bear && + test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" && + test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" && + + git checkout master && git branch -D koala/bear && + + git checkout --track refs/new/koala/bear && + test "refs/heads/koala/bear" = "$(git symbolic-ref HEAD)" && + test "$(git rev-parse HEAD)" = "$(git rev-parse renamer)" +' test_expect_success \ 'checkout with --track, but without -b, fails with too short tracked name' ' -- cgit v1.2.3 From 8fdcf3125465f70c0cad5be5ab192d46e46307c7 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 29 Aug 2008 13:40:36 -0700 Subject: checkout: do not check out unmerged higher stages randomly During a conflicted merge when you have unmerged stages for a path F in the index, if you said: $ git checkout F we rewrote F as many times as we have stages for it, and the last one (typically "theirs") was left in the work tree, without resolving the conflict. This fixes it by noticing that a specified pathspec pattern matches an unmerged path, and by erroring out. Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 9ad5d635a2..83a366f1e7 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -337,4 +337,26 @@ test_expect_success \ test refs/heads/delete-me = "$(git symbolic-ref HEAD)" && test_must_fail git checkout --track -b track' +test_expect_success 'checkout an unmerged path should fail' ' + rm -f .git/index && + O=$(echo original | git hash-object -w --stdin) && + A=$(echo ourside | git hash-object -w --stdin) && + B=$(echo theirside | git hash-object -w --stdin) && + ( + echo "100644 $A 0 fild" && + echo "100644 $O 1 file" && + echo "100644 $A 2 file" && + echo "100644 $B 3 file" && + echo "100644 $A 0 filf" + ) | git update-index --index-info && + echo "none of the above" >sample && + cat sample >fild && + cat sample >file && + cat sample >filf && + test_must_fail git checkout fild file filf && + test_cmp sample fild && + test_cmp sample filf && + test_cmp sample file +' + test_done -- cgit v1.2.3 From db9410990ee41f2b253763621c0023c782ec86e2 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 30 Aug 2008 07:46:55 -0700 Subject: checkout -f: allow ignoring unmerged paths when checking out of the index Earlier we made "git checkout $pathspec" to atomically refuse the operation of $pathspec matched any path with unmerged stages. This patch allows: $ git checkout -f a b c to ignore, instead of error out on, such unmerged paths. The fix to prevent checkout of an unmerged path from random stages is still there. Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 83a366f1e7..88692f9877 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -359,4 +359,27 @@ test_expect_success 'checkout an unmerged path should fail' ' test_cmp sample file ' +test_expect_success 'checkout with an unmerged path can be ignored' ' + rm -f .git/index && + O=$(echo original | git hash-object -w --stdin) && + A=$(echo ourside | git hash-object -w --stdin) && + B=$(echo theirside | git hash-object -w --stdin) && + ( + echo "100644 $A 0 fild" && + echo "100644 $O 1 file" && + echo "100644 $A 2 file" && + echo "100644 $B 3 file" && + echo "100644 $A 0 filf" + ) | git update-index --index-info && + echo "none of the above" >sample && + echo ourside >expect && + cat sample >fild && + cat sample >file && + cat sample >filf && + git checkout -f fild file filf && + test_cmp expect fild && + test_cmp expect filf && + test_cmp sample file +' + test_done -- cgit v1.2.3 From 38901a48375952ab6c02f22bddfa19ac2bec2c36 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 30 Aug 2008 07:48:18 -0700 Subject: checkout --ours/--theirs: allow checking out one side of a conflicting merge This lets you to check out 'our' (or 'their') version of an unmerged path out of the index while resolving conflicts. Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index 88692f9877..c7ae14118a 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -382,4 +382,29 @@ test_expect_success 'checkout with an unmerged path can be ignored' ' test_cmp sample file ' +test_expect_success 'checkout unmerged stage' ' + rm -f .git/index && + O=$(echo original | git hash-object -w --stdin) && + A=$(echo ourside | git hash-object -w --stdin) && + B=$(echo theirside | git hash-object -w --stdin) && + ( + echo "100644 $A 0 fild" && + echo "100644 $O 1 file" && + echo "100644 $A 2 file" && + echo "100644 $B 3 file" && + echo "100644 $A 0 filf" + ) | git update-index --index-info && + echo "none of the above" >sample && + echo ourside >expect && + cat sample >fild && + cat sample >file && + cat sample >filf && + git checkout --ours . && + test_cmp expect fild && + test_cmp expect filf && + test_cmp expect file && + git checkout --theirs file && + test ztheirside = "z$(cat file)" +' + test_done -- cgit v1.2.3 From 0cf8581e330e7140c9f5c94a53d441187c0f8ff9 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 30 Aug 2008 07:52:24 -0700 Subject: checkout -m: recreate merge when checking out of unmerged index This teaches git-checkout to recreate a merge out of unmerged index entries while resolving conflicts. With this patch, checking out an unmerged path from the index now have the following possibilities: * Without any option, an attempt to checkout an unmerged path will atomically fail (i.e. no other cleanly-merged paths are checked out either); * With "-f", other cleanly-merged paths are checked out, and unmerged paths are ignored; * With "--ours" or "--theirs, the contents from the specified stage is checked out; * With "-m" (we should add "--merge" as synonym), the 3-way merge is recreated from the staged object names and checked out. Signed-off-by: Junio C Hamano --- t/t7201-co.sh | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) (limited to 't/t7201-co.sh') diff --git a/t/t7201-co.sh b/t/t7201-co.sh index c7ae14118a..1d4ff6e8d3 100755 --- a/t/t7201-co.sh +++ b/t/t7201-co.sh @@ -407,4 +407,67 @@ test_expect_success 'checkout unmerged stage' ' test ztheirside = "z$(cat file)" ' +test_expect_success 'checkout with --merge' ' + rm -f .git/index && + O=$(echo original | git hash-object -w --stdin) && + A=$(echo ourside | git hash-object -w --stdin) && + B=$(echo theirside | git hash-object -w --stdin) && + ( + echo "100644 $A 0 fild" && + echo "100644 $O 1 file" && + echo "100644 $A 2 file" && + echo "100644 $B 3 file" && + echo "100644 $A 0 filf" + ) | git update-index --index-info && + echo "none of the above" >sample && + echo ourside >expect && + cat sample >fild && + cat sample >file && + cat sample >filf && + git checkout -m -- fild file filf && + ( + echo "<<<<<<< ours" + echo ourside + echo "=======" + echo theirside + echo ">>>>>>> theirs" + ) >merged && + test_cmp expect fild && + test_cmp expect filf && + test_cmp merged file +' + +test_expect_success 'checkout with --merge, in diff3 -m style' ' + git config merge.conflictstyle diff3 && + rm -f .git/index && + O=$(echo original | git hash-object -w --stdin) && + A=$(echo ourside | git hash-object -w --stdin) && + B=$(echo theirside | git hash-object -w --stdin) && + ( + echo "100644 $A 0 fild" && + echo "100644 $O 1 file" && + echo "100644 $A 2 file" && + echo "100644 $B 3 file" && + echo "100644 $A 0 filf" + ) | git update-index --index-info && + echo "none of the above" >sample && + echo ourside >expect && + cat sample >fild && + cat sample >file && + cat sample >filf && + git checkout -m -- fild file filf && + ( + echo "<<<<<<< ours" + echo ourside + echo "|||||||" + echo original + echo "=======" + echo theirside + echo ">>>>>>> theirs" + ) >merged && + test_cmp expect fild && + test_cmp expect filf && + test_cmp merged file +' + test_done -- cgit v1.2.3 From eac5a401512181cd315a1031af2b8a25430e335a Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sun, 31 Aug 2008 19:32:40 -0700 Subject: checkout --conflict=