#!/bin/sh global test_description := ''read-tree -m -u checks working tree files'' source ./test-lib.sh source "$TEST_DIRECTORY"/lib-read-tree.sh # two-tree test test_expect_success 'two-way setup' ' mkdir subdir && echo >file1 file one && echo >file2 file two && echo >subdir/file1 file one in subdirectory && echo >subdir/file2 file two in subdirectory && git update-index --add file1 file2 subdir/file1 subdir/file2 && git commit -m initial && git branch side && git tag -f branch-point && echo file2 is not tracked on the master anymore && rm -f file2 subdir/file2 && git update-index --remove file2 subdir/file2 && git commit -a -m "master removes file2 and subdir/file2" ' test_expect_success 'two-way not clobbering' ' echo >file2 master creates untracked file2 && echo >subdir/file2 master creates untracked subdir/file2 && if err=$(read_tree_u_must_succeed -m -u master side 2>&1) then echo should have complained false else echo "happy to see $err" fi ' echo file2 >.gitignore test_expect_success 'two-way with incorrect --exclude-per-directory (1)' ' if err=$(read_tree_u_must_succeed -m --exclude-per-directory=.gitignore master side 2>&1) then echo should have complained false else echo "happy to see $err" fi ' test_expect_success 'two-way with incorrect --exclude-per-directory (2)' ' if err=$(read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore master side 2>&1) then echo should have complained false else echo "happy to see $err" fi ' test_expect_success 'two-way clobbering a ignored file' ' read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore master side ' rm -f .gitignore # three-tree test test_expect_success 'three-way not complaining on an untracked path in both' ' rm -f file2 subdir/file2 && git checkout side && echo >file3 file three && echo >subdir/file3 file three && git update-index --add file3 subdir/file3 && git commit -a -m "side adds file3 and removes file2" && git checkout master && echo >file2 file two is untracked on the master side && echo >subdir/file2 file two is untracked on the master side && read_tree_u_must_succeed -m -u branch-point master side ' test_expect_success 'three-way not clobbering a working tree file' ' git reset --hard && rm -f file2 subdir/file2 file3 subdir/file3 && git checkout master && echo >file3 file three created in master, untracked && echo >subdir/file3 file three created in master, untracked && if err=$(read_tree_u_must_succeed -m -u branch-point master side 2>&1) then echo should have complained false else echo "happy to see $err" fi ' echo >.gitignore file3>.gitignore file3 test_expect_success 'three-way not complaining on an untracked file' ' git reset --hard && rm -f file2 subdir/file2 file3 subdir/file3 && git checkout master && echo >file3 file three created in master, untracked && echo >subdir/file3 file three created in master, untracked && read_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore branch-point master side ' test_expect_success '3-way not overwriting local changes (setup)' ' git reset --hard && git checkout -b side-a branch-point && echo >>file1 "new line to be kept in the merge result" && git commit -a -m "side-a changes file1" && git checkout -b side-b branch-point && echo >>file2 "new line to be kept in the merge result" && git commit -a -m "side-b changes file2" && git checkout side-a ' test_expect_success '3-way not overwriting local changes (our side)' ' # At this point, file1 from side-a should be kept as side-b # did not touch it. git reset --hard && echo >>file1 "local changes" && read_tree_u_must_succeed -m -u branch-point side-a side-b && grep "new line to be kept" file1 && grep "local changes" file1 ' test_expect_success '3-way not overwriting local changes (their side)' ' # At this point, file2 from side-b should be taken as side-a # did not touch it. git reset --hard && echo >>file2 "local changes" && read_tree_u_must_fail -m -u branch-point side-a side-b && ! grep "new line to be kept" file2 && grep "local changes" file2 ' test_expect_success 'funny symlink in work tree' ' git reset --hard && git checkout -b sym-b side-b && mkdir -p a && >a/b && git add a/b && git commit -m "side adds a/b" && rm -fr a && git checkout -b sym-a side-a && mkdir -p a && test_ln_s_add ../b a/b && git commit -m "we add a/b" && read_tree_u_must_succeed -m -u sym-a sym-a sym-b ' test_expect_success SANITY 'funny symlink in work tree, un-unlink-able' ' rm -fr a b && git reset --hard && git checkout sym-a && chmod a-w a && test_must_fail git read-tree -m -u sym-a sym-a sym-b ' # clean-up from the above test chmod a+w a !2 >/dev/null rm -fr a b test_expect_success 'D/F setup' ' git reset --hard && git checkout side-a && rm -f subdir/file2 && mkdir subdir/file2 && echo qfwfq >subdir/file2/another && git add subdir/file2/another && test_tick && git commit -m "side-a changes file2 to directory" ' test_expect_success 'D/F' ' git checkout side-b && read_tree_u_must_succeed -m -u branch-point side-b side-a && git ls-files -u >actual && ( a=$(git rev-parse branch-point:subdir/file2) b=$(git rev-parse side-a:subdir/file2/another) echo "100644 $a 1 subdir/file2" echo "100644 $a 2 subdir/file2" echo "100644 $b 3 subdir/file2/another" ) >expect && test_cmp actual expect ' test_expect_success 'D/F resolve' ' git reset --hard && git checkout side-b && git merge-resolve branch-point -- side-b side-a ' test_expect_success 'D/F recursive' ' git reset --hard && git checkout side-b && git merge-recursive branch-point -- side-b side-a ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"read-tree -m -u checks working tree files">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(.)} {(DQ ($ VSub_Name "$TEST_DIRECTORY")) (/lib-read-tree.sh)}) (C {(test_expect_success)} {(SQ <"two-way setup">)} { (SQ <"\n"> <"\n"> <"\tmkdir subdir &&\n"> <"\techo >file1 file one &&\n"> <"\techo >file2 file two &&\n"> <"\techo >subdir/file1 file one in subdirectory &&\n"> <"\techo >subdir/file2 file two in subdirectory &&\n"> <"\tgit update-index --add file1 file2 subdir/file1 subdir/file2 &&\n"> <"\tgit commit -m initial &&\n"> <"\n"> <"\tgit branch side &&\n"> <"\tgit tag -f branch-point &&\n"> <"\n"> <"\techo file2 is not tracked on the master anymore &&\n"> <"\trm -f file2 subdir/file2 &&\n"> <"\tgit update-index --remove file2 subdir/file2 &&\n"> <"\tgit commit -a -m \"master removes file2 and subdir/file2\"\n"> ) } ) (C {(test_expect_success)} {(SQ <"two-way not clobbering">)} { (SQ <"\n"> <"\n"> <"\techo >file2 master creates untracked file2 &&\n"> <"\techo >subdir/file2 master creates untracked subdir/file2 &&\n"> <"\tif err=$(read_tree_u_must_succeed -m -u master side 2>&1)\n"> <"\tthen\n"> <"\t\techo should have complained\n"> <"\t\tfalse\n"> <"\telse\n"> <"\t\techo \"happy to see $err\"\n"> <"\tfi\n"> ) } ) (SimpleCommand words: [{(echo)} {(file2)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(.gitignore)} spids:[78])] ) (C {(test_expect_success)} {(SQ <"two-way with incorrect --exclude-per-directory (1)">)} { (SQ <"\n"> <"\n"> < "\tif err=$(read_tree_u_must_succeed -m --exclude-per-directory=.gitignore master side 2>&1)\n" > <"\tthen\n"> <"\t\techo should have complained\n"> <"\t\tfalse\n"> <"\telse\n"> <"\t\techo \"happy to see $err\"\n"> <"\tfi\n"> ) } ) (C {(test_expect_success)} {(SQ <"two-way with incorrect --exclude-per-directory (2)">)} { (SQ <"\n"> <"\n"> < "\tif err=$(read_tree_u_must_succeed -m -u --exclude-per-directory=foo --exclude-per-directory=.gitignore master side 2>&1)\n" > <"\tthen\n"> <"\t\techo should have complained\n"> <"\t\tfalse\n"> <"\telse\n"> <"\t\techo \"happy to see $err\"\n"> <"\tfi\n"> ) } ) (C {(test_expect_success)} {(SQ <"two-way clobbering a ignored file">)} { (SQ <"\n"> <"\n"> <"\tread_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore master side\n"> ) } ) (C {(rm)} {(-f)} {(.gitignore)}) (C {(test_expect_success)} {(SQ <"three-way not complaining on an untracked path in both">)} { (SQ <"\n"> <"\n"> <"\trm -f file2 subdir/file2 &&\n"> <"\tgit checkout side &&\n"> <"\techo >file3 file three &&\n"> <"\techo >subdir/file3 file three &&\n"> <"\tgit update-index --add file3 subdir/file3 &&\n"> <"\tgit commit -a -m \"side adds file3 and removes file2\" &&\n"> <"\n"> <"\tgit checkout master &&\n"> <"\techo >file2 file two is untracked on the master side &&\n"> <"\techo >subdir/file2 file two is untracked on the master side &&\n"> <"\n"> <"\tread_tree_u_must_succeed -m -u branch-point master side\n"> ) } ) (C {(test_expect_success)} {(SQ <"three-way not clobbering a working tree file">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\trm -f file2 subdir/file2 file3 subdir/file3 &&\n"> <"\tgit checkout master &&\n"> <"\techo >file3 file three created in master, untracked &&\n"> <"\techo >subdir/file3 file three created in master, untracked &&\n"> <"\tif err=$(read_tree_u_must_succeed -m -u branch-point master side 2>&1)\n"> <"\tthen\n"> <"\t\techo should have complained\n"> <"\t\tfalse\n"> <"\telse\n"> <"\t\techo \"happy to see $err\"\n"> <"\tfi\n"> ) } ) (SimpleCommand words: [{(echo)} {(file3)}] redirects: [(Redir op_id:Redir_Great fd:-1 arg_word:{(.gitignore)} spids:[194])] ) (C {(test_expect_success)} {(SQ <"three-way not complaining on an untracked file">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\trm -f file2 subdir/file2 file3 subdir/file3 &&\n"> <"\tgit checkout master &&\n"> <"\techo >file3 file three created in master, untracked &&\n"> <"\techo >subdir/file3 file three created in master, untracked &&\n"> <"\n"> < "\tread_tree_u_must_succeed -m -u --exclude-per-directory=.gitignore branch-point master side\n" > ) } ) (C {(test_expect_success)} {(SQ <"3-way not overwriting local changes (setup)">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout -b side-a branch-point &&\n"> <"\techo >>file1 \"new line to be kept in the merge result\" &&\n"> <"\tgit commit -a -m \"side-a changes file1\" &&\n"> <"\tgit checkout -b side-b branch-point &&\n"> <"\techo >>file2 \"new line to be kept in the merge result\" &&\n"> <"\tgit commit -a -m \"side-b changes file2\" &&\n"> <"\tgit checkout side-a\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"3-way not overwriting local changes (our side)">)} { (SQ <"\n"> <"\n"> <"\t# At this point, file1 from side-a should be kept as side-b\n"> <"\t# did not touch it.\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\n"> <"\techo >>file1 \"local changes\" &&\n"> <"\tread_tree_u_must_succeed -m -u branch-point side-a side-b &&\n"> <"\tgrep \"new line to be kept\" file1 &&\n"> <"\tgrep \"local changes\" file1\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"3-way not overwriting local changes (their side)">)} { (SQ <"\n"> <"\n"> <"\t# At this point, file2 from side-b should be taken as side-a\n"> <"\t# did not touch it.\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\n"> <"\techo >>file2 \"local changes\" &&\n"> <"\tread_tree_u_must_fail -m -u branch-point side-a side-b &&\n"> <"\t! grep \"new line to be kept\" file2 &&\n"> <"\tgrep \"local changes\" file2\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"funny symlink in work tree">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout -b sym-b side-b &&\n"> <"\tmkdir -p a &&\n"> <"\t>a/b &&\n"> <"\tgit add a/b &&\n"> <"\tgit commit -m \"side adds a/b\" &&\n"> <"\n"> <"\trm -fr a &&\n"> <"\tgit checkout -b sym-a side-a &&\n"> <"\tmkdir -p a &&\n"> <"\ttest_ln_s_add ../b a/b &&\n"> <"\tgit commit -m \"we add a/b\" &&\n"> <"\n"> <"\tread_tree_u_must_succeed -m -u sym-a sym-a sym-b\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SANITY)} {(SQ <"funny symlink in work tree, un-unlink-able">)} { (SQ <"\n"> <"\n"> <"\trm -fr a b &&\n"> <"\tgit reset --hard &&\n"> <"\n"> <"\tgit checkout sym-a &&\n"> <"\tchmod a-w a &&\n"> <"\ttest_must_fail git read-tree -m -u sym-a sym-a sym-b\n"> <"\n"> ) } ) (SimpleCommand words: [{(chmod)} {(a) (Lit_Other "+") (w)} {(a)}] redirects: [(Redir op_id:Redir_Great fd:2 arg_word:{(/dev/null)} spids:[343])] ) (C {(rm)} {(-fr)} {(a)} {(b)}) (C {(test_expect_success)} {(SQ <"D/F setup">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\n"> <"\tgit checkout side-a &&\n"> <"\trm -f subdir/file2 &&\n"> <"\tmkdir subdir/file2 &&\n"> <"\techo qfwfq >subdir/file2/another &&\n"> <"\tgit add subdir/file2/another &&\n"> <"\ttest_tick &&\n"> <"\tgit commit -m \"side-a changes file2 to directory\"\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ )} { (SQ <"\n"> <"\n"> <"\tgit checkout side-b &&\n"> <"\tread_tree_u_must_succeed -m -u branch-point side-b side-a &&\n"> <"\tgit ls-files -u >actual &&\n"> <"\t(\n"> <"\t\ta=$(git rev-parse branch-point:subdir/file2)\n"> <"\t\tb=$(git rev-parse side-a:subdir/file2/another)\n"> <"\t\techo \"100644 $a 1\tsubdir/file2\"\n"> <"\t\techo \"100644 $a 2\tsubdir/file2\"\n"> <"\t\techo \"100644 $b 3\tsubdir/file2/another\"\n"> <"\t) >expect &&\n"> <"\ttest_cmp actual expect\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"D/F resolve">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout side-b &&\n"> <"\tgit merge-resolve branch-point -- side-b side-a\n"> <"\n"> ) } ) (C {(test_expect_success)} {(SQ <"D/F recursive">)} { (SQ <"\n"> <"\n"> <"\tgit reset --hard &&\n"> <"\tgit checkout side-b &&\n"> <"\tgit merge-recursive branch-point -- side-b side-a\n"> <"\n"> ) } ) (C {(test_done)}) ] )