1#!/bin/sh2#3# Copyright (c) 2006 Junio C Hamano4#56test_description='git-checkout tests.'78. ./test-lib.sh910fill () {11for i12do13echo "$i"14done15}161718test_expect_success setup '1920fill 1 2 3 4 5 6 7 8 >one &&21fill a b c d e >two &&22git add one two &&23git commit -m "Initial A one, A two" &&2425git checkout -b renamer &&26rm -f one &&27fill 1 3 4 5 6 7 8 >uno &&28git add uno &&29fill a b c d e f >two &&30git commit -a -m "Renamer R one->uno, M two" &&3132git checkout -b side master &&33fill 1 2 3 4 5 6 7 >one &&34fill A B C D E >three &&35rm -f two &&36git update-index --add --remove one two three &&37git commit -m "Side M one, D two, A three" &&3839git checkout master40'4142test_expect_success "checkout from non-existing branch" '4344git checkout -b delete-me master &&45rm .git/refs/heads/delete-me &&46test refs/heads/delete-me = "$(git symbolic-ref HEAD)" &&47git checkout master &&48test refs/heads/master = "$(git symbolic-ref HEAD)"49'5051test_expect_success "checkout with dirty tree without -m" '5253fill 0 1 2 3 4 5 6 7 8 >one &&54if git checkout side55then56echo Not happy57false58else59echo "happy - failed correctly"60fi6162'6364test_expect_success "checkout -m with dirty tree" '6566git checkout -f master &&67git clean &&6869fill 0 1 2 3 4 5 6 7 8 >one &&70git checkout -m side &&7172test "$(git symbolic-ref HEAD)" = "refs/heads/side" &&7374fill "M one" "A three" "D two" >expect.master &&75git diff --name-status master >current.master &&76diff expect.master current.master &&7778fill "M one" >expect.side &&79git diff --name-status side >current.side &&80diff expect.side current.side &&8182: >expect.index &&83git diff --cached >current.index &&84diff expect.index current.index85'8687test_expect_success "checkout -m with dirty tree, renamed" '8889git checkout -f master && git clean &&9091fill 1 2 3 4 5 7 8 >one &&92if git checkout renamer93then94echo Not happy95false96else97echo "happy - failed correctly"98fi &&99100git checkout -m renamer &&101fill 1 3 4 5 7 8 >expect &&102diff expect uno &&103! test -f one &&104git diff --cached >current &&105! test -s current106107'108109test_expect_success 'checkout -m with merge conflict' '110111git checkout -f master && git clean &&112113fill 1 T 3 4 5 6 S 8 >one &&114if git checkout renamer115then116echo Not happy117false118else119echo "happy - failed correctly"120fi &&121122git checkout -m renamer &&123124git diff master:one :3:uno |125sed -e "1,/^@@/d" -e "/^ /d" -e "s/^-/d/" -e "s/^+/a/" >current &&126fill d2 aT d7 aS >expect &&127diff current expect &&128git diff --cached two >current &&129! test -s current130'131132test_done