-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checkout: implement "-" abbreviation, add docs and tests
Have '-' mean the same as '@{-1}', i.e., the last branch we were on. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>
- Loading branch information
Thomas Rast
authored and
Junio C Hamano
committed
Jan 18, 2009
1 parent
d18ba22
commit 696acf4
Showing
3 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/bin/sh | ||
|
||
test_description='checkout can switch to last branch' | ||
|
||
. ./test-lib.sh | ||
|
||
test_expect_success 'setup' ' | ||
echo hello >world && | ||
git add world && | ||
git commit -m initial && | ||
git branch other && | ||
echo "hello again" >>world && | ||
git add world && | ||
git commit -m second | ||
' | ||
|
||
test_expect_success '"checkout -" does not work initially' ' | ||
test_must_fail git checkout - | ||
' | ||
|
||
test_expect_success 'first branch switch' ' | ||
git checkout other | ||
' | ||
|
||
test_expect_success '"checkout -" switches back' ' | ||
git checkout - && | ||
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/master" | ||
' | ||
|
||
test_expect_success '"checkout -" switches forth' ' | ||
git checkout - && | ||
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other" | ||
' | ||
|
||
test_expect_success 'detach HEAD' ' | ||
git checkout $(git rev-parse HEAD) | ||
' | ||
|
||
test_expect_success '"checkout -" attaches again' ' | ||
git checkout - && | ||
test "z$(git symbolic-ref HEAD)" = "zrefs/heads/other" | ||
' | ||
|
||
test_expect_success '"checkout -" detaches again' ' | ||
git checkout - && | ||
test "z$(git rev-parse HEAD)" = "z$(git rev-parse other)" && | ||
test_must_fail git symbolic-ref HEAD | ||
' | ||
|
||
test_done |