2011-02-08 13:32:49 +03:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
test_description='checkout into detached HEAD state'
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
|
|
|
check_detached () {
|
|
|
|
test_must_fail git symbolic-ref -q HEAD >/dev/null
|
|
|
|
}
|
|
|
|
|
|
|
|
check_not_detached () {
|
|
|
|
git symbolic-ref -q HEAD >/dev/null
|
|
|
|
}
|
|
|
|
|
2011-03-20 12:04:16 +03:00
|
|
|
ORPHAN_WARNING='you are leaving .* commit.*behind'
|
|
|
|
check_orphan_warning() {
|
2011-04-13 03:20:32 +04:00
|
|
|
test_i18ngrep "$ORPHAN_WARNING" "$1"
|
2011-03-20 12:04:16 +03:00
|
|
|
}
|
|
|
|
check_no_orphan_warning() {
|
2011-04-13 03:20:32 +04:00
|
|
|
test_i18ngrep ! "$ORPHAN_WARNING" "$1"
|
2011-03-20 12:04:16 +03:00
|
|
|
}
|
|
|
|
|
2011-02-08 13:32:49 +03:00
|
|
|
reset () {
|
|
|
|
git checkout master &&
|
|
|
|
check_not_detached
|
|
|
|
}
|
|
|
|
|
|
|
|
test_expect_success 'setup' '
|
|
|
|
test_commit one &&
|
|
|
|
test_commit two &&
|
2011-03-20 12:04:16 +03:00
|
|
|
test_commit three && git tag -d three &&
|
|
|
|
test_commit four && git tag -d four &&
|
2011-02-08 13:32:49 +03:00
|
|
|
git branch branch &&
|
|
|
|
git tag tag
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout branch does not detach' '
|
|
|
|
reset &&
|
|
|
|
git checkout branch &&
|
|
|
|
check_not_detached
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout tag detaches' '
|
|
|
|
reset &&
|
|
|
|
git checkout tag &&
|
|
|
|
check_detached
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout branch by full name detaches' '
|
|
|
|
reset &&
|
|
|
|
git checkout refs/heads/branch &&
|
|
|
|
check_detached
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout non-ref detaches' '
|
|
|
|
reset &&
|
|
|
|
git checkout branch^ &&
|
|
|
|
check_detached
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout ref^0 detaches' '
|
|
|
|
reset &&
|
|
|
|
git checkout branch^0 &&
|
|
|
|
check_detached
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout --detach detaches' '
|
|
|
|
reset &&
|
|
|
|
git checkout --detach branch &&
|
|
|
|
check_detached
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout --detach without branch name' '
|
|
|
|
reset &&
|
|
|
|
git checkout --detach &&
|
|
|
|
check_detached
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout --detach errors out for non-commit' '
|
|
|
|
reset &&
|
|
|
|
test_must_fail git checkout --detach one^{tree} &&
|
|
|
|
check_not_detached
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout --detach errors out for extra argument' '
|
|
|
|
reset &&
|
|
|
|
git checkout master &&
|
|
|
|
test_must_fail git checkout --detach tag one.t &&
|
|
|
|
check_not_detached
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout --detached and -b are incompatible' '
|
|
|
|
reset &&
|
|
|
|
test_must_fail git checkout --detach -b newbranch tag &&
|
|
|
|
check_not_detached
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout --detach moves HEAD' '
|
|
|
|
reset &&
|
|
|
|
git checkout one &&
|
|
|
|
git checkout --detach two &&
|
|
|
|
git diff --exit-code HEAD &&
|
|
|
|
git diff --exit-code two
|
|
|
|
'
|
|
|
|
|
2011-03-20 12:04:16 +03:00
|
|
|
test_expect_success 'checkout warns on orphan commits' '
|
|
|
|
reset &&
|
|
|
|
git checkout --detach two &&
|
|
|
|
echo content >orphan &&
|
|
|
|
git add orphan &&
|
|
|
|
git commit -a -m orphan &&
|
2011-04-10 23:34:08 +04:00
|
|
|
git checkout master 2>stderr
|
|
|
|
'
|
|
|
|
|
2011-04-13 03:20:32 +04:00
|
|
|
test_expect_success 'checkout warns on orphan commits: output' '
|
2011-03-20 12:04:16 +03:00
|
|
|
check_orphan_warning stderr
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout does not warn leaving ref tip' '
|
|
|
|
reset &&
|
|
|
|
git checkout --detach two &&
|
2011-04-10 23:34:08 +04:00
|
|
|
git checkout master 2>stderr
|
|
|
|
'
|
|
|
|
|
2011-04-13 03:20:32 +04:00
|
|
|
test_expect_success 'checkout does not warn leaving ref tip' '
|
2011-03-20 12:04:16 +03:00
|
|
|
check_no_orphan_warning stderr
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'checkout does not warn leaving reachable commit' '
|
|
|
|
reset &&
|
|
|
|
git checkout --detach HEAD^ &&
|
2011-04-10 23:34:08 +04:00
|
|
|
git checkout master 2>stderr
|
|
|
|
'
|
|
|
|
|
2011-04-13 03:20:32 +04:00
|
|
|
test_expect_success 'checkout does not warn leaving reachable commit' '
|
2011-03-20 12:04:16 +03:00
|
|
|
check_no_orphan_warning stderr
|
|
|
|
'
|
|
|
|
|
2011-03-20 12:09:18 +03:00
|
|
|
cat >expect <<'EOF'
|
|
|
|
Your branch is behind 'master' by 1 commit, and can be fast-forwarded.
|
|
|
|
EOF
|
|
|
|
test_expect_success 'tracking count is accurate after orphan check' '
|
|
|
|
reset &&
|
|
|
|
git branch child master^ &&
|
|
|
|
git config branch.child.remote . &&
|
|
|
|
git config branch.child.merge refs/heads/master &&
|
|
|
|
git checkout child^ &&
|
|
|
|
git checkout child >stdout &&
|
|
|
|
test_cmp expect stdout
|
|
|
|
'
|
|
|
|
|
2011-02-08 13:32:49 +03:00
|
|
|
test_done
|