{"thread":{"id":"36290","subject":"[RFC/PATCH 1/4] test-lib: add test_dir_is_empty()","startedAt":"2014-03-25T17:03:50Z","lastAt":"2014-04-18T12:39:18Z","messageCount":17,"participants":["Jens Lehmann","Junio C Hamano","Michael Haggerty","David Kastrup","W. Trevor King","Heiko Voigt"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"237669","messageId":"5331B6F6.60501@web.de","threadId":"36290","inReplyTo":null,"subject":"[RFC/PATCH 0/4] Add submodule test harness","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2014-03-25T17:03:50Z","receivedAt":"2014-03-25T17:03:50Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"So here is my proposal for a single test harness for submodule updates. It is\nintended to be easily applicable to all work tree manipulating commands. The\ncurrent version tests the status quo (and it documents two bugs in current\nGit). This framework will be extended to cover recursive submodule update too\nin a later series.\n\nThe first patch adds a simple helper function to the test lib which makes\nit easier to test for an empty submodule directory.\n\nThe second patch contains the heavy lifting, it adds the test framework for\nswitching submodules. Currently only transitions without merge conflicts are\ntested for, I intend to add others producing merge conflicts in a follow-up\nseries.\n\nThe third and forth patch show how to apply this framework to a simple\ncommand (checkout) and a more complicated case where a helper function is\nused to execute a preparing command (diff) which produces the input for the\nthen to-be-tested command (apply).\n\nI'm currently working on adding this harness to more commands. read-tree and\nreset are finished, merge and pull still show some oddities when used with\nthe --no-ff option, also cherry-pick and checkout-index are not working as\nexpected yet. And then there are am, apply, bisect, rebase, revert & stash\napply which still need to be covered.\n\nJens Lehmann (4):\n  test-lib: add test_dir_is_empty()\n  Submodules: Add the lib-submodule-update.sh test library\n  checkout: call the new submodule update test framework\n  apply: add t4137 for submodule updates\n\n t/lib-submodule-update.sh     | 627 ++++++++++++++++++++++++++++++++++++++++++\n t/t2013-checkout-submodule.sh |   5 +\n t/t4137-apply-submodule.sh    |  20 ++\n t/test-lib-functions.sh       |  11 +\n 4 files changed, 663 insertions(+)\n create mode 100755 t/lib-submodule-update.sh\n create mode 100755 t/t4137-apply-submodule.sh\n\n-- \n1.9.1.327.g3d8d896\n"},{"id":"237666","messageId":"5331B717.5010600@web.de","threadId":"36290","inReplyTo":"5331B6F6.60501@web.de","subject":"[RFC/PATCH 1/4] test-lib: add test_dir_is_empty()","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2014-03-25T17:04:23Z","receivedAt":"2014-03-25T17:04:23Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"For the upcoming submodule test framework we often need to assert that an\nempty directory exists in the work tree. Add the test_dir_is_empty()\nfunction which asserts that the given argument is an empty directory.\n\nSigned-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n---\n\nI believe this one is pretty straightforward (unless I missed that this\nfunctionality already exists someplace I forgot to look ;-).\n\n t/test-lib-functions.sh | 11 +++++++++++\n 1 file changed, 11 insertions(+)\n\ndiff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\nindex 158e10a..93d10cd 100644\n--- a/t/test-lib-functions.sh\n+++ b/t/test-lib-functions.sh\n@@ -489,6 +489,17 @@ test_path_is_dir () {\n \tfi\n }\n\n+# Check if the directory exists and is empty as expected, barf otherwise.\n+test_dir_is_empty () {\n+\ttest_path_is_dir \"$1\" &&\n+\tif test $(ls -a1 \"$1\" | wc -l) != 2\n+\tthen\n+\t\techo \"Directory '$1' is not empty, it contains:\"\n+\t\tls -la \"$1\"\n+\t\treturn 1\n+\tfi\n+}\n+\n test_path_is_missing () {\n \tif [ -e \"$1\" ]\n \tthen\n-- \n1.9.1.327.g3d8d896\n"},{"id":"237667","messageId":"5331B741.6000606@web.de","threadId":"36290","inReplyTo":"5331B6F6.60501@web.de","subject":"[RFC/PATCH 2/4] Submodules: Add the lib-submodule-update.sh test library","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2014-03-25T17:05:05Z","receivedAt":"2014-03-25T17:05:05Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Add this test library to simplify covering all combinations of submodule\nupdate scenarios without having to add those to a test of each work tree\nmanipulating command over and over again.\n\nThe functions test_submodule_switch() and test_submodule_forced_switch()\nare intended to be called from a test script with a single argument. This\nargument is either a work tree manipulating command (including any command\nline options) or a function (when more than a single git command is needed\nto switch work trees from the current HEAD to another commit). This\ncommand (or function) is passed a target branch as argument. The two new\nfunctions check that each submodule transition is handled as expected,\nwhich currently means that submodule work trees are not affected until\n\"git submodule update\" is called. The \"forced\" variant is for commands\nusing their '-f' or '--hard' option and expects them to overwrite local\nmodifications as a result. Each of these two functions contains 14\ntests_expect_* calls.\n\nCalling one of these test functions the first time creates a repository\nnamed \"submodule_update_repo\". At first it contains two files, then a\nsingle submodule is added in another commit followed by commits covering\nall relevant submodule modifications. This repository is newly cloned into\nthe \"submodule_update\" for each test_expect_* to avoid interference\nbetween different parts of the test functions (some to-be-tested commands\nalso manipulate refs along with the work tree, e.g. \"git reset\").\n\nFollow-up commits will then call these two test functions for all work\ntree manipulating commands (with a combination of all their options\nrelevant to what they do with the work tree) making sure they work as\nexpected. Later this test library will be extended to cover merges\nresulting in conflicts too. Also it is intended to be easily extendable\nfor the recursive update functionality, where even more combinations of\nsubmodule modifications have to be tested for.\n\nThis version documents two bugs in current Git with expected failures:\n\n*) When a submodule is replaced with a tracked file of the same name the\n   submodule work tree including any local modifications (and even the\n   whole history if it uses a .git directory instead of a gitfile!) is\n   simply removed.\n\n*) Forced work tree updates happily manipulate files in the directory of a\n   submodule that has just been removed in the superproject (but is of\n   course still present in the work tree due to the way submodules are\n   currently handled). This becomes dangerous when files in the submodule\n   directory are overwritten by files from the new superproject commit, as\n   any modifications to the submodule files will be lost) and is expected\n   to also destroy history in the - admittedly unlikely case - the new\n   commit adds a file named \".git\" to the submodule directory.\n\nSigned-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n---\n\nI think the first bug really needs to be fixed, as that behavior is extremely\nnasty. We should always protect work tree modifications (unless forced) and\n*never* remove a .git directory (even when forced).\n\nI'm not so sure about the second one. Even though I believe the current\nbehavior is not correct (switching commits should never mess around in a\nsubmodule directory) it may be that people who committed a directory =>\nsubmodule transition (or vice versa) are depending on the current\nbehavior. Fixing the bug would forbid to repeat the submodule => directory\ntransition and only allow that after the user removed the submodule directory\nmanually. And as the potential fallout of this bug is not as disastrous as\nfor the first bug, I might be convinced we should not fix it.\n\n t/lib-submodule-update.sh | 627 ++++++++++++++++++++++++++++++++++++++++++++++\n 1 file changed, 627 insertions(+)\n create mode 100755 t/lib-submodule-update.sh\n\ndiff --git a/t/lib-submodule-update.sh b/t/lib-submodule-update.sh\nnew file mode 100755\nindex 0000000..de5d54e\n--- /dev/null\n+++ b/t/lib-submodule-update.sh\n@@ -0,0 +1,627 @@\n+# Create a submodule layout used for all tests below.\n+#\n+# The following use cases are covered:\n+# - New submodule (no_submodule => add_sub1)\n+# - Removed submodule (add_sub1 => remove_sub1)\n+# - Updated submodule (add_sub1 => modify_sub1)\n+# - Submodule updated to invalid commit (add_sub1 => invalid_sub1)\n+# - Submodule updated from invalid commit (invalid_sub1 => valid_sub1)\n+# - Submodule replaced by tracked files in directory (add_sub1 =>\n+#   replace_sub1_with_directory)\n+# - Directory containing tracked files replaced by submodule\n+#   (replace_sub1_with_directory => replace_directory_with_sub1)\n+# - Submodule replaced by tracked file with the same name (add_sub1 =>\n+#   replace_sub1_with_file)\n+# - Tracked file replaced by submodule (replace_sub1_with_file =>\n+#   replace_file_with_sub1)\n+#\n+#                   --O-----O\n+#                  /  ^     replace_directory_with_sub1\n+#                 /   replace_sub1_with_directory\n+#                /----O\n+#               /     ^\n+#              /      modify_sub1\n+#      O------O-------O\n+#      ^      ^\\      ^\n+#      |      | \\     remove_sub1\n+#      |      |  -----O-----O\n+#      |      |   \\   ^     replace_file_with_sub1\n+#      |      |    \\  replace_sub1_with_file\n+#      |   add_sub1 --O-----O\n+# no_submodule        ^     valid_sub1\n+#                     invalid_sub1\n+#\n+create_lib_submodule_repo () {\n+\tgit init submodule_update_repo &&\n+\t(\n+\t\tcd submodule_update_repo &&\n+\t\techo \"expect\" >>.gitignore &&\n+\t\techo \"actual\" >>.gitignore &&\n+\t\techo \"x\" >file1 &&\n+\t\techo \"y\" >file2 &&\n+\t\tgit add .gitignore file1 file2 &&\n+\t\tgit commit -m \"Base\" &&\n+\t\tgit branch \"no_submodule\" &&\n+\n+\t\tgit checkout -b \"add_sub1\" &&\n+\t\tgit submodule add ./. sub1 &&\n+\t\tgit commit -m \"Add sub1\" &&\n+\t\tgit checkout -b remove_sub1 &&\n+\t\tgit revert HEAD &&\n+\n+\t\tgit checkout -b \"modify_sub1\" \"add_sub1\" &&\n+\t\tgit submodule update &&\n+\t\t(\n+\t\t\tcd sub1 &&\n+\t\t\tgit fetch &&\n+\t\t\tgit checkout -b \"modifications\" &&\n+\t\t\techo \"z\" >file2 &&\n+\t\t\techo \"x\" >file3 &&\n+\t\t\tgit add file2 file3 &&\n+\t\t\tgit commit -m \"modified file2 and added file3\" &&\n+\t\t\tgit push origin modifications\n+\t\t) &&\n+\t\tgit add sub1 &&\n+\t\tgit commit -m \"Modify sub1\" &&\n+\n+\t\tgit checkout -b \"replace_sub1_with_directory\" \"add_sub1\" &&\n+\t\tgit submodule update &&\n+\t\t(\n+\t\t\tcd sub1 &&\n+\t\t\tgit checkout modifications\n+\t\t) &&\n+\t\tgit rm --cached sub1 &&\n+\t\trm sub1/.git* &&\n+\t\tgit config -f .gitmodules --remove-section \"submodule.sub1\" &&\n+\t\tgit add .gitmodules sub1/* &&\n+\t\tgit commit -m \"Replace sub1 with directory\" &&\n+\t\tgit checkout -b replace_directory_with_sub1 &&\n+\t\tgit revert HEAD &&\n+\n+\t\tgit checkout -b \"replace_sub1_with_file\" \"add_sub1\" &&\n+\t\tgit rm sub1 &&\n+\t\techo \"content\" >sub1 &&\n+\t\tgit add sub1 &&\n+\t\tgit commit -m \"Replace sub1 with file\" &&\n+\t\tgit checkout -b replace_file_with_sub1 &&\n+\t\tgit revert HEAD &&\n+\n+\t\tgit checkout -b \"invalid_sub1\" \"add_sub1\" &&\n+\t\tgit update-index --cacheinfo 160000 0123456789012345678901234567890123456789 sub1 &&\n+\t\tgit commit -m \"Invalid sub1 commit\" &&\n+\t\tgit checkout -b valid_sub1 &&\n+\t\tgit revert HEAD &&\n+\t\tgit checkout master\n+\t)\n+}\n+\n+# Helper function to replace gitfile with .git directory\n+replace_gitfile_with_git_dir () {\n+\t(\n+\t\tcd \"$1\" &&\n+\t\tgit_dir=\"$(git rev-parse --git-dir)\" &&\n+\t\trm -f .git &&\n+\t\tcp -a \"$git_dir\" .git &&\n+\t\tGIT_WORK_TREE=. git config --unset core.worktree\n+\t)\n+}\n+\n+# Test that the .git directory in the submodule is unchanged (except for the\n+# core.worktree setting)\n+test_git_directory_is_unchanged () {\n+\t(\n+\t\tcd \"$1\" &&\n+\t\tgit config core.worktree \"../../../$1\"\n+\t) &&\n+\tgit diff -r \".git/modules/$1\" \"$1/.git\" &&\n+\t(\n+\t\tcd \"$1\" &&\n+\t\tGIT_WORK_TREE=. git config --unset core.worktree\n+\t)\n+}\n+\n+# Helper function to be executed at the start of every test below, it sets up\n+# the submodule repo if it doesn't exist and configures the most problematic\n+# settings for diff.ignoreSubmodules.\n+prolog () {\n+\t(test -d submodule_update_repo || create_lib_submodule_repo) &&\n+\ttest_config_global diff.ignoreSubmodules all &&\n+\ttest_config diff.ignoreSubmodules all\n+}\n+\n+# Helper function to bring work tree back into the state given by the\n+# commit. This includes trying to populate sub1 accordingly if it exists and\n+# should be updated to an existing commit.\n+reset_work_tree_to () {\n+\trm -rf submodule_update &&\n+\tgit clone submodule_update_repo submodule_update &&\n+\t(\n+\t\tcd submodule_update &&\n+\t\trm -rf sub1 &&\n+\t\tgit checkout -f \"$1\" &&\n+\t\tgit status -u -s >actual &&\n+\t\ttest_must_be_empty actual &&\n+\t\tsha1=$(git ls-tree HEAD \"sub1\" 2>/dev/null | grep 160000 | tr '\\t' ' ' | cut -d ' ' -f3) &&\n+\t\tif test -n \"$sha1\" &&\n+\t\t   test $(cd \"sub1\" && git rev-parse --verify \"$sha1^{commit}\")\n+\t\tthen\n+\t\t\tgit submodule update --init --recursive \"sub1\"\n+\t\tfi\n+\t)\n+}\n+\n+# Test that the superproject contains the content according to commit \"$1\"\n+# (the work tree must match the index for everything but submodules but the\n+# index must exactly match the given commit including any submodule SHA-1s).\n+test_superproject_content () {\n+\tgit diff-index --cached \"$1\" >actual &&\n+\ttest_must_be_empty actual &&\n+\tgit diff-files --ignore-submodules >actual &&\n+\ttest_must_be_empty actual\n+}\n+\n+# Test that the given submodule at path \"$1\" contains the content according\n+# to the submodule commit recorded in the superproject's commit \"$2\"\n+test_submodule_content () {\n+\tif test $# != 2\n+\tthen\n+\t\techo \"test_submodule_content needs two arguments\"\n+\t\treturn 1\n+\tfi &&\n+\tsubmodule=\"$1\" &&\n+\tcommit=\"$2\" &&\n+\ttest -d \"$submodule\"/ &&\n+\tif ! test -f \"$submodule\"/.git && ! test -d \"$submodule\"/.git\n+\tthen\n+\t\techo \"Submodule $submodule is not populated\"\n+\t\treturn 1\n+\tfi &&\n+\tsha1=$(git ls-tree \"$commit\" \"$submodule\" 2>/dev/null | tr '\\t' ' ' | cut -d ' ' -f3) &&\n+\tif test -z \"$sha1\"\n+\tthen\n+\t\techo \"Couldn't retrieve SHA-1 of $submodule for $commit\"\n+\t\treturn 1\n+\tfi &&\n+\t(\n+\t\tcd \"$submodule\" &&\n+\t\tgit status -u -s >actual &&\n+\t\ttest_must_be_empty actual &&\n+\t\tgit diff \"$sha1\" >actual &&\n+\t\ttest_must_be_empty actual\n+\t)\n+}\n+\n+# Test that the following transitions are correctly handled:\n+# - Updated submodule\n+# - New submodule\n+# - Removed submodule\n+# - Directory containing tracked files replaced by submodule\n+# - Submodule replaced by tracked files in directory\n+# - Submodule replaced by tracked file with the same name\n+# - tracked file replaced by submodule\n+#\n+# The default is that submodule contents aren't changed until \"git submodule\n+# update\" is run. And even then that command doesn't delete the work tree of\n+# a removed submodule.\n+#\n+# Removing a submodule containing a .git directory must fail even when forced\n+# to protect the history!\n+#\n+\n+# Test that submodule contents are currently not updated when switching\n+# between commits that change a submodule.\n+test_submodule_switch () {\n+\tcommand=\"$1\"\n+\t######################### Appearing submodule #########################\n+\t# Switching to a commit letting a submodule appear creates empty dir ...\n+\ttest_expect_success \"$command: added submodule creates empty directory\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to no_submodule &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t add_sub1 origin/add_sub1 &&\n+\t\t\t$command add_sub1 &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_dir_is_empty sub1 &&\n+\t\t\tgit submodule update --init --recursive &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# ... and doesn't care if it already exists ...\n+\ttest_expect_success \"$command: added submodule leaves existing empty directory alone\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to no_submodule &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tmkdir sub1 &&\n+\t\t\tgit branch -t add_sub1 origin/add_sub1 &&\n+\t\t\t$command add_sub1 &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_dir_is_empty sub1 &&\n+\t\t\tgit submodule update --init --recursive &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# ... unless there is an untracked file in its place.\n+\ttest_expect_success \"$command: added submodule doesn't remove untracked unignored file with same name\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to no_submodule &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t add_sub1 origin/add_sub1 &&\n+\t\t\techo -n >sub1 &&\n+\t\t\ttest_must_fail $command add_sub1 &&\n+\t\t\ttest_superproject_content origin/no_submodule &&\n+\t\t\ttest_must_be_empty sub1\n+\t\t)\n+\t'\n+\t# Replacing a tracked file with a submodule produces an empty\n+\t# directory ...\n+\ttest_expect_success \"$command: replace tracked file with submodule creates empty directory\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to replace_sub1_with_file &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_file_with_sub1 origin/replace_file_with_sub1 &&\n+\t\t\t$command replace_file_with_sub1 &&\n+\t\t\ttest_superproject_content origin/replace_file_with_sub1 &&\n+\t\t\ttest_dir_is_empty sub1 &&\n+\t\t\tgit submodule update --init --recursive &&\n+\t\t\ttest_submodule_content sub1 origin/replace_file_with_sub1\n+\t\t)\n+\t'\n+\t# ... as does removing a directory with tracked files with a\n+\t# submodule.\n+\ttest_expect_success \"$command: replace directory with submodule\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to replace_sub1_with_directory &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_directory_with_sub1 origin/replace_directory_with_sub1 &&\n+\t\t\t$command replace_directory_with_sub1 &&\n+\t\t\ttest_superproject_content origin/replace_directory_with_sub1 &&\n+\t\t\ttest_dir_is_empty sub1 &&\n+\t\t\tgit submodule update --init --recursive &&\n+\t\t\ttest_submodule_content sub1 origin/replace_directory_with_sub1\n+\t\t)\n+\t'\n+\n+\t######################## Disappearing submodule #######################\n+\t# Removing a submodule doesn't remove its work tree ...\n+\ttest_expect_success \"$command: removed submodule leaves submodule directory and its contents in place\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t remove_sub1 origin/remove_sub1 &&\n+\t\t\t$command remove_sub1 &&\n+\t\t\ttest_superproject_content origin/remove_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# ... especially when it contains a .git directory.\n+\ttest_expect_success \"$command: removed submodule leaves submodule containing a .git directory alone\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t remove_sub1 origin/remove_sub1 &&\n+\t\t\treplace_gitfile_with_git_dir sub1 &&\n+\t\t\t$command remove_sub1 &&\n+\t\t\ttest_superproject_content origin/remove_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1 &&\n+\t\t\ttest_git_directory_is_unchanged sub1\n+\t\t)\n+\t'\n+\t# Replacing a submodule with files in a directory must fail as the\n+\t# submodule work tree isn't removed ...\n+\ttest_expect_success \"$command: replace submodule with a directory fails\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&\n+\t\t\ttest_must_fail $command replace_sub1_with_directory &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# ... especially when it contains a .git directory.\n+\ttest_expect_success \"$command: replace submodule containing a .git directory with a directory fails\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&\n+\t\t\treplace_gitfile_with_git_dir sub1 &&\n+\t\t\ttest_must_fail $command replace_sub1_with_directory &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1 &&\n+\t\t\ttest_git_directory_is_unchanged sub1\n+\t\t)\n+\t'\n+\t# Replacing it with a file must fail as it could throw away any local\n+\t# work tree changes ...\n+\ttest_expect_failure \"$command: replace submodule directory with a file must fail\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_sub1_with_file origin/replace_sub1_with_file &&\n+\t\t\ttest_must_fail $command replace_sub1_with_file &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# ... or even destroy unpushed parts of submodule history if that\n+\t# still uses a .git directory.\n+\ttest_expect_failure \"$command: replace submodule directory with a file must fail\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_sub1_with_file origin/replace_sub1_with_file &&\n+\t\t\treplace_gitfile_with_git_dir sub1 &&\n+\t\t\ttest_must_fail $command replace_sub1_with_file &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1 &&\n+\t\t\ttest_git_directory_is_unchanged sub1\n+\t\t)\n+\t'\n+\n+\t########################## Modified submodule #########################\n+\t# Updating a submodule sha1 doesn't update the submodule's work tree\n+\ttest_expect_success \"$command: modified submodule does not update submodule work tree\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t modify_sub1 origin/modify_sub1 &&\n+\t\t\t$command modify_sub1 &&\n+\t\t\ttest_superproject_content origin/modify_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1 &&\n+\t\t\tgit submodule update &&\n+\t\t\ttest_submodule_content sub1 origin/modify_sub1\n+\t\t)\n+\t'\n+\n+\t# Updating a submodule to an invalid sha1 doesn't update the\n+\t# submodule's work tree, subsequent update will fail\n+\ttest_expect_success \"$command: modified submodule does not update submodule work tree to invalid commit\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t invalid_sub1 origin/invalid_sub1 &&\n+\t\t\t$command invalid_sub1 &&\n+\t\t\ttest_superproject_content origin/invalid_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1 &&\n+\t\t\ttest_must_fail git submodule update &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# Updating a submodule from an invalid sha1 doesn't update the\n+\t# submodule's work tree, subsequent update will succeed\n+\ttest_expect_success \"$command: modified submodule does not update submodule work tree from invalid commit\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to invalid_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t valid_sub1 origin/valid_sub1 &&\n+\t\t\t$command valid_sub1 &&\n+\t\t\ttest_superproject_content origin/valid_sub1 &&\n+\t\t\ttest_dir_is_empty sub1 &&\n+\t\t\tgit submodule update --init --recursive &&\n+\t\t\ttest_submodule_content sub1 origin/valid_sub1\n+\t\t)\n+\t'\n+}\n+\n+# Test that submodule contents are currently not updated when switching\n+# between commits that change a submodule, but throwing away local changes in\n+# the superproject is allowed.\n+test_submodule_forced_switch () {\n+\tcommand=\"$1\"\n+\t######################### Appearing submodule #########################\n+\t# Switching to a commit letting a submodule appear creates empty dir ...\n+\ttest_expect_success \"$command: added submodule creates empty directory\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to no_submodule &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t add_sub1 origin/add_sub1 &&\n+\t\t\t$command add_sub1 &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_dir_is_empty sub1 &&\n+\t\t\tgit submodule update --init --recursive &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# ... and doesn't care if it already exists ...\n+\ttest_expect_success \"$command: added submodule leaves existing empty directory alone\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to no_submodule &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t add_sub1 origin/add_sub1 &&\n+\t\t\tmkdir sub1 &&\n+\t\t\t$command add_sub1 &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_dir_is_empty sub1 &&\n+\t\t\tgit submodule update --init --recursive &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# ... unless there is an untracked file in its place.\n+\ttest_expect_success \"$command: added submodule does remove untracked unignored file with same name when forced\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to no_submodule &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t add_sub1 origin/add_sub1 &&\n+\t\t\techo -n >sub1 &&\n+\t\t\t$command add_sub1 &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_dir_is_empty sub1\n+\t\t)\n+\t'\n+\t# Replacing a tracked file with a submodule produces an empty\n+\t# directory ...\n+\ttest_expect_success \"$command: replace tracked file with submodule creates empty directory\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to replace_sub1_with_file &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_file_with_sub1 origin/replace_file_with_sub1 &&\n+\t\t\t$command replace_file_with_sub1 &&\n+\t\t\ttest_superproject_content origin/replace_file_with_sub1 &&\n+\t\t\ttest_dir_is_empty sub1 &&\n+\t\t\tgit submodule update --init --recursive &&\n+\t\t\ttest_submodule_content sub1 origin/replace_file_with_sub1\n+\t\t)\n+\t'\n+\t# ... as does removing a directory with tracked files with a\n+\t# submodule.\n+\ttest_expect_success \"$command: replace directory with submodule\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to replace_sub1_with_directory &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_directory_with_sub1 origin/replace_directory_with_sub1 &&\n+\t\t\t$command replace_directory_with_sub1 &&\n+\t\t\ttest_superproject_content origin/replace_directory_with_sub1 &&\n+\t\t\ttest_dir_is_empty sub1 &&\n+\t\t\tgit submodule update --init --recursive &&\n+\t\t\ttest_submodule_content sub1 origin/replace_directory_with_sub1\n+\t\t)\n+\t'\n+\n+\t######################## Disappearing submodule #######################\n+\t# Removing a submodule doesn't remove its work tree ...\n+\ttest_expect_success \"$command: removed submodule leaves submodule directory and its contents in place\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t remove_sub1 origin/remove_sub1 &&\n+\t\t\t$command remove_sub1 &&\n+\t\t\ttest_superproject_content origin/remove_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# ... especially when it contains a .git directory.\n+\ttest_expect_success \"$command: removed submodule leaves submodule containing a .git directory alone\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t remove_sub1 origin/remove_sub1 &&\n+\t\t\treplace_gitfile_with_git_dir sub1 &&\n+\t\t\t$command remove_sub1 &&\n+\t\t\ttest_superproject_content origin/remove_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1 &&\n+\t\t\ttest_git_directory_is_unchanged sub1\n+\t\t)\n+\t'\n+\t# Replacing a submodule with files in a directory must fail as the\n+\t# submodule work tree isn't removed ...\n+\ttest_expect_failure \"$command: replace submodule with a directory fails\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&\n+\t\t\ttest_must_fail $command replace_sub1_with_directory &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# ... especially when it contains a .git directory.\n+\ttest_expect_failure \"$command: replace submodule containing a .git directory with a directory fails\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_sub1_with_directory origin/replace_sub1_with_directory &&\n+\t\t\treplace_gitfile_with_git_dir sub1 &&\n+\t\t\ttest_must_fail $command replace_sub1_with_directory &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1 &&\n+\t\t\ttest_git_directory_is_unchanged sub1\n+\t\t)\n+\t'\n+\t# Replacing it with a file must fail as it could throw away any local\n+\t# work tree changes ...\n+\ttest_expect_failure \"$command: replace submodule directory with a file must fail\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_sub1_with_file origin/replace_sub1_with_file &&\n+\t\t\ttest_must_fail $command replace_sub1_with_file &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# ... or even destroy unpushed parts of submodule history if that\n+\t# still uses a .git directory.\n+\ttest_expect_failure \"$command: replace submodule directory with a file must fail\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t replace_sub1_with_file origin/replace_sub1_with_file &&\n+\t\t\treplace_gitfile_with_git_dir sub1 &&\n+\t\t\ttest_must_fail $command replace_sub1_with_file &&\n+\t\t\ttest_superproject_content origin/add_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1 &&\n+\t\t\ttest_git_directory_is_unchanged sub1\n+\t\t)\n+\t'\n+\n+\t########################## Modified submodule #########################\n+\t# Updating a submodule sha1 doesn't update the submodule's work tree\n+\ttest_expect_success \"$command: modified submodule does not update submodule work tree\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t modify_sub1 origin/modify_sub1 &&\n+\t\t\t$command modify_sub1 &&\n+\t\t\ttest_superproject_content origin/modify_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1 &&\n+\t\t\tgit submodule update &&\n+\t\t\ttest_submodule_content sub1 origin/modify_sub1\n+\t\t)\n+\t'\n+\t# Updating a submodule to an invalid sha1 doesn't update the\n+\t# submodule's work tree, subsequent update will fail\n+\ttest_expect_success \"$command: modified submodule does not update submodule work tree to invalid commit\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to add_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t invalid_sub1 origin/invalid_sub1 &&\n+\t\t\t$command invalid_sub1 &&\n+\t\t\ttest_superproject_content origin/invalid_sub1 &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1 &&\n+\t\t\ttest_must_fail git submodule update &&\n+\t\t\ttest_submodule_content sub1 origin/add_sub1\n+\t\t)\n+\t'\n+\t# Updating a submodule from an invalid sha1 doesn't update the\n+\t# submodule's work tree, subsequent update will succeed\n+\ttest_expect_success \"$command: modified submodule does not update submodule work tree from invalid commit\" '\n+\t\tprolog &&\n+\t\treset_work_tree_to invalid_sub1 &&\n+\t\t(\n+\t\t\tcd submodule_update &&\n+\t\t\tgit branch -t valid_sub1 origin/valid_sub1 &&\n+\t\t\t$command valid_sub1 &&\n+\t\t\ttest_superproject_content origin/valid_sub1 &&\n+\t\t\ttest_dir_is_empty sub1 &&\n+\t\t\tgit submodule update --init --recursive &&\n+\t\t\ttest_submodule_content sub1 origin/valid_sub1\n+\t\t)\n+\t'\n+}\n-- \n1.9.1.327.g3d8d896\n"},{"id":"237668","messageId":"5331B763.10808@web.de","threadId":"36290","inReplyTo":"5331B6F6.60501@web.de","subject":"[RFC/PATCH 3/4] checkout: call the new submodule update test framework","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2014-03-25T17:05:39Z","receivedAt":"2014-03-25T17:05:39Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Test that the checkout command updates the work tree as expected with or\nwithout the '-f' flag.\n\nSigned-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n---\n\nI think this should explain how to use the framework with a single command\nand some options.\n\n t/t2013-checkout-submodule.sh | 5 +++++\n 1 file changed, 5 insertions(+)\n\ndiff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh\nindex 06b18f8..6847f75 100755\n--- a/t/t2013-checkout-submodule.sh\n+++ b/t/t2013-checkout-submodule.sh\n@@ -3,6 +3,7 @@\n test_description='checkout can handle submodules'\n\n . ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-submodule-update.sh\n\n test_expect_success 'setup' '\n \tmkdir submodule &&\n@@ -62,4 +63,8 @@ test_expect_success '\"checkout <submodule>\" honors submodule.*.ignore from .git/\n \t! test -s actual\n '\n\n+test_submodule_switch \"git checkout\"\n+\n+test_submodule_forced_switch \"git checkout -f\"\n+\n test_done\n-- \n1.9.1.327.g3d8d896\n"},{"id":"237670","messageId":"5331B779.3050306@web.de","threadId":"36290","inReplyTo":"5331B6F6.60501@web.de","subject":"[RFC/PATCH 4/4] apply: add t4137 for submodule updates","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2014-03-25T17:06:01Z","receivedAt":"2014-03-25T17:06:01Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Test that the apply command updates the work tree as expected for the\n'--index' and the '--3way' options (for submodule changes which don't\nresult in conflicts).\n\nSigned-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n---\n\nAnd this shows how to use the new framework when more than a single command\nis needed to switch to a new work tree.\n\n t/t4137-apply-submodule.sh | 20 ++++++++++++++++++++\n 1 file changed, 20 insertions(+)\n create mode 100755 t/t4137-apply-submodule.sh\n\ndiff --git a/t/t4137-apply-submodule.sh b/t/t4137-apply-submodule.sh\nnew file mode 100755\nindex 0000000..f0a0500\n--- /dev/null\n+++ b/t/t4137-apply-submodule.sh\n@@ -0,0 +1,20 @@\n+#!/bin/sh\n+\n+test_description='git am handling submodules'\n+\n+. ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-submodule-update.sh\n+\n+apply_index () {\n+    git diff --ignore-submodules=dirty \"..$1\" | git apply --index -\n+}\n+\n+test_submodule_switch \"apply_index\"\n+\n+apply_3way () {\n+    git diff --ignore-submodules=dirty \"..$1\" | git apply --3way -\n+}\n+\n+test_submodule_switch \"apply_3way\"\n+\n+test_done\n-- \n1.9.1.327.g3d8d896\n"},{"id":"237774","messageId":"xmqq4n2mknqf.fsf@gitster.dls.corp.google.com","threadId":"36290","inReplyTo":"5331B717.5010600@web.de","subject":"Re: [RFC/PATCH 1/4] test-lib: add test_dir_is_empty()","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-25T20:49:28Z","receivedAt":"2014-03-25T20:49:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jens Lehmann <Jens.Lehmann@web.de> writes:\n\n> For the upcoming submodule test framework we often need to assert that an\n> empty directory exists in the work tree. Add the test_dir_is_empty()\n> function which asserts that the given argument is an empty directory.\n>\n> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n> ---\n>\n> I believe this one is pretty straightforward (unless I missed that this\n> functionality already exists someplace I forgot to look ;-).\n\nI am not very thrilled to see that it depends on \".\" and \"..\" to\nalways exist, which may be true for all POSIX filesystems, but\nstill...\n\nDo expected callsites of this helper care if \"$1\" is a symbolic link\nthat points at an empty directory?\n\nWhat do expected callsites really want to ensure?  In other words,\nwhy do they care if the directory is empty?  Is it to make sure,\nafter some operation, they can \"rmdir\" the directory?\n\n>  t/test-lib-functions.sh | 11 +++++++++++\n>  1 file changed, 11 insertions(+)\n>\n> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n> index 158e10a..93d10cd 100644\n> --- a/t/test-lib-functions.sh\n> +++ b/t/test-lib-functions.sh\n> @@ -489,6 +489,17 @@ test_path_is_dir () {\n>  \tfi\n>  }\n>\n> +# Check if the directory exists and is empty as expected, barf otherwise.\n> +test_dir_is_empty () {\n> +\ttest_path_is_dir \"$1\" &&\n> +\tif test $(ls -a1 \"$1\" | wc -l) != 2\n> +\tthen\n> +\t\techo \"Directory '$1' is not empty, it contains:\"\n> +\t\tls -la \"$1\"\n> +\t\treturn 1\n> +\tfi\n> +}\n> +\n>  test_path_is_missing () {\n>  \tif [ -e \"$1\" ]\n>  \tthen\n"},{"id":"237797","messageId":"87y4zyt2cj.fsf@fencepost.gnu.org","threadId":"36290","inReplyTo":"xmqq4n2mknqf.fsf@gitster.dls.corp.google.com","subject":"Re: [RFC/PATCH 1/4] test-lib: add test_dir_is_empty()","fromName":"David Kastrup","fromEmail":"dak@gnu.org","sentAt":"2014-03-25T21:06:36Z","receivedAt":"2014-03-25T21:06:36Z","isPatch":true,"sender":{"key":"dak@gnu.org","avatar":"https://avatars.githubusercontent.com/u/52141349?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Jens Lehmann <Jens.Lehmann@web.de> writes:\n>\n>> For the upcoming submodule test framework we often need to assert that an\n>> empty directory exists in the work tree. Add the test_dir_is_empty()\n>> function which asserts that the given argument is an empty directory.\n>>\n>> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n>> ---\n>>\n>> I believe this one is pretty straightforward (unless I missed that this\n>> functionality already exists someplace I forgot to look ;-).\n>\n> I am not very thrilled to see that it depends on \".\" and \"..\" to\n> always exist, which may be true for all POSIX filesystems, but\n> still...\n\nNot even there, though few people will likely use / as their work\ntree...\n\n-- \nDavid Kastrup\n"},{"id":"237790","messageId":"53328FD8.4050907@web.de","threadId":"36290","inReplyTo":"xmqq4n2mknqf.fsf@gitster.dls.corp.google.com","subject":"Re: [RFC/PATCH 1/4] test-lib: add test_dir_is_empty()","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2014-03-26T08:29:12Z","receivedAt":"2014-03-26T08:29:12Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 25.03.2014 21:49, schrieb Junio C Hamano:\n> Jens Lehmann <Jens.Lehmann@web.de> writes:\n> \n>> For the upcoming submodule test framework we often need to assert that an\n>> empty directory exists in the work tree. Add the test_dir_is_empty()\n>> function which asserts that the given argument is an empty directory.\n>>\n>> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n>> ---\n>>\n>> I believe this one is pretty straightforward (unless I missed that this\n>> functionality already exists someplace I forgot to look ;-).\n> \n> I am not very thrilled to see that it depends on \".\" and \"..\" to\n> always exist, which may be true for all POSIX filesystems, but\n> still...\n\nAgreed. I didn't find any one-liners to do that (\"ls -A\" isn't\nPOSIX), so I decided to wrap that in a function. Testing that\n\"rmdir\" on the directory succeeds (because the directory is\nempty) would kinda work, but then we'd have to re-create the\ndirectory afterwards, which really doesn't sound like a good\nstrategy either as the test would manipulate the to-be-tested\nobject. I'm not terribly happy with depending on \".\" and \"..\"\neither, but couldn't come up with something better. At least\nthe test should fail for any filesystem not having the dot\nfiles ...\n\n> Do expected callsites of this helper care if \"$1\" is a symbolic link\n> that points at an empty directory?\n\nYep, a symbolic link pointing to an empty directory should make\nthe test fail.\n\n> What do expected callsites really want to ensure?  In other words,\n> why do they care if the directory is empty?  Is it to make sure,\n> after some operation, they can \"rmdir\" the directory?\n\nTo assert that a submodule is created but *not* populated. This\nis intended to catch any possible fallout from the recursive\ncheckout later, in case that would kick in when it shouldn't.\n\n>>  t/test-lib-functions.sh | 11 +++++++++++\n>>  1 file changed, 11 insertions(+)\n>>\n>> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n>> index 158e10a..93d10cd 100644\n>> --- a/t/test-lib-functions.sh\n>> +++ b/t/test-lib-functions.sh\n>> @@ -489,6 +489,17 @@ test_path_is_dir () {\n>>  \tfi\n>>  }\n>>\n>> +# Check if the directory exists and is empty as expected, barf otherwise.\n>> +test_dir_is_empty () {\n>> +\ttest_path_is_dir \"$1\" &&\n>> +\tif test $(ls -a1 \"$1\" | wc -l) != 2\n>> +\tthen\n>> +\t\techo \"Directory '$1' is not empty, it contains:\"\n>> +\t\tls -la \"$1\"\n>> +\t\treturn 1\n>> +\tfi\n>> +}\n>> +\n>>  test_path_is_missing () {\n>>  \tif [ -e \"$1\" ]\n>>  \tthen\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n> \n"},{"id":"237794","messageId":"5332AF6B.1050108@alum.mit.edu","threadId":"36290","inReplyTo":"53328FD8.4050907@web.de","subject":"Re: [RFC/PATCH 1/4] test-lib: add test_dir_is_empty()","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2014-03-26T10:43:55Z","receivedAt":"2014-03-26T10:43:55Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 03/26/2014 09:29 AM, Jens Lehmann wrote:\n> Am 25.03.2014 21:49, schrieb Junio C Hamano:\n>> Jens Lehmann <Jens.Lehmann@web.de> writes:\n>>\n>>> For the upcoming submodule test framework we often need to assert that an\n>>> empty directory exists in the work tree. Add the test_dir_is_empty()\n>>> function which asserts that the given argument is an empty directory.\n>>>\n>>> Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>\n>>> ---\n>>>\n>>> I believe this one is pretty straightforward (unless I missed that this\n>>> functionality already exists someplace I forgot to look ;-).\n>>\n>> I am not very thrilled to see that it depends on \".\" and \"..\" to\n>> always exist, which may be true for all POSIX filesystems, but\n>> still...\n> \n> Agreed. I didn't find any one-liners to do that (\"ls -A\" isn't\n> POSIX), so I decided to wrap that in a function. Testing that\n> \"rmdir\" on the directory succeeds (because the directory is\n> empty) would kinda work, but then we'd have to re-create the\n> directory afterwards, which really doesn't sound like a good\n> strategy either as the test would manipulate the to-be-tested\n> object. I'm not terribly happy with depending on \".\" and \"..\"\n> either, but couldn't come up with something better. At least\n> the test should fail for any filesystem not having the dot\n> files ...\n> \n>> Do expected callsites of this helper care if \"$1\" is a symbolic link\n>> that points at an empty directory?\n> \n> Yep, a symbolic link pointing to an empty directory should make\n> the test fail.\n> \n>> What do expected callsites really want to ensure?  In other words,\n>> why do they care if the directory is empty?  Is it to make sure,\n>> after some operation, they can \"rmdir\" the directory?\n> \n> To assert that a submodule is created but *not* populated. This\n> is intended to catch any possible fallout from the recursive\n> checkout later, in case that would kick in when it shouldn't.\n> \n>>>  t/test-lib-functions.sh | 11 +++++++++++\n>>>  1 file changed, 11 insertions(+)\n>>>\n>>> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n>>> index 158e10a..93d10cd 100644\n>>> --- a/t/test-lib-functions.sh\n>>> +++ b/t/test-lib-functions.sh\n>>> @@ -489,6 +489,17 @@ test_path_is_dir () {\n>>>  \tfi\n>>>  }\n>>>\n>>> +# Check if the directory exists and is empty as expected, barf otherwise.\n>>> +test_dir_is_empty () {\n>>> +\ttest_path_is_dir \"$1\" &&\n>>> +\tif test $(ls -a1 \"$1\" | wc -l) != 2\n>>> +\tthen\n>>> +\t\techo \"Directory '$1' is not empty, it contains:\"\n>>> +\t\tls -la \"$1\"\n>>> +\t\treturn 1\n>>> +\tfi\n>>> +}\n>>> +\n>>>  test_path_is_missing () {\n>>>  \tif [ -e \"$1\" ]\n>>>  \tthen\n\nWhy not do something like\n\n    test -z \"$(ls -a1 \"$1\" | egrep -v '^\\.\\.?$')\"\n\nI.e., make the test ignore \".\" and \"..\" without depending on their\nexistence?\n\nMichael\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\nhttp://softwareswirl.blogspot.com/\n"},{"id":"237836","messageId":"53332905.2050808@web.de","threadId":"36290","inReplyTo":"5332AF6B.1050108@alum.mit.edu","subject":"Re: [RFC/PATCH 1/4] test-lib: add test_dir_is_empty()","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2014-03-26T19:22:45Z","receivedAt":"2014-03-26T19:22:45Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 26.03.2014 11:43, schrieb Michael Haggerty:\n> On 03/26/2014 09:29 AM, Jens Lehmann wrote:\n>> Am 25.03.2014 21:49, schrieb Junio C Hamano:\n>>> Jens Lehmann <Jens.Lehmann@web.de> writes:\n>>>>  t/test-lib-functions.sh | 11 +++++++++++\n>>>>  1 file changed, 11 insertions(+)\n>>>>\n>>>> diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh\n>>>> index 158e10a..93d10cd 100644\n>>>> --- a/t/test-lib-functions.sh\n>>>> +++ b/t/test-lib-functions.sh\n>>>> @@ -489,6 +489,17 @@ test_path_is_dir () {\n>>>>  \tfi\n>>>>  }\n>>>>\n>>>> +# Check if the directory exists and is empty as expected, barf otherwise.\n>>>> +test_dir_is_empty () {\n>>>> +\ttest_path_is_dir \"$1\" &&\n>>>> +\tif test $(ls -a1 \"$1\" | wc -l) != 2\n>>>> +\tthen\n>>>> +\t\techo \"Directory '$1' is not empty, it contains:\"\n>>>> +\t\tls -la \"$1\"\n>>>> +\t\treturn 1\n>>>> +\tfi\n>>>> +}\n>>>> +\n>>>>  test_path_is_missing () {\n>>>>  \tif [ -e \"$1\" ]\n>>>>  \tthen\n> \n> Why not do something like\n> \n>     test -z \"$(ls -a1 \"$1\" | egrep -v '^\\.\\.?$')\"\n> \n> I.e., make the test ignore \".\" and \"..\" without depending on their\n> existence?\n\nThanks, will do so in the next round.\n"},{"id":"239019","messageId":"20140417164138.GP21805@odin.tremily.us","threadId":"36290","inReplyTo":"5331B741.6000606@web.de","subject":"Re: [RFC/PATCH 2/4] Submodules: Add the lib-submodule-update.sh test library","fromName":"W. Trevor King","fromEmail":"wking@tremily.us","sentAt":"2014-04-17T16:41:38Z","receivedAt":"2014-04-17T16:41:38Z","isPatch":true,"sender":{"key":"wking@tremily.us","avatar":"https://avatars.githubusercontent.com/u/209920?v=4"},"body":"On Tue, Mar 25, 2014 at 06:05:05PM +0100, Jens Lehmann wrote:\n> *) When a submodule is replaced with a tracked file of the same name\n>    the submodule work tree including any local modifications (and\n>    even the whole history if it uses a .git directory instead of a\n>    gitfile!) is simply removed.\n> …\n> I think the first bug really needs to be fixed, as that behavior is\n> extremely nasty. We should always protect work tree modifications\n> (unless forced) and *never* remove a .git directory (even when\n> forced).\n\nI think this should be covered by the usual “don't allow checkouts\nfrom dirty workdirs unless the dirty-ing changes are easily applied to\nthe target tree”.\n\nAre we waiting to land this series (or a successor) before starting on\na fix for this issue?  There have been a number of submodule series in\nflight recently, and I'm having trouble keeping track of them all ;).\n\n> *) Forced work tree updates happily manipulate files in the\n>    directory of a submodule that has just been removed in the\n>    superproject (but is of course still present in the work tree due\n>    to the way submodules are currently handled). This becomes\n>    dangerous when files in the submodule directory are overwritten\n>    by files from the new superproject commit, as any modifications\n>    to the submodule files will be lost) and is expected to also\n>    destroy history in the - admittedly unlikely case - the new\n>    commit adds a file named \".git\" to the submodule directory.\n> …\n> I'm not so sure about the second one. Even though I believe the\n> current behavior is not correct (switching commits should never mess\n> around in a submodule directory)\n\nThis should also be covered by the usual “don't allow checkouts from\ndirty workdirs unless the dirty-ing changes are easily applied to the\ntarget tree”.  We don't implement this yet, but I'd like to force\nusers to move any about-to-be-clobbered state from their submodule\ninto .git/modules/<name>/ (via commits or stashes) before allowing\nthem to begin the checkout.  Once we've ensured that the state is\npreserved out-of-tree, then clobber away ;).\n\nCheers,\nTrevor\n\n-- \nThis email may be signed or encrypted with GnuPG (http://www.gnupg.org).\nFor more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy\n"},{"id":"239033","messageId":"xmqq38hbep5v.fsf@gitster.dls.corp.google.com","threadId":"36290","inReplyTo":"20140417164138.GP21805@odin.tremily.us","subject":"Re: [RFC/PATCH 2/4] Submodules: Add the lib-submodule-update.sh test library","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-04-17T19:23:08Z","receivedAt":"2014-04-17T19:23:08Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"W. Trevor King\" <wking@tremily.us> writes:\n\n> There have been a number of submodule series in\n> flight recently, and I'm having trouble keeping track of them all ;).\n\nUnfortunately I share that same feeling X-<.\n\nCould you guys collectively summarize what issues each of these\nin-flight topics try to address and how, how close it is to achieve\nconcensus, and how it interact with other proposed topics?\n\nThanks.\n"},{"id":"239049","messageId":"535042B6.7040800@web.de","threadId":"36290","inReplyTo":"20140417164138.GP21805@odin.tremily.us","subject":"Re: [RFC/PATCH 2/4] Submodules: Add the lib-submodule-update.sh test library","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2014-04-17T21:08:06Z","receivedAt":"2014-04-17T21:08:06Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 17.04.2014 18:41, schrieb W. Trevor King:\n> On Tue, Mar 25, 2014 at 06:05:05PM +0100, Jens Lehmann wrote:\n>> *) When a submodule is replaced with a tracked file of the same name\n>>    the submodule work tree including any local modifications (and\n>>    even the whole history if it uses a .git directory instead of a\n>>    gitfile!) is simply removed.\n>> …\n>> I think the first bug really needs to be fixed, as that behavior is\n>> extremely nasty. We should always protect work tree modifications\n>> (unless forced) and *never* remove a .git directory (even when\n>> forced).\n> \n> I think this should be covered by the usual “don't allow checkouts\n> from dirty workdirs unless the dirty-ing changes are easily applied to\n> the target tree”.\n\nNope, the target tree will be removed completely and everything in\nit is silently nuked. It should be allowed with '-f', but only if\nthe submodule contains a gitfile, and never if it contains a .git\ndirectory (which is just what we do for rm too).\n\n> Are we waiting to land this series (or a successor) before starting on\n> a fix for this issue?\n\nI think so, as this bug is there for a long time (so I see no urge\nto fix it very soon) and my test harness is intended to document\nthis current bug (and then soon its fix).\n\n>> *) Forced work tree updates happily manipulate files in the\n>>    directory of a submodule that has just been removed in the\n>>    superproject (but is of course still present in the work tree due\n>>    to the way submodules are currently handled). This becomes\n>>    dangerous when files in the submodule directory are overwritten\n>>    by files from the new superproject commit, as any modifications\n>>    to the submodule files will be lost) and is expected to also\n>>    destroy history in the - admittedly unlikely case - the new\n>>    commit adds a file named \".git\" to the submodule directory.\n>> …\n>> I'm not so sure about the second one. Even though I believe the\n>> current behavior is not correct (switching commits should never mess\n>> around in a submodule directory)\n> \n> This should also be covered by the usual “don't allow checkouts from\n> dirty workdirs unless the dirty-ing changes are easily applied to the\n> target tree”.  We don't implement this yet, but I'd like to force\n> users to move any about-to-be-clobbered state from their submodule\n> into .git/modules/<name>/ (via commits or stashes) before allowing\n> them to begin the checkout.  Once we've ensured that the state is\n> preserved out-of-tree, then clobber away ;).\n\nI'm intending to fix this in the recursive checkout series, as I'm\na) not sure if any users currently depend on that for a submodule\nto directory transition and b) recursive checkout is the place to\nconsistently care about submodule modifications (the submodule\nscript doesn't do that and it is impossible to change that without\ncausing trouble to a lot of users.\n"},{"id":"239051","messageId":"535047DC.2000809@web.de","threadId":"36290","inReplyTo":"xmqq38hbep5v.fsf@gitster.dls.corp.google.com","subject":"Re: [RFC/PATCH 2/4] Submodules: Add the lib-submodule-update.sh test library","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2014-04-17T21:30:04Z","receivedAt":"2014-04-17T21:30:04Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 17.04.2014 21:23, schrieb Junio C Hamano:\n> \"W. Trevor King\" <wking@tremily.us> writes:\n> \n>> There have been a number of submodule series in\n>> flight recently, and I'm having trouble keeping track of them all ;).\n> \n> Unfortunately I share that same feeling X-<.\n> \n> Could you guys collectively summarize what issues each of these\n> in-flight topics try to address and how, how close it is to achieve\n> concensus, and how it interact with other proposed topics?\n\nI'm aware of these topics:\n\n- My 4 \"Never ignore staged but ignored submodules\" patches\n\n  I recall that everyone agreed that this is a good change.\n\n- Johan's \"Test various 'git submodule update' scenarios\"\n\n  Intended to document current behavior of the submodule.<name>.branch\n  setting (and others) as a starting point for a discussion of how\n  that could (and should) evolve. Needs some cooking.\n\n- My \"submodule test harness\" RFC series (currently 14 patches)\n\n  Similar to Johan's patch I try to document the current behavior\n  of Git, but with the focus on all work tree manipulating commands\n  (not only 'submodule update' handling all submodule changes. Will\n  send to the list again when I resolved the last outstanding issues,\n  current state can be seen in the submodule-test-harness branch of\n  my GitHub repo. My next to-be-finished topic.\n\n- Ronald's two \"Teach add and commit the --ignore-submodules option\"\n  options\n\n  Will review v4 soonish, looking good from the first cursory look.\n\n- My \"recursive submodule checkout\" series\n\n  Needs to be rerolled, I intend to extend my \"submodule test harness\"\n  to cover all relevant scenarios for this series.\n\n- Heiko's \"config cache for submodules\" patch\n\n  Needed for my recursive checkout series to populate new submodules.\n\nAnd then a not yet surfaced \"do not replace submodules with a file\"\nfix I intend to send between the \"submodule test harness\" and the\n\"recursive submodule checkout\" series.\n\nHope that makes it clearer ;-)\n"},{"id":"239054","messageId":"20140417215531.GY21805@odin.tremily.us","threadId":"36290","inReplyTo":"535042B6.7040800@web.de","subject":"Re: [RFC/PATCH 2/4] Submodules: Add the lib-submodule-update.sh test library","fromName":"W. Trevor King","fromEmail":"wking@tremily.us","sentAt":"2014-04-17T21:55:31Z","receivedAt":"2014-04-17T21:55:31Z","isPatch":true,"sender":{"key":"wking@tremily.us","avatar":"https://avatars.githubusercontent.com/u/209920?v=4"},"body":"On Thu, Apr 17, 2014 at 11:08:06PM +0200, Jens Lehmann wrote:\n> Am 17.04.2014 18:41, schrieb W. Trevor King:\n> > On Tue, Mar 25, 2014 at 06:05:05PM +0100, Jens Lehmann wrote:\n> >> *) When a submodule is replaced with a tracked file of the same name\n> >>    the submodule work tree including any local modifications (and\n> >>    even the whole history if it uses a .git directory instead of a\n> >>    gitfile!) is simply removed.\n> >> …\n> >> I think the first bug really needs to be fixed, as that behavior is\n> >> extremely nasty. We should always protect work tree modifications\n> >> (unless forced) and *never* remove a .git directory (even when\n> >> forced).\n> > \n> > I think this should be covered by the usual “don't allow checkouts\n> > from dirty workdirs unless the dirty-ing changes are easily applied to\n> > the target tree”.\n> \n> Nope, the target tree will be removed completely and everything in\n> it is silently nuked. It should be allowed with '-f', but only if\n> the submodule contains a gitfile, and never if it contains a .git\n> directory (which is just what we do for rm too).\n\nI think it's not covered *now* because of a flaw in our “are dirty-ing\nchanges easily applied to the target tree” detection logic, and the\nsolution should involve updating that logic to hit on this case.\n\n> b) recursive checkout is the place to consistently care about\n> submodule modifications (the submodule script doesn't do that and it\n> is impossible to change that without causing trouble to a lot of\n> users.\n\nI agree that the submodule script is not the place for this, and the\ncore checkout code is.  I'd like checkouts to always be recursive, and\nsee --[no-]recurse-submodules as a finger-breaking stop-gap until we\ncan complete that transition for checkout, bisect, merge, reset, and\nother work-tree altering commands.  I think this is one reason why\nsome folks prefer the stiffer joints you get from a subtree approach.\n\nCheers,\nTrevor\n\n-- \nThis email may be signed or encrypted with GnuPG (http://www.gnupg.org).\nFor more information, see http://en.wikipedia.org/wiki/Pretty_Good_Privacy\n"},{"id":"239066","messageId":"53511B09.1010700@web.de","threadId":"36290","inReplyTo":"20140417215531.GY21805@odin.tremily.us","subject":"Re: [RFC/PATCH 2/4] Submodules: Add the lib-submodule-update.sh test library","fromName":"Jens Lehmann","fromEmail":"jens.lehmann@web.de","sentAt":"2014-04-18T12:31:05Z","receivedAt":"2014-04-18T12:31:05Z","isPatch":true,"sender":{"key":"jens.lehmann@web.de","avatar":"https://avatars.githubusercontent.com/u/135220?v=4"},"body":"Am 17.04.2014 23:55, schrieb W. Trevor King:\n> On Thu, Apr 17, 2014 at 11:08:06PM +0200, Jens Lehmann wrote:\n>> Am 17.04.2014 18:41, schrieb W. Trevor King:\n>>> On Tue, Mar 25, 2014 at 06:05:05PM +0100, Jens Lehmann wrote:\n>>>> *) When a submodule is replaced with a tracked file of the same name\n>>>>    the submodule work tree including any local modifications (and\n>>>>    even the whole history if it uses a .git directory instead of a\n>>>>    gitfile!) is simply removed.\n>>>> …\n>>>> I think the first bug really needs to be fixed, as that behavior is\n>>>> extremely nasty. We should always protect work tree modifications\n>>>> (unless forced) and *never* remove a .git directory (even when\n>>>> forced).\n>>>\n>>> I think this should be covered by the usual “don't allow checkouts\n>>> from dirty workdirs unless the dirty-ing changes are easily applied to\n>>> the target tree”.\n>>\n>> Nope, the target tree will be removed completely and everything in\n>> it is silently nuked. It should be allowed with '-f', but only if\n>> the submodule contains a gitfile, and never if it contains a .git\n>> directory (which is just what we do for rm too).\n> \n> I think it's not covered *now* because of a flaw in our “are dirty-ing\n> changes easily applied to the target tree” detection logic, and the\n> solution should involve updating that logic to hit on this case.\n\nYup.\n\n>> b) recursive checkout is the place to consistently care about\n>> submodule modifications (the submodule script doesn't do that and it\n>> is impossible to change that without causing trouble to a lot of\n>> users.\n> \n> I agree that the submodule script is not the place for this, and the\n> core checkout code is.  I'd like checkouts to always be recursive, and\n> see --[no-]recurse-submodules as a finger-breaking stop-gap until we\n> can complete that transition for checkout, bisect, merge, reset, and\n> other work-tree altering commands.  I think this is one reason why\n> some folks prefer the stiffer joints you get from a subtree approach.\n\nWe are definitely in the same boat here :-)\n"},{"id":"239067","messageId":"20140418123918.GA4388@sandbox-ub","threadId":"36290","inReplyTo":"535047DC.2000809@web.de","subject":"Re: Re: [RFC/PATCH 2/4] Submodules: Add the lib-submodule-update.sh test library","fromName":"Heiko Voigt","fromEmail":"hvoigt@hvoigt.net","sentAt":"2014-04-18T12:39:18Z","receivedAt":"2014-04-18T12:39:18Z","isPatch":true,"sender":{"key":"hvoigt@hvoigt.net","avatar":"https://avatars.githubusercontent.com/u/184958?v=4"},"body":"On Thu, Apr 17, 2014 at 11:30:04PM +0200, Jens Lehmann wrote:\n> - Heiko's \"config cache for submodules\" patch\n> \n>   Needed for my recursive checkout series to populate new submodules.\n\nWhich will be followed by my recursive fetch series, which is also the\nlast part of what started with this:\n\nhttp://thread.gmane.org/gmane.comp.version-control.git/217018\n\nand is described here:\n\nhttps://github.com/hvoigt/git/wiki/submodule-fetch-config\n\nCheers Heiko\n"}]}