From: Stefan Sperling Subject: add submodule tests To: gameoftrees@openbsd.org Date: Tue, 12 May 2020 16:54:26 +0200 This patch adds 17 tests which check behaviour related to submodules. The commit problem reported by semarie@ is covered, as well as many other cases I could think of. To cover merges I have chosen to write tests for 'got cherrypick'. Cherrypick runs the same merge code as histedit and rebase. Therefore, the latter two commands do not need any submodule tests of their own. Since submodule tree entries are never added to the file index, use cases which operate on the file index only, or which don't use tree objects, will not need any tests. This includes cases like marking files for removal with 'got rm' or staging changes for commit. All tests simply verify the existing behaviour. This already provides some insights: Several commands will try to look up the ID contained in the submodule tree entry, which will usually fail, unless the (SHA1-wise) same object happens to exist in both the outer repository and the submodule. E.g. 'got cat' will show the commit pointed to by a submodule, provided that a commit with the same ID exists in the local repository. Otherwise 'got cat' will raise an error. Updating to, and merging, commits which contain changes to submodule tree entries is already working. Even in cases where a submodule would clash with a file. Submodule tree entries are simply ignored. If the only path changed in a commit is a submodule tree entry this results in no-op updates and merges. And such commits show up with an empty path list in 'got log -P'. An attempt to commit a file where a submodule exists will fail, and Got will ask the user to update and try again. But the next commit attempt will fail in the same way :) I think this set of tests shows that there is a lot of room for improvement in behaviour, especially regarding the reporting of error conditions. With tests it will be much easier for us to see the impact of any changes we might want to make going forward. We can discuss such changes on a case-by-case basis, and always adjust test expectations as needed. Ok? Can anyone think of important test cases I have missed? ----------------------------------------------- commit 4169cf85f3e971e0ecd555e7050ba3d18da9ec1f (submodule) from: Stefan Sperling date: Tue May 12 14:08:17 2020 UTC add submodule tests M regress/cmdline/add.sh M regress/cmdline/blame.sh M regress/cmdline/cat.sh M regress/cmdline/checkout.sh M regress/cmdline/cherrypick.sh M regress/cmdline/commit.sh M regress/cmdline/common.sh M regress/cmdline/diff.sh M regress/cmdline/log.sh M regress/cmdline/tree.sh M regress/cmdline/update.sh diff e936b84e7f44ca8592c5116fbcec48032702bb40 697854b6547de3a4e26b247d900ab03180cf2c75 blob - c77f4d708ad9d8b4be8f6b2d4f47d197a81ea872 blob + 030ece4e122124a89fa7523bf23c419719dcb231 --- regress/cmdline/add.sh +++ regress/cmdline/add.sh @@ -249,9 +249,57 @@ function test_add_directory { test_done "$testroot" "$ret" } +function test_add_clashes_with_submodule { + local testroot=`test_init add_clashes_with_submodule` + + make_single_file_repo $testroot/repo2 foo + + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + got checkout $testroot/repo $testroot/wt > /dev/null + + # Atttempt to add a file clashes with a submodule + echo "This is a file called repo2" > $testroot/wt/repo2 + (cd $testroot/wt && got add repo2 > /dev/null) + + (cd $testroot/wt && got status > $testroot/stdout) + echo "A repo2" > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + # Update for good measure; see the error below. + (cd $testroot/wt && got update > /dev/null) + + # This currently fails with "work tree must be updated"... + (cd $testroot/wt && got commit -m 'add file repo2' \ + > $testroot/stdout 2> $testroot/stderr) + ret="$?" + if [ "$ret" == "0" ]; then + echo "commit succeeded unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + + echo -n "got: work tree must be updated " > $testroot/stderr.expected + echo "before these changes can be committed" >> $testroot/stderr.expected + cmp -s $testroot/stderr.expected $testroot/stderr + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stderr.expected $testroot/stderr + fi + test_done "$testroot" "$ret" +} + run_test test_add_basic run_test test_double_add run_test test_add_multiple run_test test_add_file_in_new_subdir run_test test_add_deleted run_test test_add_directory +run_test test_add_clashes_with_submodule blob - 33d4c773bd77f62c42b299dd8477a9daa3142ddb blob + 9e0475af05cac63a02818ca77164c2355cf2428e --- regress/cmdline/blame.sh +++ regress/cmdline/blame.sh @@ -731,6 +731,37 @@ function test_blame_added_on_branch { test_done "$testroot" "$ret" } +function test_blame_submodule { + local testroot=`test_init blame_submodule` + local commit_id0=`git_show_head $testroot/repo` + local author_time=`git_show_author_time $testroot/repo` + + make_single_file_repo $testroot/repo2 foo + + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + # Attempt a (nonsensical) blame of a submodule. + got blame -r $testroot/repo repo2 \ + > $testroot/stdout 2> $testroot/stderr + ret="$?" + if [ "$ret" == "0" ]; then + echo "blame command succeeded unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + local submodule_id=$(got tree -r $testroot/repo -i | \ + grep 'repo2\$$' | cut -d ' ' -f1) + echo "got: object $submodule_id not found" > $testroot/stderr.expected + + cmp -s $testroot/stderr.expected $testroot/stderr + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stderr.expected $testroot/stderr + fi + test_done "$testroot" "$ret" +} + run_test test_blame_basic run_test test_blame_tag run_test test_blame_file_single_line @@ -741,3 +772,4 @@ run_test test_blame_lines_shifted_down run_test test_blame_commit_subsumed run_test test_blame_blame_h run_test test_blame_added_on_branch +run_test test_blame_submodule blob - e94f00225a6d92aed87516ccb71ed5c81a284b32 blob + 3c88697b0b4d38195808b7f3667068dc92dc3b5f --- regress/cmdline/cat.sh +++ regress/cmdline/cat.sh @@ -202,5 +202,64 @@ function test_cat_path { test_done "$testroot" "$ret" } +function test_cat_submodule { + local testroot=`test_init cat_submodule` + + make_single_file_repo $testroot/repo2 foo + + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + got cat -r $testroot/repo repo2 > $testroot/stdout \ + > $testroot/stdout 2> $testroot/stderr + ret="$?" + if [ "$ret" == "0" ]; then + echo "cat command succeeded unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + local submodule_id=$(got tree -r $testroot/repo -i | \ + grep 'repo2\$$' | cut -d ' ' -f1) + echo "got: object $submodule_id not found" > $testroot/stderr.expected + + cmp -s $testroot/stderr.expected $testroot/stderr + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stderr.expected $testroot/stderr + fi + test_done "$testroot" "$ret" +} + +function test_cat_submodule_of_same_repo { + local testroot=`test_init cat_submodule_of_same_repo` + local commit_id0=`git_show_head $testroot/repo` + local author_time=`git_show_author_time $testroot/repo` + + (cd $testroot && git clone -q repo repo2 >/dev/null) + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + # 'got cat' shows the commit object which the submodule points to + # because a commit with the same ID exists in the outer repository + got cat -r $testroot/repo $commit_id0 | grep ^tree > $testroot/stdout.expected + echo "numparents 0" >> $testroot/stdout.expected + echo "author $GOT_AUTHOR $author_time +0000" >> $testroot/stdout.expected + echo "committer $GOT_AUTHOR $author_time +0000" \ + >> $testroot/stdout.expected + echo "messagelen 22" >> $testroot/stdout.expected + printf "\nadding the test tree\n" >> $testroot/stdout.expected + + got cat -r $testroot/repo repo2 > $testroot/stdout + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + + test_done "$testroot" "$ret" +} + run_test test_cat_basic run_test test_cat_path +run_test test_cat_submodule +run_test test_cat_submodule_of_same_repo blob - 6d3a99a2cce157075a82450a18aaa39d48615932 blob + abba81a65d3c964e736faa7f7c27c92fd429bb1f --- regress/cmdline/checkout.sh +++ regress/cmdline/checkout.sh @@ -261,7 +261,8 @@ function test_checkout_tag { function test_checkout_ignores_submodules { local testroot=`test_init checkout_ignores_submodules` - (cd $testroot && git clone -q repo repo2 >/dev/null) + make_single_file_repo $testroot/repo2 foo + (cd $testroot/repo && git submodule -q add ../repo2) (cd $testroot/repo && git commit -q -m 'adding submodule') blob - 8cca1c73d2210b4fca11501a822a550ddc379362 blob + 15366064a879e3cb8137061a6408c3504af03578 --- regress/cmdline/cherrypick.sh +++ regress/cmdline/cherrypick.sh @@ -234,6 +234,120 @@ function test_cherrypick_into_work_tree_with_conflicts test_done "$testroot" "$ret" } +function test_cherrypick_modified_submodule { + local testroot=`test_init cherrypick_modified_submodules` + + make_single_file_repo $testroot/repo2 foo + + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + got checkout $testroot/repo $testroot/wt > /dev/null + + echo "modified foo" > $testroot/repo2/foo + (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule') + + (cd $testroot/repo && git checkout -q -b newbranch) + # Update the repo/repo2 submodule link on newbranch + (cd $testroot/repo && git -C repo2 pull -q) + (cd $testroot/repo && git add repo2) + git_commit $testroot/repo -m "modified submodule link" + local commit_id=`git_show_head $testroot/repo` + + # This cherrypick is a no-op because Got's file index + # does not track submodules. + (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout) + + echo -n > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + +function test_cherrypick_added_submodule { + local testroot=`test_init cherrypick_added_submodules` + + got checkout $testroot/repo $testroot/wt > /dev/null + + make_single_file_repo $testroot/repo2 foo + + # Add the repo/repo2 submodule on newbranch + (cd $testroot/repo && git checkout -q -b newbranch) + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + local commit_id=`git_show_head $testroot/repo` + + (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout) + + echo "A .gitmodules" > $testroot/stdout.expected + echo "Merged commit $commit_id" >> $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + +function test_cherrypick_conflict_wt_file_vs_repo_submodule { + local testroot=`test_init cherrypick_conflict_wt_file_vs_repo_submodule` + + got checkout $testroot/repo $testroot/wt > /dev/null + + # Add a file which will clash with the submodule + echo "This is a file called repo2" > $testroot/wt/repo2 + (cd $testroot/wt && got add repo2 > /dev/null) + (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null) + ret="$?" + if [ "$ret" != "0" ]; then + echo "commit failed unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + + make_single_file_repo $testroot/repo2 foo + + # Add the repo/repo2 submodule on newbranch + (cd $testroot/repo && git checkout -q -b newbranch) + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + local commit_id=`git_show_head $testroot/repo` + + # Modify the clashing file such that any modifications brought + # in by 'got cherrypick' would require a merge. + echo "This file was changed" > $testroot/wt/repo2 + + (cd $testroot/wt && got update >/dev/null) + (cd $testroot/wt && got cherrypick $commit_id > $testroot/stdout) + + echo "A .gitmodules" > $testroot/stdout.expected + echo "Merged commit $commit_id" >> $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + (cd $testroot/wt && got status > $testroot/stdout) + + echo "A .gitmodules" > $testroot/stdout.expected + echo "M repo2" >> $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + run_test test_cherrypick_basic run_test test_cherrypick_root_commit run_test test_cherrypick_into_work_tree_with_conflicts +run_test test_cherrypick_modified_submodule +run_test test_cherrypick_added_submodule +run_test test_cherrypick_conflict_wt_file_vs_repo_submodule blob - aafe14583ef36fe909f7c1ce1608fe5ae98bb5a1 blob + 3c8e833ec7ad8718957fd61f1be12dd5eceabd1f --- regress/cmdline/commit.sh +++ regress/cmdline/commit.sh @@ -862,6 +862,43 @@ function test_commit_normalizes_filemodes { test_done "$testroot" "$ret" } +function test_commit_with_unrelated_submodule { + local testroot=`test_init commit_with_unrelated_submodule` + + make_single_file_repo $testroot/repo2 foo + + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + got checkout $testroot/repo $testroot/wt > /dev/null + ret="$?" + if [ "$ret" != "0" ]; then + test_done "$testroot" "$ret" + return 1 + fi + + echo "modified alpha" > $testroot/wt/alpha + + # Currently fails with "bad file type" error + (cd $testroot/wt && got commit -m 'modify alpha' \ + > $testroot/stdout 2> $testroot/stderr) + ret="$?" + if [ "$ret" == "0" ]; then + echo "commit succeeded unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + echo "got: bad file type" > $testroot/stderr.expected + + cmp -s $testroot/stderr.expected $testroot/stderr + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stderr.expected $testroot/stderr + return 1 + fi + test_done "$testroot" "$ret" +} + run_test test_commit_basic run_test test_commit_new_subdir run_test test_commit_subdir @@ -881,3 +918,4 @@ run_test test_commit_tree_entry_sorting run_test test_commit_gitconfig_author run_test test_commit_xbit_change run_test test_commit_normalizes_filemodes +run_test test_commit_with_unrelated_submodule blob - ff453b223f4e883bf285ec5a0e4e0c465ba3dd3c blob + 5104375e287f0e845051a912863028d3e6a4d86c --- regress/cmdline/common.sh +++ regress/cmdline/common.sh @@ -129,6 +129,27 @@ function make_test_tree echo zeta > $repo/epsilon/zeta } +function make_single_file_repo +{ + repo="$1" + file="$2" + + mkdir $repo + git_init $repo + echo "this is file $file" > $repo/$file + (cd $repo && git add .) + git_commit $repo -m "intialize $repo with file $file" +} + +function get_loose_object_path +{ + local repo="$1" + local id="$2" + local id0=`trim_obj_id 38 $id` + local idrest=`echo ${id#[0-9a-f][0-9a-f]}` + echo "$repo/.git/objects/$id0/$idrest" +} + function get_blob_id { repo="$1" blob - 6fb2ea68d14402fd1574c7ba4c85ff2feb11fb8f blob + a3f99c8779d3bd933ae0f0f14741563fad6794a7 --- regress/cmdline/diff.sh +++ regress/cmdline/diff.sh @@ -329,8 +329,42 @@ function test_diff_ignore_whitespace { test_done "$testroot" "$ret" } +function test_diff_submodule_of_same_repo { + local testroot=`test_init diff_submodule_of_same_repo` + + (cd $testroot && git clone -q repo repo2 >/dev/null) + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + epsilon_id=$(got tree -r $testroot/repo -i | grep 'epsilon/$' | \ + cut -d ' ' -f 1) + submodule_id=$(got tree -r $testroot/repo -i | grep 'repo2\$$' | \ + cut -d ' ' -f 1) + + # Attempt a (nonsensical) diff between a tree object and a submodule. + # Currently fails with "wrong type of object" error + got diff -r $testroot/repo $epsilon_id $submodule_id \ + > $testroot/stdout 2> $testroot/stderr + ret="$?" + if [ "$ret" == "0" ]; then + echo "diff command succeeded unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + echo "got: wrong type of object" > $testroot/stderr.expected + + cmp -s $testroot/stderr.expected $testroot/stderr + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stderr.expected $testroot/stderr + return 1 + fi + test_done "$testroot" "$ret" +} + run_test test_diff_basic run_test test_diff_shows_conflict run_test test_diff_tag run_test test_diff_lightweight_tag run_test test_diff_ignore_whitespace +run_test test_diff_submodule_of_same_repo blob - d88d0fa11e29a8dc0efae3812238dcf959a1891b blob + c563ee1744ab12c961f2d4a98fcb8a56e3f2df3f --- regress/cmdline/log.sh +++ regress/cmdline/log.sh @@ -690,6 +690,85 @@ function test_log_changed_paths { test_done "$testroot" "$ret" } +function test_log_submodule { + local testroot=`test_init log_submodule` + + make_single_file_repo $testroot/repo2 foo + + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + local head_commit=`git_show_head $testroot/repo` + + echo "commit $head_commit (master)" > $testroot/stdout.expected + + got log -r $testroot/repo -l1 repo2 | grep ^commit > $testroot/stdout + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + echo " A .gitmodules" > $testroot/stdout.expected + + got log -r $testroot/repo -l1 -P repo2 | grep '^ [MDmA]' \ + > $testroot/stdout + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + got log -p -r $testroot/repo -l1 repo2 \ + > $testroot/stdout 2> $testroot/stderr + ret="$?" + if [ "$ret" == "0" ]; then + echo "log command succeeded unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + local submodule_id=$(got tree -r $testroot/repo -i | \ + grep 'repo2\$$' | cut -d ' ' -f1) + echo "got: object $submodule_id not found" > $testroot/stderr.expected + + cmp -s $testroot/stderr.expected $testroot/stderr + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stderr.expected $testroot/stderr + test_done "$testroot" "$ret" + return 1 + fi + + echo "modified foo" > $testroot/repo2/foo + (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule') + + # Update the repo/repo2 submodule link + (cd $testroot/repo && git -C repo2 pull -q) + (cd $testroot/repo && git add repo2) + git_commit $testroot/repo -m "changed submodule link" + + # log -P does not show the changed submodule path + got log -P -r $testroot/repo -l1 repo2 > $testroot/stdout.full + ret="$?" + if [ "$ret" != "0" ]; then + echo "log command failed unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + grep '^ [MDmA]' $testroot/stdout.full > $testroot/stdout + + echo -n > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + run_test test_log_in_repo run_test test_log_in_bare_repo run_test test_log_in_worktree @@ -702,3 +781,4 @@ run_test test_log_end_at_commit run_test test_log_reverse_display run_test test_log_in_worktree_different_repo run_test test_log_changed_paths +run_test test_log_submodule blob - 5a9d63de84c2b6a4ded2565e9eca228c844eeafd blob + 44be74f368edca7e5c51454b4911ab4fc3a71465 --- regress/cmdline/tree.sh +++ regress/cmdline/tree.sh @@ -77,5 +77,65 @@ function test_tree_branch { test_done "$testroot" "$ret" } +function test_tree_submodule { + local testroot=`test_init tree_submodule` + + make_single_file_repo $testroot/repo2 foo + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + local submodule_id=$(got tree -r $testroot/repo -i | \ + grep 'repo2\$$' | cut -d ' ' -f1) + local objpath=`get_loose_object_path $testroot/repo $submodule_id` + + # Currently fails in open(2) + got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr + ret="$?" + if [ "$ret" == "0" ]; then + echo "tree command succeeded unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + echo "got: open: $objpath: No such file or directory" \ + > $testroot/stderr.expected + + cmp -s $testroot/stderr.expected $testroot/stderr + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stderr.expected $testroot/stderr + return 1 + fi + test_done "$testroot" "$ret" +} + +function test_tree_submodule_of_same_repo { + local testroot=`test_init tree_submodule_of_same_repo` + + (cd $testroot && git clone -q repo repo2 >/dev/null) + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + # Currently fails with "bad object data" + got tree -r $testroot/repo repo2 > $testroot/stdout 2> $testroot/stderr + ret="$?" + if [ "$ret" == "0" ]; then + echo "tree command succeeded unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + echo "got-read-tree: bad object data" > $testroot/stderr.expected + echo "got: bad object data" >> $testroot/stderr.expected + + cmp -s $testroot/stderr.expected $testroot/stderr + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stderr.expected $testroot/stderr + return 1 + fi + test_done "$testroot" "$ret" +} + run_test test_tree_basic run_test test_tree_branch +run_test test_tree_submodule +run_test test_tree_submodule_of_same_repo blob - 05fd291f00dbf87bd49689c4a514adf28e7a09f8 blob + 60a1a2ab40ff159845a71f43bd69ec3145dfa795 --- regress/cmdline/update.sh +++ regress/cmdline/update.sh @@ -1710,6 +1710,122 @@ function test_update_preserves_conflicted_file { test_done "$testroot" "$ret" } +function test_update_modified_submodules { + local testroot=`test_init update_modified_submodules` + + make_single_file_repo $testroot/repo2 foo + + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + got checkout $testroot/repo $testroot/wt > /dev/null + + echo "modified foo" > $testroot/repo2/foo + (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule') + + # Update the repo/repo2 submodule link + (cd $testroot/repo && git -C repo2 pull -q) + (cd $testroot/repo && git add repo2) + git_commit $testroot/repo -m "modified submodule link" + + # This update only records the new base commit. Otherwise it is a + # no-op change because Got's file index does not track submodules. + echo -n "Updated to commit " > $testroot/stdout.expected + git_show_head $testroot/repo >> $testroot/stdout.expected + echo >> $testroot/stdout.expected + + (cd $testroot/wt && got update > $testroot/stdout) + + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + +function test_update_adds_submodule { + local testroot=`test_init update_adds_submodule` + + got checkout $testroot/repo $testroot/wt > /dev/null + + make_single_file_repo $testroot/repo2 foo + + echo "modified foo" > $testroot/repo2/foo + (cd $testroot/repo2 && git commit -q -a -m 'modified a submodule') + + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + echo "A .gitmodules" > $testroot/stdout.expected + echo -n "Updated to commit " >> $testroot/stdout.expected + git_show_head $testroot/repo >> $testroot/stdout.expected + echo >> $testroot/stdout.expected + + (cd $testroot/wt && got update > $testroot/stdout) + + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + +function test_update_conflict_wt_file_vs_repo_submodule { + local testroot=`test_init update_conflict_wt_file_vs_repo_submodule` + + got checkout $testroot/repo $testroot/wt > /dev/null + + make_single_file_repo $testroot/repo2 foo + + # Add a file which will clash with the submodule + echo "This is a file called repo2" > $testroot/wt/repo2 + (cd $testroot/wt && got add repo2 > /dev/null) + (cd $testroot/wt && got commit -m 'add file repo2' > /dev/null) + ret="$?" + if [ "$ret" != "0" ]; then + echo "commit failed unexpectedly" >&2 + test_done "$testroot" "1" + return 1 + fi + + (cd $testroot/repo && git submodule -q add ../repo2) + (cd $testroot/repo && git commit -q -m 'adding submodule') + + # Modify the clashing file such that any modifications brought + # in by 'got update' would require a merge. + echo "This file was changed" > $testroot/wt/repo2 + + # No conflict occurs because 'got update' ignores the submodule + # and leaves the clashing file as it was. + echo "A .gitmodules" > $testroot/stdout.expected + echo -n "Updated to commit " >> $testroot/stdout.expected + git_show_head $testroot/repo >> $testroot/stdout.expected + echo >> $testroot/stdout.expected + + (cd $testroot/wt && got update > $testroot/stdout) + + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + test_done "$testroot" "$ret" + return 1 + fi + + (cd $testroot/wt && got status > $testroot/stdout) + + echo "M repo2" > $testroot/stdout.expected + cmp -s $testroot/stdout.expected $testroot/stdout + ret="$?" + if [ "$ret" != "0" ]; then + diff -u $testroot/stdout.expected $testroot/stdout + fi + test_done "$testroot" "$ret" +} + + run_test test_update_basic run_test test_update_adds_file run_test test_update_deletes_file @@ -1742,3 +1858,6 @@ run_test test_update_bumps_base_commit_id run_test test_update_tag run_test test_update_toggles_xbit run_test test_update_preserves_conflicted_file +run_test test_update_modified_submodules +run_test test_update_adds_submodule +run_test test_update_conflict_wt_file_vs_repo_submodule