#!/bin/sh global test_description := ''checkout $tree -- $paths'' source ./test-lib.sh test_expect_success setup ' mkdir dir && >dir/master && echo common >dir/common && git add dir/master dir/common && test_tick && git commit -m "master has dir/master" && git checkout -b next && git mv dir/master dir/next0 && echo next >dir/next1 && git add dir && test_tick && git commit -m "next has dir/next but not dir/master" ' test_expect_success 'checking out paths out of a tree does not clobber unrelated paths' ' git checkout next && git reset --hard && rm dir/next0 && cat dir/common >expect.common && echo modified >expect.next1 && cat expect.next1 >dir/next1 && echo untracked >expect.next2 && cat expect.next2 >dir/next2 && git checkout master dir && test_cmp expect.common dir/common && test_path_is_file dir/master && git diff --exit-code master dir/master && test_path_is_missing dir/next0 && test_cmp expect.next1 dir/next1 && test_path_is_file dir/next2 && test_must_fail git ls-files --error-unmatch dir/next2 && test_cmp expect.next2 dir/next2 ' test_expect_success 'do not touch unmerged entries matching $path but not in $tree' ' git checkout next && git reset --hard && cat dir/common >expect.common && EMPTY_SHA1=$(git hash-object -w --stdin expect.next0 <<-EOF && 100644 $EMPTY_SHA1 1 dir/next0 100644 $EMPTY_SHA1 2 dir/next0 EOF git update-index --index-info actual.next0 && test_cmp expect.next0 actual.next0 ' test_expect_success 'do not touch files that are already up-to-date' ' git reset --hard && echo one >file1 && echo two >file2 && git add file1 file2 && git commit -m base && echo modified >file1 && test-chmtime =1000000000 file2 && git update-index -q --refresh && git checkout HEAD -- file1 file2 && echo one >expect && test_cmp expect file1 && echo "1000000000 file2" >expect && test-chmtime -v +0 file2 >actual && test_cmp expect actual ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"checkout $tree -- $paths">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(setup)} { (SQ <"\n"> <"\tmkdir dir &&\n"> <"\t>dir/master &&\n"> <"\techo common >dir/common &&\n"> <"\tgit add dir/master dir/common &&\n"> <"\ttest_tick && git commit -m \"master has dir/master\" &&\n"> <"\tgit checkout -b next &&\n"> <"\tgit mv dir/master dir/next0 &&\n"> <"\techo next >dir/next1 &&\n"> <"\tgit add dir &&\n"> <"\ttest_tick && git commit -m \"next has dir/next but not dir/master\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"checking out paths out of a tree does not clobber unrelated paths">)} { (SQ <"\n"> <"\tgit checkout next &&\n"> <"\tgit reset --hard &&\n"> <"\trm dir/next0 &&\n"> <"\tcat dir/common >expect.common &&\n"> <"\techo modified >expect.next1 &&\n"> <"\tcat expect.next1 >dir/next1 &&\n"> <"\techo untracked >expect.next2 &&\n"> <"\tcat expect.next2 >dir/next2 &&\n"> <"\n"> <"\tgit checkout master dir &&\n"> <"\n"> <"\ttest_cmp expect.common dir/common &&\n"> <"\ttest_path_is_file dir/master &&\n"> <"\tgit diff --exit-code master dir/master &&\n"> <"\n"> <"\ttest_path_is_missing dir/next0 &&\n"> <"\ttest_cmp expect.next1 dir/next1 &&\n"> <"\ttest_path_is_file dir/next2 &&\n"> <"\ttest_must_fail git ls-files --error-unmatch dir/next2 &&\n"> <"\ttest_cmp expect.next2 dir/next2\n"> ) } ) (C {(test_expect_success)} {(SQ <"do not touch unmerged entries matching $path but not in $tree">)} { (SQ <"\n"> <"\tgit checkout next &&\n"> <"\tgit reset --hard &&\n"> <"\n"> <"\tcat dir/common >expect.common &&\n"> <"\tEMPTY_SHA1=$(git hash-object -w --stdin <"\tgit rm dir/next0 &&\n"> <"\tcat >expect.next0 <<-EOF &&\n"> <"\t100644 $EMPTY_SHA1 1\tdir/next0\n"> <"\t100644 $EMPTY_SHA1 2\tdir/next0\n"> <"\tEOF\n"> <"\tgit update-index --index-info <"\n"> <"\tgit checkout master dir &&\n"> <"\n"> <"\ttest_cmp expect.common dir/common &&\n"> <"\ttest_path_is_file dir/master &&\n"> <"\tgit diff --exit-code master dir/master &&\n"> <"\tgit ls-files -s dir/next0 >actual.next0 &&\n"> <"\ttest_cmp expect.next0 actual.next0\n"> ) } ) (C {(test_expect_success)} {(SQ <"do not touch files that are already up-to-date">)} { (SQ <"\n"> <"\tgit reset --hard &&\n"> <"\techo one >file1 &&\n"> <"\techo two >file2 &&\n"> <"\tgit add file1 file2 &&\n"> <"\tgit commit -m base &&\n"> <"\techo modified >file1 &&\n"> <"\ttest-chmtime =1000000000 file2 &&\n"> <"\tgit update-index -q --refresh &&\n"> <"\tgit checkout HEAD -- file1 file2 &&\n"> <"\techo one >expect &&\n"> <"\ttest_cmp expect file1 &&\n"> <"\techo \"1000000000\tfile2\" >expect &&\n"> <"\ttest-chmtime -v +0 file2 >actual &&\n"> <"\ttest_cmp expect actual\n"> ) } ) (C {(test_done)}) ] )