Add submodule test harness
cover Add submodule test harness
This is the series I sought feedback for some time ago in gmane/$245048. It took longer than I expected to finish this series because I had to diagnose the test failures I saw with some of the ten commands I added since then. They boiled down to four different inconsistencies in Git's handling of new or removed submodules. Sometimes no empty directory is created for a new submodule. stash and cherry-pick seem to use wrong submodule ignore settings ("all" instead of "dirty"), so they overlook submodule changes. And merge behaves strange when a submodule is removed, as it tries to merge new tracked files with those remaining from the submodule. This series only documents these issues (which most probably didn't cause any real world problems until now because adding and removing submodules wasn't well supported anyway).
The first patch adds a simple helper function to the test lib which makes it easier to test for an empty submodule directory.
The second patch contains the heavy lifting, it adds the test framework for switching submodules. Currently only transitions without merge conflicts are tested for, I intend to add others producing merge conflicts in a follow-up series.
The other twelve patches use the framework to test all relevant work tree manipulating commands. In addition to the two general problems documented in the second patch some patches add known failures for problems of some commands/actions to be fixed in later patches.
The only work tree changing command I didn't cover here is checkout-index, as that updates the work tree to the content of the index but doesn't remove any formerly tracked files, which means it doesn't do a full transition from one commit to another. If I overlooked another command, please speak up so I can include it too.
Jens Lehmann (14):
test-lib: add test_dir_is_empty()
submodules: Add the lib-submodule-update.sh test library
checkout: call the new submodule update test framework
apply: add t4137 for submodule updates
read-tree: add t1013 for submodule updates
reset: add t7112 for submodule updates
bisect: add t6041 for submodule updates
merge: add t7613 for submodule updates
rebase: add t3426 for submodule updates
pull: add t5572 for submodule updates
cherry-pick: add t3512 for submodule updates
am: add t4255 for submodule updates
stash: add t3906 for submodule updates
revert: add t3513 for submodule updates
t/lib-submodule-update.sh | 670 +++++++++++++++++++++++++++++++++++++++ t/t1013-read-tree-submodule.sh | 12 + t/t2013-checkout-submodule.sh | 5 + t/t3426-rebase-submodule.sh | 46 +++ t/t3512-cherry-pick-submodule.sh | 13 + t/t3513-revert-submodule.sh | 32 ++ t/t3906-stash-submodule.sh | 24 ++ t/t4137-apply-submodule.sh | 20 ++ t/t4255-am-submodule.sh | 21 ++ t/t5572-pull-submodule.sh | 74 +++++ t/t6041-bisect-submodule.sh | 32 ++ t/t7112-reset-submodule.sh | 14 + t/t7613-merge-submodule.sh | 19 ++ t/test-lib-functions.sh | 11 + 14 files changed, 993 insertions(+) create mode 100755 t/lib-submodule-update.sh create mode 100755 t/t1013-read-tree-submodule.sh create mode 100755 t/t3426-rebase-submodule.sh create mode 100755 t/t3512-cherry-pick-submodule.sh create mode 100755 t/t3513-revert-submodule.sh create mode 100755 t/t3906-stash-submodule.sh create mode 100755 t/t4137-apply-submodule.sh create mode 100755 t/t4255-am-submodule.sh create mode 100755 t/t5572-pull-submodule.sh create mode 100755 t/t6041-bisect-submodule.sh create mode 100755 t/t7112-reset-submodule.sh create mode 100755 t/t7613-merge-submodule.sh
Signature · 1 line
2.0.0.275.gc479268
PATCH 1/14 test-lib: add test_dir_is_empty()
For the upcoming submodule test framework we often need to assert that an empty directory exists in the work tree. Add the test_dir_is_empty() function which asserts that the given argument is an empty directory.
--- t/test-lib-functions.sh | 11 +++++++++++ 1 file changed, 11 insertions(+)
t/test-lib-functions.sh +11 -0
@@ -489,6 +489,17 @@ test_path_is_dir () { fi } +# Check if the directory exists and is empty as expected, barf otherwise. +test_dir_is_empty () { + test_path_is_dir "$1" && + if test "$(ls -a1 "$1" | egrep -v '^\.\.?$')" + then + echo "Directory '$1' is not empty, it contains:" + ls -la "$1" + return 1 + fi +} + test_path_is_missing () { if [ -e "$1" ] then
Signature · 1 line
2.0.0.275.gc479268
Re: [PATCH 01/14] test-lib: add test_dir_is_empty()
Quoted 14 lines · Jens Lehmann
For the upcoming submodule test framework we often need to assert that an empty directory exists in the work tree. Add the
test_dir_is_empty()function which asserts that the given argument is an empty directory.Signed-off-by Jens Lehmann <[email protected]>--- t/test-lib-functions.sh | 11 +++++++++++ 1 file changed, 11 insertions(+)t/test-lib-functions.sh +0
-0
t/test-lib-functions.sh test_path_is_dir () { · line 495
Quoted 7 lines
t/test-lib-functions.sh +4
-0@@ -489,6 +489,17 @@ test_path_is_dir () { fi } +# Check if the directory exists and is empty as expected, barf otherwise. +test_dir_is_empty () { + test_path_is_dir "$1" && + if test "$(ls -a1 "$1" | egrep -v '^\.\.?$')"
It is safer to say "test -n" when testing an emptyness of a string whose contents you do not know or control (e.g. the string may begin with "-something").
Quoted 10 lines
t/test-lib-functions.sh +7
-0+ then + echo "Directory '$1' is not empty, it contains:" + ls -la "$1" + return 1 + fi +} + test_path_is_missing () { if [ -e "$1" ] then
Re: [PATCH 01/14] test-lib: add test_dir_is_empty()
Am 17.06.2014 00:05, schrieb Junio C Hamano:
Quoted 19 lines
Quoted 17 lines · Jens Lehmann
For the upcoming submodule test framework we often need to assert that an empty directory exists in the work tree. Add the
test_dir_is_empty()function which asserts that the given argument is an empty directory.Signed-off-by Jens Lehmann <[email protected]>--- t/test-lib-functions.sh | 11 +++++++++++ 1 file changed, 11 insertions(+)t/test-lib-functions.sh +0
-0@@ -489,6 +489,17 @@ test_path_is_dir () { fi }
Quoted 8 lines
t/test-lib-functions.sh test_path_is_dir () { · line 495
Quoted 4 lines
t/test-lib-functions.sh +4
-0+# Check if the directory exists and is empty as expected, barf otherwise. +test_dir_is_empty () { + test_path_is_dir "$1" && + if test "$(ls -a1 "$1" | egrep -v '^\.\.?$')"It is safer to say "test -n" when testing an emptyness of a string whose contents you do not know or control (e.g. the string may begin with "-something").
Yup, will do so in v2.
Quoted 11 lines
Quoted 10 lines
t/test-lib-functions.sh +7
-0+ then + echo "Directory '$1' is not empty, it contains:" + ls -la "$1" + return 1 + fi +} + test_path_is_missing () { if [ -e "$1" ] then
PATCH v2 1/14 test-lib: add test_dir_is_empty()
In reply to Jens LehmannFor the upcoming submodule test framework we often need to assert that an empty directory exists in the work tree. Add the test_dir_is_empty() function which asserts that the given argument is an empty directory.
---
Changes to v1:
*) Added "-n" to test expression (you have this as "SQUASH???" commit in pu)
t/test-lib-functions.sh | 11 +++++++++++ 1 file changed, 11 insertions(+)
t/test-lib-functions.sh +11 -0
@@ -489,6 +489,17 @@ test_path_is_dir () { fi } +# Check if the directory exists and is empty as expected, barf otherwise. +test_dir_is_empty () { + test_path_is_dir "$1" && + if test -n "$(ls -a1 "$1" | egrep -v '^\.\.?$')" + then + echo "Directory '$1' is not empty, it contains:" + ls -la "$1" + return 1 + fi +} + test_path_is_missing () { if [ -e "$1" ] then
Signature · 1 line
2.0.0.406.gf4dce28
PATCH 2/14 submodules: Add the lib-submodule-update.sh test library
In reply to Jens LehmannAdd this test library to simplify covering all combinations of submodule update scenarios without having to add those to a test of each work tree manipulating command over and over again.
The functions test_submodule_switch() and test_submodule_forced_switch() are intended to be called from a test script with a single argument. This argument is either a work tree manipulating command (including any command line options) or a function (when more than a single git command is needed to switch work trees from the current HEAD to another commit). This command (or function) is passed a target branch as argument. The two new functions check that each submodule transition is handled as expected, which currently means that submodule work trees are not affected until "git submodule update" is called. The "forced" variant is for commands using their '-f' or '--hard' option and expects them to overwrite local modifications as a result. Each of these two functions contains 14 tests_expect_* calls.
Calling one of these test functions the first time creates a repository named "submodule_update_repo". At first it contains two files, then a single submodule is added in another commit followed by commits covering all relevant submodule modifications. This repository is newly cloned into the "submodule_update" for each test_expect_* to avoid interference between different parts of the test functions (some to-be-tested commands also manipulate refs along with the work tree, e.g. "git reset").
Follow-up commits will then call these two test functions for all work tree manipulating commands (with a combination of all their options relevant to what they do with the work tree) making sure they work as expected. Later this test library will be extended to cover merges resulting in conflicts too. Also it is intended to be easily extendable for the recursive update functionality, where even more combinations of submodule modifications have to be tested for.
This version documents two bugs in current Git with expected failures:
*) When a submodule is replaced with a tracked file of the same name the
submodule work tree including any local modifications (and even the whole history if it uses a .git directory instead of a gitfile!) is silently removed.
*) Forced work tree updates happily manipulate files in the directory of a
submodule that has just been removed in the superproject (but is of course still present in the work tree due to the way submodules are currently handled). This becomes dangerous when files in the submodule directory are overwritten by files from the new superproject commit, as any modifications to the submodule files will be lost) and is expected to also destroy history in the - admittedly unlikely case - the new commit adds a file named ".git" to the submodule directory.
--- t/lib-submodule-update.sh | 630 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 630 insertions(+) create mode 100755 t/lib-submodule-update.sh
t/lib-submodule-update.sh new file +630 -0
@@ -0,0 +1,630 @@ +# Create a submodule layout used for all tests below. +# +# The following use cases are covered: +# - New submodule (no_submodule => add_sub1) +# - Removed submodule (add_sub1 => remove_sub1) +# - Updated submodule (add_sub1 => modify_sub1) +# - Submodule updated to invalid commit (add_sub1 => invalid_sub1) +# - Submodule updated from invalid commit (invalid_sub1 => valid_sub1) +# - Submodule replaced by tracked files in directory (add_sub1 => +# replace_sub1_with_directory) +# - Directory containing tracked files replaced by submodule +# (replace_sub1_with_directory => replace_directory_with_sub1) +# - Submodule replaced by tracked file with the same name (add_sub1 => +# replace_sub1_with_file) +# - Tracked file replaced by submodule (replace_sub1_with_file => +# replace_file_with_sub1) +# +# --O-----O +# / ^ replace_directory_with_sub1 +# / replace_sub1_with_directory +# /----O +# / ^ +# / modify_sub1 +# O------O-------O +# ^ ^\ ^ +# | | \ remove_sub1 +# | | -----O-----O +# | | \ ^ replace_file_with_sub1 +# | | \ replace_sub1_with_file +# | add_sub1 --O-----O +# no_submodule ^ valid_sub1 +# invalid_sub1 +# +create_lib_submodule_repo () { + git init submodule_update_repo && + ( + cd submodule_update_repo && + echo "expect" >>.gitignore && + echo "actual" >>.gitignore && + echo "x" >file1 && + echo "y" >file2 && + git add .gitignore file1 file2 && + git commit -m "Base" && + git branch "no_submodule" && + + git checkout -b "add_sub1" && + git submodule add ./. sub1 && + git config -f .gitmodules submodule.sub1.ignore all && + git config submodule.sub1.ignore all && + git add .gitmodules && + git commit -m "Add sub1" && + git checkout -b remove_sub1 && + git revert HEAD && + + git checkout -b "modify_sub1" "add_sub1" && + git submodule update && + ( + cd sub1 && + git fetch && + git checkout -b "modifications" && + echo "z" >file2 && + echo "x" >file3 && + git add file2 file3 && + git commit -m "modified file2 and added file3" && + git push origin modifications + ) && + git add sub1 && + git commit -m "Modify sub1" && + + git checkout -b "replace_sub1_with_directory" "add_sub1" && + git submodule update && + ( + cd sub1 && + git checkout modifications + ) && + git rm --cached sub1 && + rm sub1/.git* && + git config -f .gitmodules --remove-section "submodule.sub1" && + git add .gitmodules sub1/* && + git commit -m "Replace sub1 with directory" && + git checkout -b replace_directory_with_sub1 && + git revert HEAD && + + git checkout -b "replace_sub1_with_file" "add_sub1" && + git rm sub1 && + echo "content" >sub1 && + git add sub1 && + git commit -m "Replace sub1 with file" && + git checkout -b replace_file_with_sub1 && + git revert HEAD && + + git checkout -b "invalid_sub1" "add_sub1" && + git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 sub1 && + git commit -m "Invalid sub1 commit" && + git checkout -b valid_sub1 && + git revert HEAD && + git checkout master + ) +} + +# Helper function to replace gitfile with .git directory +replace_gitfile_with_git_dir () { + ( + cd "$1" && + git_dir="$(git rev-parse --git-dir)" && + rm -f .git && + cp -a "$git_dir" .git && + GIT_WORK_TREE=. git config --unset core.worktree + ) +} + +# Test that the .git directory in the submodule is unchanged (except for the +# core.worktree setting) +test_git_directory_is_unchanged () { + ( + cd "$1" && + git config core.worktree "../../../$1" + ) && + git diff -r ".git/modules/$1" "$1/.git" && + ( + cd "$1" && + GIT_WORK_TREE=. git config --unset core.worktree + ) +} + +# Helper function to be executed at the start of every test below, it sets up +# the submodule repo if it doesn't exist and configures the most problematic +# settings for diff.ignoreSubmodules. +prolog () { + (test -d submodule_update_repo || create_lib_submodule_repo) && + test_config_global diff.ignoreSubmodules all && + test_config diff.ignoreSubmodules all +} + +# Helper function to bring work tree back into the state given by the +# commit. This includes trying to populate sub1 accordingly if it exists and +# should be updated to an existing commit. +reset_work_tree_to () { + rm -rf submodule_update && + git clone submodule_update_repo submodule_update && + ( + cd submodule_update && + rm -rf sub1 && + git checkout -f "$1" && + git status -u -s >actual && + test_must_be_empty actual && + sha1=$(git ls-tree HEAD "sub1" 2>/dev/null | grep 160000 | tr '\t' ' ' | cut -d ' ' -f3) && + if test -n "$sha1" && + test $(cd "sub1" && git rev-parse --verify "$sha1^{commit}") + then + git submodule update --init --recursive "sub1" + fi + ) +} + +# Test that the superproject contains the content according to commit "$1" +# (the work tree must match the index for everything but submodules but the +# index must exactly match the given commit including any submodule SHA-1s). +test_superproject_content () { + git diff-index --cached "$1" >actual && + test_must_be_empty actual && + git diff-files --ignore-submodules >actual && + test_must_be_empty actual +} + +# Test that the given submodule at path "$1" contains the content according +# to the submodule commit recorded in the superproject's commit "$2" +test_submodule_content () { + if test $# != 2 + then + echo "test_submodule_content needs two arguments" + return 1 + fi && + submodule="$1" && + commit="$2" && + test -d "$submodule"/ && + if ! test -f "$submodule"/.git && ! test -d "$submodule"/.git + then + echo "Submodule $submodule is not populated" + return 1 + fi && + sha1=$(git ls-tree "$commit" "$submodule" 2>/dev/null | tr '\t' ' ' | cut -d ' ' -f3) && + if test -z "$sha1" + then + echo "Couldn't retrieve SHA-1 of $submodule for $commit" + return 1 + fi && + ( + cd "$submodule" && + git status -u -s >actual && + test_must_be_empty actual && + git diff "$sha1" >actual && + test_must_be_empty actual + ) +} + +# Test that the following transitions are correctly handled: +# - Updated submodule +# - New submodule +# - Removed submodule +# - Directory containing tracked files replaced by submodule +# - Submodule replaced by tracked files in directory +# - Submodule replaced by tracked file with the same name +# - tracked file replaced by submodule +# +# The default is that submodule contents aren't changed until "git submodule +# update" is run. And even then that command doesn't delete the work tree of +# a removed submodule. +# +# Removing a submodule containing a .git directory must fail even when forced +# to protect the history! +# + +# Test that submodule contents are currently not updated when switching +# between commits that change a submodule. +test_submodule_switch () { + command="$1" + ######################### Appearing submodule ######################### + # Switching to a commit letting a submodule appear creates empty dir ... + test_expect_success "$command: added submodule creates empty directory" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... and doesn't care if it already exists ... + test_expect_success "$command: added submodule leaves existing empty directory alone" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + mkdir sub1 && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... unless there is an untracked file in its place. + test_expect_success "$command: added submodule doesn't remove untracked unignored file with same name" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + echo -n >sub1 && + test_must_fail $command add_sub1 && + test_superproject_content origin/no_submodule && + test_must_be_empty sub1 + ) + ' + # Replacing a tracked file with a submodule produces an empty + # directory ... + test_expect_success "$command: replace tracked file with submodule creates empty directory" ' + prolog && + reset_work_tree_to replace_sub1_with_file && + ( + cd submodule_update && + git branch -t replace_file_with_sub1 origin/replace_file_with_sub1 && + $command replace_file_with_sub1 && + test_superproject_content origin/replace_file_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_file_with_sub1 + ) + ' + # ... as does removing a directory with tracked files with a + # submodule. + test_expect_success "$command: replace directory with submodule" ' + prolog && + reset_work_tree_to replace_sub1_with_directory && + ( + cd submodule_update && + git branch -t replace_directory_with_sub1 origin/replace_directory_with_sub1 && + $command replace_directory_with_sub1 && + test_superproject_content origin/replace_directory_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_directory_with_sub1 + ) + ' + + ######################## Disappearing submodule ####################### + # Removing a submodule doesn't remove its work tree ... + test_expect_success "$command: removed submodule leaves submodule directory and its contents in place" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_success "$command: removed submodule leaves submodule containing a .git directory alone" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + replace_gitfile_with_git_dir sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_git_directory_is_unchanged sub1 + ) + ' + # Replacing a submodule with files in a directory must fail as the + # submodule work tree isn't removed ... + test_expect_success "$command: replace submodule with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_success "$command: replace submodule containing a .git directory with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_git_directory_is_unchanged sub1 + ) + ' + # Replacing it with a file must fail as it could throw away any local + # work tree changes ... + test_expect_failure "$command: replace submodule with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... or even destroy unpushed parts of submodule history if that + # still uses a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_git_directory_is_unchanged sub1 + ) + ' + + ########################## Modified submodule ######################### + # Updating a submodule sha1 doesn't update the submodule's work tree + test_expect_success "$command: modified submodule does not update submodule work tree" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t modify_sub1 origin/modify_sub1 && + $command modify_sub1 && + test_superproject_content origin/modify_sub1 && + test_submodule_content sub1 origin/add_sub1 && + git submodule update && + test_submodule_content sub1 origin/modify_sub1 + ) + ' + + # Updating a submodule to an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will fail + test_expect_success "$command: modified submodule does not update submodule work tree to invalid commit" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t invalid_sub1 origin/invalid_sub1 && + $command invalid_sub1 && + test_superproject_content origin/invalid_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_must_fail git submodule update && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Updating a submodule from an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will succeed + test_expect_success "$command: modified submodule does not update submodule work tree from invalid commit" ' + prolog && + reset_work_tree_to invalid_sub1 && + ( + cd submodule_update && + git branch -t valid_sub1 origin/valid_sub1 && + $command valid_sub1 && + test_superproject_content origin/valid_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/valid_sub1 + ) + ' +} + +# Test that submodule contents are currently not updated when switching +# between commits that change a submodule, but throwing away local changes in +# the superproject is allowed. +test_submodule_forced_switch () { + command="$1" + ######################### Appearing submodule ######################### + # Switching to a commit letting a submodule appear creates empty dir ... + test_expect_success "$command: added submodule creates empty directory" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... and doesn't care if it already exists ... + test_expect_success "$command: added submodule leaves existing empty directory alone" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + mkdir sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... unless there is an untracked file in its place. + test_expect_success "$command: added submodule does remove untracked unignored file with same name when forced" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + echo -n >sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 + ) + ' + # Replacing a tracked file with a submodule produces an empty + # directory ... + test_expect_success "$command: replace tracked file with submodule creates empty directory" ' + prolog && + reset_work_tree_to replace_sub1_with_file && + ( + cd submodule_update && + git branch -t replace_file_with_sub1 origin/replace_file_with_sub1 && + $command replace_file_with_sub1 && + test_superproject_content origin/replace_file_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_file_with_sub1 + ) + ' + # ... as does removing a directory with tracked files with a + # submodule. + test_expect_success "$command: replace directory with submodule" ' + prolog && + reset_work_tree_to replace_sub1_with_directory && + ( + cd submodule_update && + git branch -t replace_directory_with_sub1 origin/replace_directory_with_sub1 && + $command replace_directory_with_sub1 && + test_superproject_content origin/replace_directory_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_directory_with_sub1 + ) + ' + + ######################## Disappearing submodule ####################### + # Removing a submodule doesn't remove its work tree ... + test_expect_success "$command: removed submodule leaves submodule directory and its contents in place" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_success "$command: removed submodule leaves submodule containing a .git directory alone" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + replace_gitfile_with_git_dir sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_git_directory_is_unchanged sub1 + ) + ' + # Replacing a submodule with files in a directory must fail as the + # submodule work tree isn't removed ... + test_expect_failure "$command: replace submodule with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_git_directory_is_unchanged sub1 + ) + ' + # Replacing it with a file must fail as it could throw away any local + # work tree changes ... + test_expect_failure "$command: replace submodule with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... or even destroy unpushed parts of submodule history if that + # still uses a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_git_directory_is_unchanged sub1 + ) + ' + + ########################## Modified submodule ######################### + # Updating a submodule sha1 doesn't update the submodule's work tree + test_expect_success "$command: modified submodule does not update submodule work tree" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t modify_sub1 origin/modify_sub1 && + $command modify_sub1 && + test_superproject_content origin/modify_sub1 && + test_submodule_content sub1 origin/add_sub1 && + git submodule update && + test_submodule_content sub1 origin/modify_sub1 + ) + ' + # Updating a submodule to an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will fail + test_expect_success "$command: modified submodule does not update submodule work tree to invalid commit" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t invalid_sub1 origin/invalid_sub1 && + $command invalid_sub1 && + test_superproject_content origin/invalid_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_must_fail git submodule update && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Updating a submodule from an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will succeed + test_expect_success "$command: modified submodule does not update submodule work tree from invalid commit" ' + prolog && + reset_work_tree_to invalid_sub1 && + ( + cd submodule_update && + git branch -t valid_sub1 origin/valid_sub1 && + $command valid_sub1 && + test_superproject_content origin/valid_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/valid_sub1 + ) + ' +}
Signature · 1 line
2.0.0.275.gc479268
Re: [PATCH 02/14] submodules: Add the lib-submodule-update.sh test library
Quoted 98 lines · Jens Lehmann
Add this test library to simplify covering all combinations of submodule update scenarios without having to add those to a test of each work tree manipulating command over and over again.
The functions
test_submodule_switch()andtest_submodule_forced_switch()are intended to be called from a test script with a single argument. This argument is either a work tree manipulating command (including any command line options) or a function (when more than a single git command is needed to switch work trees from the current HEAD to another commit). This command (or function) is passed a target branch as argument. The two new functions check that each submodule transition is handled as expected, which currently means that submodule work trees are not affected until "git submodule update" is called. The "forced" variant is for commands using their '-f' or '--hard' option and expects them to overwrite local modifications as a result. Each of these two functions contains 14 tests_expect_* calls.Calling one of these test functions the first time creates a repository named "
submodule_update_repo". At first it contains two files, then a single submodule is added in another commit followed by commits covering all relevant submodule modifications. This repository is newly cloned into the "submodule_update" for each test_expect_* to avoid interference between different parts of the test functions (some to-be-tested commands also manipulate refs along with the work tree, e.g. "git reset").Follow-up commits will then call these two test functions for all work tree manipulating commands (with a combination of all their options relevant to what they do with the work tree) making sure they work as expected. Later this test library will be extended to cover merges resulting in conflicts too. Also it is intended to be easily extendable for the recursive update functionality, where even more combinations of submodule modifications have to be tested for.
This version documents two bugs in current Git with expected failures:
*) When a submodule is replaced with a tracked file of the same name the
submodule work tree including any local modifications (and even the whole history if it uses a .git directory instead of a gitfile!) is silently removed.*) Forced work tree updates happily manipulate files in the directory of a
submodule that has just been removed in the superproject (but is of course still present in the work tree due to the way submodules are currently handled). This becomes dangerous when files in the submodule directory are overwritten by files from the new superproject commit, as any modifications to the submodule files will be lost) and is expected to also destroy history in the - admittedly unlikely case - the new commit adds a file named ".git" to the submodule directory.Signed-off-by Jens Lehmann <[email protected]>--- t/lib-submodule-update.sh | 630 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 630 insertions(+) create mode 100755 t/lib-submodule-update.sht/lib-submodule-update.sh new file +37
-0@@ -0,0 +1,630 @@ +# Create a submodule layout used for all tests below. +# +# The following use cases are covered: +# - New submodule (no_submodule => add_sub1) +# - Removed submodule (add_sub1 => remove_sub1) +# - Updated submodule (add_sub1 => modify_sub1) +# - Submodule updated to invalid commit (add_sub1 => invalid_sub1) +# - Submodule updated from invalid commit (invalid_sub1 => valid_sub1) +# - Submodule replaced by tracked files in directory (add_sub1 => +# replace_sub1_with_directory) +# - Directory containing tracked files replaced by submodule +# (replace_sub1_with_directory => replace_directory_with_sub1) +# - Submodule replaced by tracked file with the same name (add_sub1 => +# replace_sub1_with_file) +# - Tracked file replaced by submodule (replace_sub1_with_file => +# replace_file_with_sub1) +# +# --O-----O +# / ^ replace_directory_with_sub1 +# / replace_sub1_with_directory +# /----O +# / ^ +# / modify_sub1 +# O------O-------O +# ^ ^\ ^ +# | | \ remove_sub1 +# | | -----O-----O +# | | \ ^ replace_file_with_sub1 +# | | \ replace_sub1_with_file +# | add_sub1 --O-----O +# no_submodule ^ valid_sub1 +# invalid_sub1 +# +create_lib_submodule_repo () { + git init submodule_update_repo && + ( + cd submodule_update_repo &&
t/lib-submodule-update.sh line 47
Quoted 10 lines
t/lib-submodule-update.sh new file +10
-0+ echo "expect" >>.gitignore && + echo "actual" >>.gitignore && + echo "x" >file1 && + echo "y" >file2 && + git add .gitignore file1 file2 && + git commit -m "Base" && + git branch "no_submodule" && + + git checkout -b "add_sub1" && + git submodule add ./. sub1 &&
This is not technically wrong per-se, but having the project's history itself as its own submodule *is* something nobody sane would do in the real life. Do we really have to do it this unusual way?
Quoted 50 lines
t/lib-submodule-update.sh new file +50
-0+ git config -f .gitmodules submodule.sub1.ignore all && + git config submodule.sub1.ignore all && + git add .gitmodules && + git commit -m "Add sub1" && + git checkout -b remove_sub1 && + git revert HEAD && + + git checkout -b "modify_sub1" "add_sub1" && + git submodule update && + ( + cd sub1 && + git fetch && + git checkout -b "modifications" && + echo "z" >file2 && + echo "x" >file3 && + git add file2 file3 && + git commit -m "modified file2 and added file3" && + git push origin modifications + ) && + git add sub1 && + git commit -m "Modify sub1" && + + git checkout -b "replace_sub1_with_directory" "add_sub1" && + git submodule update && + ( + cd sub1 && + git checkout modifications + ) && + git rm --cached sub1 && + rm sub1/.git* && + git config -f .gitmodules --remove-section "submodule.sub1" && + git add .gitmodules sub1/* && + git commit -m "Replace sub1 with directory" && + git checkout -b replace_directory_with_sub1 && + git revert HEAD && + + git checkout -b "replace_sub1_with_file" "add_sub1" && + git rm sub1 && + echo "content" >sub1 && + git add sub1 && + git commit -m "Replace sub1 with file" && + git checkout -b replace_file_with_sub1 && + git revert HEAD && + + git checkout -b "invalid_sub1" "add_sub1" && + git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 sub1 && + git commit -m "Invalid sub1 commit" && + git checkout -b valid_sub1 && + git revert HEAD && + git checkout master
t/lib-submodule-update.sh line 107
Quoted 10 lines
t/lib-submodule-update.sh new file +10
-0+ ) +} + +# Helper function to replace gitfile with .git directory +replace_gitfile_with_git_dir () { + ( + cd "$1" && + git_dir="$(git rev-parse --git-dir)" && + rm -f .git && + cp -a "$git_dir" .git &&
We avoid "cp -a" for portability, don't we?
t/lib-submodule-update.sh line 108
Quoted 1 line
t/lib-submodule-update.sh new file +1
-0+ GIT_WORK_TREE=. git config --unset core.worktree
Hmph. What does GIT_WORK_TREE=. alone without GIT_DIR=<somewhere> do? It's not like it is a workaround for "git config" that complains when you do not have a working tree, right? Puzzled...
t/lib-submodule-update.sh line 119
Quoted 11 lines
t/lib-submodule-update.sh new file +11
-0+ ) +} + +# Test that the .git directory in the submodule is unchanged (except for the +# core.worktree setting) +test_git_directory_is_unchanged () { + ( + cd "$1" && + git config core.worktree "../../../$1" + ) && + git diff -r ".git/modules/$1" "$1/.git" &&
I'd prefer to see "--no-index" spelled out, if that is what is going on.
Quoted 18 lines
t/lib-submodule-update.sh new file +18
-0+ ( + cd "$1" && + GIT_WORK_TREE=. git config --unset core.worktree + ) +} + +# Helper function to be executed at the start of every test below, it sets up +# the submodule repo if it doesn't exist and configures the most problematic +# settings for diff.ignoreSubmodules. +prolog () { + (test -d submodule_update_repo || create_lib_submodule_repo) && + test_config_global diff.ignoreSubmodules all && + test_config diff.ignoreSubmodules all +} + +# Helper function to bring work tree back into the state given by the +# commit. This includes trying to populate sub1 accordingly if it exists and +# should be updated to an existing commit.
t/lib-submodule-update.sh line 147
Quoted 10 lines
t/lib-submodule-update.sh new file +10
-0+reset_work_tree_to () { + rm -rf submodule_update && + git clone submodule_update_repo submodule_update && + ( + cd submodule_update && + rm -rf sub1 && + git checkout -f "$1" && + git status -u -s >actual && + test_must_be_empty actual && + sha1=$(git ls-tree HEAD "sub1" 2>/dev/null | grep 160000 | tr '\t' ' ' | cut -d ' ' -f3) &&
Why discard the standard error stream?
grep|tr|cut looks somewhat stupid. Can't we do that with a single sed?
sha1=$(git ls-tree HEAD sub1 | sed -ne "s/^160000 commit \($_x40\) .*/\1/p")
or better yet, perhaps
sha1=$(git rev-parse HEAD:sub1)
t/lib-submodule-update.sh line 177
Quoted 12 lines
t/lib-submodule-update.sh new file +12
-0+# Test that the given submodule at path "$1" contains the content according +# to the submodule commit recorded in the superproject's commit "$2" +test_submodule_content () { + if test $# != 2 + then + echo "test_submodule_content needs two arguments" + return 1 + fi && + submodule="$1" && + commit="$2" && + test -d "$submodule"/ && + if ! test -f "$submodule"/.git && ! test -d "$submodule"/.git
I wonder if we can get away with a single "test -e" (we do not expect us to be creating device nodes or fifos there, do we?).
t/lib-submodule-update.sh line 182
Quoted 5 lines
t/lib-submodule-update.sh new file +5
-0+ then + echo "Submodule $submodule is not populated" + return 1 + fi && + sha1=$(git ls-tree "$commit" "$submodule" 2>/dev/null | tr '\t' ' ' | cut -d ' ' -f3) &&
Likewise.
Re: [PATCH 02/14] submodules: Add the lib-submodule-update.sh test library
Am 17.06.2014 00:49, schrieb Junio C Hamano:
Quoted 106 lines
Quoted 104 lines · Jens Lehmann
Add this test library to simplify covering all combinations of submodule update scenarios without having to add those to a test of each work tree manipulating command over and over again.
The functions
test_submodule_switch()andtest_submodule_forced_switch()are intended to be called from a test script with a single argument. This argument is either a work tree manipulating command (including any command line options) or a function (when more than a single git command is needed to switch work trees from the current HEAD to another commit). This command (or function) is passed a target branch as argument. The two new functions check that each submodule transition is handled as expected, which currently means that submodule work trees are not affected until "git submodule update" is called. The "forced" variant is for commands using their '-f' or '--hard' option and expects them to overwrite local modifications as a result. Each of these two functions contains 14 tests_expect_* calls.Calling one of these test functions the first time creates a repository named "
submodule_update_repo". At first it contains two files, then a single submodule is added in another commit followed by commits covering all relevant submodule modifications. This repository is newly cloned into the "submodule_update" for each test_expect_* to avoid interference between different parts of the test functions (some to-be-tested commands also manipulate refs along with the work tree, e.g. "git reset").Follow-up commits will then call these two test functions for all work tree manipulating commands (with a combination of all their options relevant to what they do with the work tree) making sure they work as expected. Later this test library will be extended to cover merges resulting in conflicts too. Also it is intended to be easily extendable for the recursive update functionality, where even more combinations of submodule modifications have to be tested for.
This version documents two bugs in current Git with expected failures:
*) When a submodule is replaced with a tracked file of the same name the
submodule work tree including any local modifications (and even the whole history if it uses a .git directory instead of a gitfile!) is silently removed.*) Forced work tree updates happily manipulate files in the directory of a
submodule that has just been removed in the superproject (but is of course still present in the work tree due to the way submodules are currently handled). This becomes dangerous when files in the submodule directory are overwritten by files from the new superproject commit, as any modifications to the submodule files will be lost) and is expected to also destroy history in the - admittedly unlikely case - the new commit adds a file named ".git" to the submodule directory.Signed-off-by Jens Lehmann <[email protected]>--- t/lib-submodule-update.sh | 630 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 630 insertions(+) create mode 100755 t/lib-submodule-update.sht/lib-submodule-update.sh new file +43
-0@@ -0,0 +1,630 @@ +# Create a submodule layout used for all tests below. +# +# The following use cases are covered: +# - New submodule (no_submodule => add_sub1) +# - Removed submodule (add_sub1 => remove_sub1) +# - Updated submodule (add_sub1 => modify_sub1) +# - Submodule updated to invalid commit (add_sub1 => invalid_sub1) +# - Submodule updated from invalid commit (invalid_sub1 => valid_sub1) +# - Submodule replaced by tracked files in directory (add_sub1 => +# replace_sub1_with_directory) +# - Directory containing tracked files replaced by submodule +# (replace_sub1_with_directory => replace_directory_with_sub1) +# - Submodule replaced by tracked file with the same name (add_sub1 => +# replace_sub1_with_file) +# - Tracked file replaced by submodule (replace_sub1_with_file => +# replace_file_with_sub1) +# +# --O-----O +# / ^ replace_directory_with_sub1 +# / replace_sub1_with_directory +# /----O +# / ^ +# / modify_sub1 +# O------O-------O +# ^ ^\ ^ +# | | \ remove_sub1 +# | | -----O-----O +# | | \ ^ replace_file_with_sub1 +# | | \ replace_sub1_with_file +# | add_sub1 --O-----O +# no_submodule ^ valid_sub1 +# invalid_sub1 +# +create_lib_submodule_repo () { + git init submodule_update_repo && + ( + cd submodule_update_repo && + echo "expect" >>.gitignore && + echo "actual" >>.gitignore && + echo "x" >file1 && + echo "y" >file2 && + git add .gitignore file1 file2 && + git commit -m "Base" &&
Quoted 8 lines
t/lib-submodule-update.sh line 47
Quoted 4 lines
t/lib-submodule-update.sh new file +4
-0+ git branch "no_submodule" && + + git checkout -b "add_sub1" && + git submodule add ./. sub1 &&This is not technically wrong per-se, but having the project's history itself as its own submodule *is* something nobody sane would do in the real life. Do we really have to do it this unusual way?
I agree that this isn't a sane setup for real world usage, but I did that because it makes things easier when adding tests for recursive submodule update later, as we can then use the same test setup just one submodule level deeper.
Quoted 54 lines
Quoted 54 lines
t/lib-submodule-update.sh new file +54
-0+ git config -f .gitmodules submodule.sub1.ignore all && + git config submodule.sub1.ignore all && + git add .gitmodules && + git commit -m "Add sub1" && + git checkout -b remove_sub1 && + git revert HEAD && + + git checkout -b "modify_sub1" "add_sub1" && + git submodule update && + ( + cd sub1 && + git fetch && + git checkout -b "modifications" && + echo "z" >file2 && + echo "x" >file3 && + git add file2 file3 && + git commit -m "modified file2 and added file3" && + git push origin modifications + ) && + git add sub1 && + git commit -m "Modify sub1" && + + git checkout -b "replace_sub1_with_directory" "add_sub1" && + git submodule update && + ( + cd sub1 && + git checkout modifications + ) && + git rm --cached sub1 && + rm sub1/.git* && + git config -f .gitmodules --remove-section "submodule.sub1" && + git add .gitmodules sub1/* && + git commit -m "Replace sub1 with directory" && + git checkout -b replace_directory_with_sub1 && + git revert HEAD && + + git checkout -b "replace_sub1_with_file" "add_sub1" && + git rm sub1 && + echo "content" >sub1 && + git add sub1 && + git commit -m "Replace sub1 with file" && + git checkout -b replace_file_with_sub1 && + git revert HEAD && + + git checkout -b "invalid_sub1" "add_sub1" && + git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 sub1 && + git commit -m "Invalid sub1 commit" && + git checkout -b valid_sub1 && + git revert HEAD && + git checkout master + ) +} + +# Helper function to replace gitfile with .git directory
Quoted 8 lines
t/lib-submodule-update.sh line 107
Quoted 6 lines
t/lib-submodule-update.sh new file +6
-0+replace_gitfile_with_git_dir () { + ( + cd "$1" && + git_dir="$(git rev-parse --git-dir)" && + rm -f .git && + cp -a "$git_dir" .git &&We avoid "cp -a" for portability, don't we?
Yup, will change to "cp -R".
Quoted 5 lines
t/lib-submodule-update.sh line 108
Quoted 1 line
t/lib-submodule-update.sh new file +1
-0+ GIT_WORK_TREE=. git config --unset core.worktreeHmph. What does GIT_WORK_TREE=. alone without GIT_DIR=<somewhere> do? It's not like it is a workaround for "git config" that complains when you do not have a working tree, right? Puzzled...
It is, it overrides the core.worktree config that would stop us from unsetting the core.worktree config with this error message:
fatal: Could not chdir to '../../../sub1': No such file or directory
(We use the same pattern in git-submodule.sh and some other tests)
Quoted 6 lines
Quoted 6 lines
t/lib-submodule-update.sh new file +6
-0+ ) +} + +# Test that the .git directory in the submodule is unchanged (except for the +# core.worktree setting) +test_git_directory_is_unchanged () {
Quoted 8 lines
t/lib-submodule-update.sh line 119
Quoted 5 lines
t/lib-submodule-update.sh new file +5
-0+ ( + cd "$1" && + git config core.worktree "../../../$1" + ) && + git diff -r ".git/modules/$1" "$1/.git" &&I'd prefer to see "--no-index" spelled out, if that is what is going on.
Thanks for catching, this should read "diff -r" (to compare the two directories like the comment above states). Correcting this brings up two test failures (in which the index file changed), will investigate ...
Quoted 22 lines
Quoted 22 lines
t/lib-submodule-update.sh new file +22
-0+ ( + cd "$1" && + GIT_WORK_TREE=. git config --unset core.worktree + ) +} + +# Helper function to be executed at the start of every test below, it sets up +# the submodule repo if it doesn't exist and configures the most problematic +# settings for diff.ignoreSubmodules. +prolog () { + (test -d submodule_update_repo || create_lib_submodule_repo) && + test_config_global diff.ignoreSubmodules all && + test_config diff.ignoreSubmodules all +} + +# Helper function to bring work tree back into the state given by the +# commit. This includes trying to populate sub1 accordingly if it exists and +# should be updated to an existing commit. +reset_work_tree_to () { + rm -rf submodule_update && + git clone submodule_update_repo submodule_update && + (
Quoted 8 lines
t/lib-submodule-update.sh line 147
Quoted 6 lines
t/lib-submodule-update.sh new file +6
-0+ cd submodule_update && + rm -rf sub1 && + git checkout -f "$1" && + git status -u -s >actual && + test_must_be_empty actual && + sha1=$(git ls-tree HEAD "sub1" 2>/dev/null | grep 160000 | tr '\t' ' ' | cut -d ' ' -f3) &&Why discard the standard error stream?
Because we sometimes reset to commits where "sub1" isn't present:
fatal: Path 'sub1' does not exist in 'HEAD'
Quoted 8 lines
grep|tr|cut looks somewhat stupid. Can't we do that with a single sed?
sha1=$(git ls-tree HEAD sub1 | sed -ne "s/^160000 commit \($_x40\) .*/\1/p")or better yet, perhaps
sha1=$(git rev-parse HEAD:sub1)
Cool, that's much better. Due to the sometimes missing "sub1" I needed to modify it to drop the error and not fail:
sha1=$(git rev-parse HEAD:sub1 2>/dev/null || true) &&
Quoted 7 lines
Quoted 7 lines
t/lib-submodule-update.sh new file +7
-0+# Test that the given submodule at path "$1" contains the content according +# to the submodule commit recorded in the superproject's commit "$2" +test_submodule_content () { + if test $# != 2 + then + echo "test_submodule_content needs two arguments" + return 1
Quoted 8 lines
t/lib-submodule-update.sh line 177
Quoted 5 lines
t/lib-submodule-update.sh new file +5
-0+ fi && + submodule="$1" && + commit="$2" && + test -d "$submodule"/ && + if ! test -f "$submodule"/.git && ! test -d "$submodule"/.gitI wonder if we can get away with a single "test -e" (we do not expect us to be creating device nodes or fifos there, do we?).
But a symbolic link maybe? I wouldn't object loosening this test, but I thought it best to spell out the only two currently expected cases.
Quoted 7 lines
t/lib-submodule-update.sh line 182
Quoted 5 lines
t/lib-submodule-update.sh new file +5
-0+ then + echo "Submodule $submodule is not populated" + return 1 + fi && + sha1=$(git ls-tree "$commit" "$submodule" 2>/dev/null | tr '\t' ' ' | cut -d ' ' -f3) &&Likewise.
Yup, I changed this to:
sha1=$(git rev-parse "$commit:$submodule")
because "$submodule" should always exist when we end up here.
Re: [PATCH 02/14] submodules: Add the lib-submodule-update.sh test library
Quoted 9 lines · Jens Lehmann
Am 17.06.2014 00:49, schrieb Junio C Hamano:
Quoted 7 lines
t/lib-submodule-update.sh line 47
Quoted 2 lines · Jens Lehmann
t/lib-submodule-update.sh new file +2
-0+ git checkout -b "add_sub1" && + git submodule add ./. sub1 &&This is not technically wrong per-se, but having the project's history itself as its own submodule *is* something nobody sane would do in the real life. Do we really have to do it this unusual way?
Quoted 4 lines
I agree that this isn't a sane setup for real world usage, but I did that because it makes things easier when adding tests for recursive submodule update later, as we can then use the same test setup just one submodule level deeper.
Hmmm... ok....
Quoted 6 lines
Quoted 5 lines
Review
Quoted 1 line
(quoted diff) +1
-0+ GIT_WORK_TREE=. git config --unset core.worktreeHmph. What does GIT_WORK_TREE=. alone without GIT_DIR=<somewhere> do? It's not like it is a workaround for "git config" that complains when you do not have a working tree, right? Puzzled...
Quoted 6 lines
It is, it overrides the core.worktree config that would stop us from unsetting the core.worktree config with this error message:
fatal: Could not chdir to '../../../sub1': No such file or directory
(We use the same pattern in
git-submodule.shand some other tests)
Is this a work-around for a bug in "git config"? Or is this an expected failure and it is unusual and not realistic outside of test setup to want to unset core.worktree? I am inclined to think it is the latter, but I dunno.
Quoted 7 lines
Quoted 3 lines
t/lib-submodule-update.sh line 147
Quoted 1 line
t/lib-submodule-update.sh new file +1
-0+ sha1=$(git ls-tree HEAD "sub1" 2>/dev/null | grep 160000 | tr '\t' ' ' | cut -d ' ' -f3) &&Why discard the standard error stream?
Because we sometimes reset to commits where "sub1" isn't present:
fatal: Path 'sub1' does not exist in 'HEAD'
Huh? We shouldn't.
$ git ls-tree HEAD no-such; echo $?
0It discards errors that may happen in other situations, too---is that something we do not have to worry about?
Quoted 4 lines
Cool, that's much better. Due to the sometimes missing "sub1" I needed to modify it to drop the error and not fail:
sha1=$(git rev-parse HEAD:sub1 2>/dev/null || true) &&
The "HEAD:sub1" notation does require that the path exists in the specified tree-ish. Even if we tried to express the above in a more carefully written form:
# We may or may not have sub1 in HEAD
if "sub1 exists in HEAD"
then
sha1=$(git rev-parse HEAD:sub1)
else
sha1= # empty
fi
we would end up using "git rev-parse HEAD:sub1" to implement "sub1 exists in HEAD" part, so your updated alternative would be the best we could do, I would think.
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
t/lib-submodule-update.sh new file +7
-0+# Test that the given submodule at path "$1" contains the content according +# to the submodule commit recorded in the superproject's commit "$2" +test_submodule_content () { + if test $# != 2 + then + echo "test_submodule_content needs two arguments" + return 1Quoted 8 lines
t/lib-submodule-update.sh line 177
Quoted 5 lines
t/lib-submodule-update.sh new file +5
-0+ fi && + submodule="$1" && + commit="$2" && + test -d "$submodule"/ && + if ! test -f "$submodule"/.git && ! test -d "$submodule"/.gitI wonder if we can get away with a single "test -e" (we do not expect us to be creating device nodes or fifos there, do we?).
Quoted 1 line
But a symbolic link maybe?
Symlinks should pose no problems, I would say, without loosening anything.
$ test -f RelNotes; echo $?; test -e RelNotes; echo $?
0
0
$ ln -s t tests; test -d tests; echo $?; test -e tests; echo $?
0
$ ln -s no-such x; test -f x; echo $?; test -e x; echo $?
1
1Thanks.
Re: [PATCH 02/14] submodules: Add the lib-submodule-update.sh test library
Am 17.06.2014 20:44, schrieb Junio C Hamano:
Quoted 13 lines
Quoted 11 lines · Jens Lehmann
Am 17.06.2014 00:49, schrieb Junio C Hamano:
Quoted 6 lines
Review
Quoted 1 line · Jens Lehmann
(quoted diff) +1
-0+ GIT_WORK_TREE=. git config --unset core.worktreeHmph. What does GIT_WORK_TREE=. alone without GIT_DIR=<somewhere> do? It's not like it is a workaround for "git config" that complains when you do not have a working tree, right? Puzzled...
It is, it overrides the core.worktree config that would stop us from unsetting the core.worktree config with this error message:
Quoted 8 lines
Quoted 3 lines
fatal: Could not chdir to '../../../sub1': No such file or directory
(We use the same pattern in
git-submodule.shand some other tests)Is this a work-around for a bug in "git config"? Or is this an expected failure and it is unusual and not realistic outside of test setup to want to unset core.worktree? I am inclined to think it is the latter, but I dunno.
I didn't think deeply about that, but when I first encountered this behavior it felt a bit strange that config does a chdir into the work tree. I somehow expected it only to access the config file in GIT_DIR and not the work tree, but I didn't care enough to investigate further after I found this solution.
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
t/lib-submodule-update.sh line 147
Quoted 1 line
t/lib-submodule-update.sh new file +1
-0+ sha1=$(git ls-tree HEAD "sub1" 2>/dev/null | grep 160000 | tr '\t' ' ' | cut -d ' ' -f3) &&Why discard the standard error stream?
Quoted 8 lines
Quoted 3 lines
Because we sometimes reset to commits where "sub1" isn't present:
fatal: Path 'sub1' does not exist in 'HEAD'
Huh? We shouldn't.
$ git ls-tree HEAD no-such; echo $? 0
You are correct, it looks like I used rev-parse instead of ls-files when producing that error.
Quoted 2 lines
It discards errors that may happen in other situations, too---is that something we do not have to worry about?
I'll look deeper into that tomorrow. After all in some tests "sub1" will be a file and not a submodule, and then we should not try to populate it ...
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
t/lib-submodule-update.sh line 177
Quoted 12 lines
t/lib-submodule-update.sh new file +12
-0+# Test that the given submodule at path "$1" contains the content according +# to the submodule commit recorded in the superproject's commit "$2" +test_submodule_content () { + if test $# != 2 + then + echo "test_submodule_content needs two arguments" + return 1 + fi && + submodule="$1" && + commit="$2" && + test -d "$submodule"/ && + if ! test -f "$submodule"/.git && ! test -d "$submodule"/.gitI wonder if we can get away with a single "test -e" (we do not expect us to be creating device nodes or fifos there, do we?).
Quoted 3 lines
Quoted 1 line
But a symbolic link maybe?
Symlinks should pose no problems, ...
Oh, I forgot to add a smiley there, I haven't been serious about that statement. I don't care too deeply about it but feel a bit more confident with the two explicit tests. Do you want me to change them to a single "test -e"?
Re: [PATCH 02/14] submodules: Add the lib-submodule-update.sh test library
Quoted 4 lines · Jens Lehmann
Oh, I forgot to add a smiley there, I haven't been serious about that statement. I don't care too deeply about it but feel a bit more confident with the two explicit tests. Do you want me to change them to a single "test -e"?
I have no strong preference.
PATCH v2 2/14 submodules: Add the lib-submodule-update.sh test library
In reply to Jens LehmannAdd this test library to simplify covering all combinations of submodule update scenarios without having to add those to a test of each work tree manipulating command over and over again.
The functions test_submodule_switch() and test_submodule_forced_switch() are intended to be called from a test script with a single argument. This argument is either a work tree manipulating command (including any command line options) or a function (when more than a single git command is needed to switch work trees from the current HEAD to another commit). This command (or function) is passed a target branch as argument. The two new functions check that each submodule transition is handled as expected, which currently means that submodule work trees are not affected until "git submodule update" is called. The "forced" variant is for commands using their '-f' or '--hard' option and expects them to overwrite local modifications as a result. Each of these two functions contains 14 tests_expect_* calls.
Calling one of these test functions the first time creates a repository named "submodule_update_repo". At first it contains two files, then a single submodule is added in another commit followed by commits covering all relevant submodule modifications. This repository is newly cloned into the "submodule_update" for each test_expect_* to avoid interference between different parts of the test functions (some to-be-tested commands also manipulate refs along with the work tree, e.g. "git reset").
Follow-up commits will then call these two test functions for all work tree manipulating commands (with a combination of all their options relevant to what they do with the work tree) making sure they work as expected. Later this test library will be extended to cover merges resulting in conflicts too. Also it is intended to be easily extendable for the recursive update functionality, where even more combinations of submodule modifications have to be tested for.
This version documents two bugs in current Git with expected failures:
*) When a submodule is replaced with a tracked file of the same name the
submodule work tree including any local modifications (and even the whole history if it uses a .git directory instead of a gitfile!) is silently removed.
*) Forced work tree updates happily manipulate files in the directory of a
submodule that has just been removed in the superproject (but is of course still present in the work tree due to the way submodules are currently handled). This becomes dangerous when files in the submodule directory are overwritten by files from the new superproject commit, as any modifications to the submodule files will be lost) and is expected to also destroy history in the - admittedly unlikely case - the new commit adds a file named ".git" to the submodule directory.
---
Changes to v1:
*) avoid non-portable "cp -a"
*) use "diff -r" without "git " when comparing directory trees
*) simplify retrieving the SHA-1 of sub1
*) call test_git_directory_is_unchanged before test_submodule_content (this
was the reason for two test failures after removing the "git " before "diff" as test_submodule_content would sometimes modify the index)
t/lib-submodule-update.sh | 632 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 632 insertions(+) create mode 100755 t/lib-submodule-update.sh
t/lib-submodule-update.sh new file +632 -0
@@ -0,0 +1,632 @@ +# Create a submodule layout used for all tests below. +# +# The following use cases are covered: +# - New submodule (no_submodule => add_sub1) +# - Removed submodule (add_sub1 => remove_sub1) +# - Updated submodule (add_sub1 => modify_sub1) +# - Submodule updated to invalid commit (add_sub1 => invalid_sub1) +# - Submodule updated from invalid commit (invalid_sub1 => valid_sub1) +# - Submodule replaced by tracked files in directory (add_sub1 => +# replace_sub1_with_directory) +# - Directory containing tracked files replaced by submodule +# (replace_sub1_with_directory => replace_directory_with_sub1) +# - Submodule replaced by tracked file with the same name (add_sub1 => +# replace_sub1_with_file) +# - Tracked file replaced by submodule (replace_sub1_with_file => +# replace_file_with_sub1) +# +# --O-----O +# / ^ replace_directory_with_sub1 +# / replace_sub1_with_directory +# /----O +# / ^ +# / modify_sub1 +# O------O-------O +# ^ ^\ ^ +# | | \ remove_sub1 +# | | -----O-----O +# | | \ ^ replace_file_with_sub1 +# | | \ replace_sub1_with_file +# | add_sub1 --O-----O +# no_submodule ^ valid_sub1 +# invalid_sub1 +# +create_lib_submodule_repo () { + git init submodule_update_repo && + ( + cd submodule_update_repo && + echo "expect" >>.gitignore && + echo "actual" >>.gitignore && + echo "x" >file1 && + echo "y" >file2 && + git add .gitignore file1 file2 && + git commit -m "Base" && + git branch "no_submodule" && + + git checkout -b "add_sub1" && + git submodule add ./. sub1 && + git config -f .gitmodules submodule.sub1.ignore all && + git config submodule.sub1.ignore all && + git add .gitmodules && + git commit -m "Add sub1" && + git checkout -b remove_sub1 && + git revert HEAD && + + git checkout -b "modify_sub1" "add_sub1" && + git submodule update && + ( + cd sub1 && + git fetch && + git checkout -b "modifications" && + echo "z" >file2 && + echo "x" >file3 && + git add file2 file3 && + git commit -m "modified file2 and added file3" && + git push origin modifications + ) && + git add sub1 && + git commit -m "Modify sub1" && + + git checkout -b "replace_sub1_with_directory" "add_sub1" && + git submodule update && + ( + cd sub1 && + git checkout modifications + ) && + git rm --cached sub1 && + rm sub1/.git* && + git config -f .gitmodules --remove-section "submodule.sub1" && + git add .gitmodules sub1/* && + git commit -m "Replace sub1 with directory" && + git checkout -b replace_directory_with_sub1 && + git revert HEAD && + + git checkout -b "replace_sub1_with_file" "add_sub1" && + git rm sub1 && + echo "content" >sub1 && + git add sub1 && + git commit -m "Replace sub1 with file" && + git checkout -b replace_file_with_sub1 && + git revert HEAD && + + git checkout -b "invalid_sub1" "add_sub1" && + git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 sub1 && + git commit -m "Invalid sub1 commit" && + git checkout -b valid_sub1 && + git revert HEAD && + git checkout master + ) +} + +# Helper function to replace gitfile with .git directory +replace_gitfile_with_git_dir () { + ( + cd "$1" && + git_dir="$(git rev-parse --git-dir)" && + rm -f .git && + cp -R "$git_dir" .git && + GIT_WORK_TREE=. git config --unset core.worktree + ) +} + +# Test that the .git directory in the submodule is unchanged (except for the +# core.worktree setting, which we temporarily restore). Call this function +# before test_submodule_content as the latter might write the index file +# leading to false positive index differences. +test_git_directory_is_unchanged () { + ( + cd "$1" && + git config core.worktree "../../../$1" + ) && + diff -r ".git/modules/$1" "$1/.git" && + ( + cd "$1" && + GIT_WORK_TREE=. git config --unset core.worktree + ) +} + +# Helper function to be executed at the start of every test below, it sets up +# the submodule repo if it doesn't exist and configures the most problematic +# settings for diff.ignoreSubmodules. +prolog () { + (test -d submodule_update_repo || create_lib_submodule_repo) && + test_config_global diff.ignoreSubmodules all && + test_config diff.ignoreSubmodules all +} + +# Helper function to bring work tree back into the state given by the +# commit. This includes trying to populate sub1 accordingly if it exists and +# should be updated to an existing commit. +reset_work_tree_to () { + rm -rf submodule_update && + git clone submodule_update_repo submodule_update && + ( + cd submodule_update && + rm -rf sub1 && + git checkout -f "$1" && + git status -u -s >actual && + test_must_be_empty actual && + sha1=$(git rev-parse HEAD:sub1 || true) && + if test -n "$sha1" && + test $(cd "sub1" && git rev-parse --verify "$sha1^{commit}") + then + git submodule update --init --recursive "sub1" + fi + ) +} + +# Test that the superproject contains the content according to commit "$1" +# (the work tree must match the index for everything but submodules but the +# index must exactly match the given commit including any submodule SHA-1s). +test_superproject_content () { + git diff-index --cached "$1" >actual && + test_must_be_empty actual && + git diff-files --ignore-submodules >actual && + test_must_be_empty actual +} + +# Test that the given submodule at path "$1" contains the content according +# to the submodule commit recorded in the superproject's commit "$2" +test_submodule_content () { + if test $# != 2 + then + echo "test_submodule_content needs two arguments" + return 1 + fi && + submodule="$1" && + commit="$2" && + test -d "$submodule"/ && + if ! test -f "$submodule"/.git && ! test -d "$submodule"/.git + then + echo "Submodule $submodule is not populated" + return 1 + fi && + sha1=$(git rev-parse "$commit:$submodule") && + if test -z "$sha1" + then + echo "Couldn't retrieve SHA-1 of $submodule for $commit" + return 1 + fi && + ( + cd "$submodule" && + git status -u -s >actual && + test_must_be_empty actual && + git diff "$sha1" >actual && + test_must_be_empty actual + ) +} + +# Test that the following transitions are correctly handled: +# - Updated submodule +# - New submodule +# - Removed submodule +# - Directory containing tracked files replaced by submodule +# - Submodule replaced by tracked files in directory +# - Submodule replaced by tracked file with the same name +# - tracked file replaced by submodule +# +# The default is that submodule contents aren't changed until "git submodule +# update" is run. And even then that command doesn't delete the work tree of +# a removed submodule. +# +# Removing a submodule containing a .git directory must fail even when forced +# to protect the history! +# + +# Test that submodule contents are currently not updated when switching +# between commits that change a submodule. +test_submodule_switch () { + command="$1" + ######################### Appearing submodule ######################### + # Switching to a commit letting a submodule appear creates empty dir ... + test_expect_success "$command: added submodule creates empty directory" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... and doesn't care if it already exists ... + test_expect_success "$command: added submodule leaves existing empty directory alone" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + mkdir sub1 && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... unless there is an untracked file in its place. + test_expect_success "$command: added submodule doesn't remove untracked unignored file with same name" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + echo -n >sub1 && + test_must_fail $command add_sub1 && + test_superproject_content origin/no_submodule && + test_must_be_empty sub1 + ) + ' + # Replacing a tracked file with a submodule produces an empty + # directory ... + test_expect_success "$command: replace tracked file with submodule creates empty directory" ' + prolog && + reset_work_tree_to replace_sub1_with_file && + ( + cd submodule_update && + git branch -t replace_file_with_sub1 origin/replace_file_with_sub1 && + $command replace_file_with_sub1 && + test_superproject_content origin/replace_file_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_file_with_sub1 + ) + ' + # ... as does removing a directory with tracked files with a + # submodule. + test_expect_success "$command: replace directory with submodule" ' + prolog && + reset_work_tree_to replace_sub1_with_directory && + ( + cd submodule_update && + git branch -t replace_directory_with_sub1 origin/replace_directory_with_sub1 && + $command replace_directory_with_sub1 && + test_superproject_content origin/replace_directory_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_directory_with_sub1 + ) + ' + + ######################## Disappearing submodule ####################### + # Removing a submodule doesn't remove its work tree ... + test_expect_success "$command: removed submodule leaves submodule directory and its contents in place" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_success "$command: removed submodule leaves submodule containing a .git directory alone" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + replace_gitfile_with_git_dir sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing a submodule with files in a directory must fail as the + # submodule work tree isn't removed ... + test_expect_success "$command: replace submodule with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_success "$command: replace submodule containing a .git directory with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing it with a file must fail as it could throw away any local + # work tree changes ... + test_expect_failure "$command: replace submodule with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... or even destroy unpushed parts of submodule history if that + # still uses a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + + ########################## Modified submodule ######################### + # Updating a submodule sha1 doesn't update the submodule's work tree + test_expect_success "$command: modified submodule does not update submodule work tree" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t modify_sub1 origin/modify_sub1 && + $command modify_sub1 && + test_superproject_content origin/modify_sub1 && + test_submodule_content sub1 origin/add_sub1 && + git submodule update && + test_submodule_content sub1 origin/modify_sub1 + ) + ' + + # Updating a submodule to an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will fail + test_expect_success "$command: modified submodule does not update submodule work tree to invalid commit" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t invalid_sub1 origin/invalid_sub1 && + $command invalid_sub1 && + test_superproject_content origin/invalid_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_must_fail git submodule update && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Updating a submodule from an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will succeed + test_expect_success "$command: modified submodule does not update submodule work tree from invalid commit" ' + prolog && + reset_work_tree_to invalid_sub1 && + ( + cd submodule_update && + git branch -t valid_sub1 origin/valid_sub1 && + $command valid_sub1 && + test_superproject_content origin/valid_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/valid_sub1 + ) + ' +} + +# Test that submodule contents are currently not updated when switching +# between commits that change a submodule, but throwing away local changes in +# the superproject is allowed. +test_submodule_forced_switch () { + command="$1" + ######################### Appearing submodule ######################### + # Switching to a commit letting a submodule appear creates empty dir ... + test_expect_success "$command: added submodule creates empty directory" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... and doesn't care if it already exists ... + test_expect_success "$command: added submodule leaves existing empty directory alone" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + mkdir sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... unless there is an untracked file in its place. + test_expect_success "$command: added submodule does remove untracked unignored file with same name when forced" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + echo -n >sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 + ) + ' + # Replacing a tracked file with a submodule produces an empty + # directory ... + test_expect_success "$command: replace tracked file with submodule creates empty directory" ' + prolog && + reset_work_tree_to replace_sub1_with_file && + ( + cd submodule_update && + git branch -t replace_file_with_sub1 origin/replace_file_with_sub1 && + $command replace_file_with_sub1 && + test_superproject_content origin/replace_file_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_file_with_sub1 + ) + ' + # ... as does removing a directory with tracked files with a + # submodule. + test_expect_success "$command: replace directory with submodule" ' + prolog && + reset_work_tree_to replace_sub1_with_directory && + ( + cd submodule_update && + git branch -t replace_directory_with_sub1 origin/replace_directory_with_sub1 && + $command replace_directory_with_sub1 && + test_superproject_content origin/replace_directory_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_directory_with_sub1 + ) + ' + + ######################## Disappearing submodule ####################### + # Removing a submodule doesn't remove its work tree ... + test_expect_success "$command: removed submodule leaves submodule directory and its contents in place" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_success "$command: removed submodule leaves submodule containing a .git directory alone" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + replace_gitfile_with_git_dir sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing a submodule with files in a directory must fail as the + # submodule work tree isn't removed ... + test_expect_failure "$command: replace submodule with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing it with a file must fail as it could throw away any local + # work tree changes ... + test_expect_failure "$command: replace submodule with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... or even destroy unpushed parts of submodule history if that + # still uses a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + + ########################## Modified submodule ######################### + # Updating a submodule sha1 doesn't update the submodule's work tree + test_expect_success "$command: modified submodule does not update submodule work tree" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t modify_sub1 origin/modify_sub1 && + $command modify_sub1 && + test_superproject_content origin/modify_sub1 && + test_submodule_content sub1 origin/add_sub1 && + git submodule update && + test_submodule_content sub1 origin/modify_sub1 + ) + ' + # Updating a submodule to an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will fail + test_expect_success "$command: modified submodule does not update submodule work tree to invalid commit" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t invalid_sub1 origin/invalid_sub1 && + $command invalid_sub1 && + test_superproject_content origin/invalid_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_must_fail git submodule update && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Updating a submodule from an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will succeed + test_expect_success "$command: modified submodule does not update submodule work tree from invalid commit" ' + prolog && + reset_work_tree_to invalid_sub1 && + ( + cd submodule_update && + git branch -t valid_sub1 origin/valid_sub1 && + $command valid_sub1 && + test_superproject_content origin/valid_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/valid_sub1 + ) + ' +}
Signature · 1 line
2.0.0.406.gf4dce28
Re: [PATCH v2 02/14] submodules: Add the lib-submodule-update.sh test library
t/lib-submodule-update.sh line 149
Quoted 5 lines · Jens Lehmann
t/lib-submodule-update.sh new file +5
-0+ rm -rf sub1 && + git checkout -f "$1" && + git status -u -s >actual && + test_must_be_empty actual && + sha1=$(git rev-parse HEAD:sub1 || true) &&
$ xx=; xx=$(git rev-parse HEAD:no-such-path || true) ; echo $? ; echo "<$xx>"
fatal: Path 'no-such-path' does not exist in 'HEAD'
0
<HEAD:no-such-path>Perhaps you want --verify (or --revs-only) there, i.e.
sha1=$(git rev-parse --verify HEAD:sub1 || :) &&
or
sha1=$(git rev-parse --revs-only HEAD:sub1) &&
t/lib-submodule-update.sh line 184
Quoted 3 lines
t/lib-submodule-update.sh new file +2
-0+ if test -n "$sha1" && + sha1=$(git rev-parse "$commit:$submodule") &&
And here too.
Quoted 1 line
t/lib-submodule-update.sh new file +1
-0+ if test -z "$sha1"
PATCH v3 2/14 submodules: Add the lib-submodule-update.sh test library
Add this test library to simplify covering all combinations of submodule update scenarios without having to add those to a test of each work tree manipulating command over and over again.
The functions test_submodule_switch() and test_submodule_forced_switch() are intended to be called from a test script with a single argument. This argument is either a work tree manipulating command (including any command line options) or a function (when more than a single git command is needed to switch work trees from the current HEAD to another commit). This command (or function) is passed a target branch as argument. The two new functions check that each submodule transition is handled as expected, which currently means that submodule work trees are not affected until "git submodule update" is called. The "forced" variant is for commands using their '-f' or '--hard' option and expects them to overwrite local modifications as a result. Each of these two functions contains 14 tests_expect_* calls.
Calling one of these test functions the first time creates a repository named "submodule_update_repo". At first it contains two files, then a single submodule is added in another commit followed by commits covering all relevant submodule modifications. This repository is newly cloned into the "submodule_update" for each test_expect_* to avoid interference between different parts of the test functions (some to-be-tested commands also manipulate refs along with the work tree, e.g. "git reset").
Follow-up commits will then call these two test functions for all work tree manipulating commands (with a combination of all their options relevant to what they do with the work tree) making sure they work as expected. Later this test library will be extended to cover merges resulting in conflicts too. Also it is intended to be easily extendable for the recursive update functionality, where even more combinations of submodule modifications have to be tested for.
This version documents two bugs in current Git with expected failures:
*) When a submodule is replaced with a tracked file of the same name the
submodule work tree including any local modifications (and even the whole history if it uses a .git directory instead of a gitfile!) is silently removed.
*) Forced work tree updates happily manipulate files in the directory of a
submodule that has just been removed in the superproject (but is of course still present in the work tree due to the way submodules are currently handled). This becomes dangerous when files in the submodule directory are overwritten by files from the new superproject commit, as any modifications to the submodule files will be lost) and is expected to also destroy history in the - admittedly unlikely case - the new commit adds a file named ".git" to the submodule directory.
---
Am 20.06.2014 19:31, schrieb Junio C Hamano:
Quoted 19 lines
Review
Quoted 5 lines · Jens Lehmann
(quoted diff) +5
-0+ rm -rf sub1 && + git checkout -f "$1" && + git status -u -s >actual && + test_must_be_empty actual && + sha1=$(git rev-parse HEAD:sub1 || true) &&$ xx=; xx=$(git rev-parse HEAD:no-such-path || true) ; echo $? ; echo "<$xx>" fatal: Path 'no-such-path' does not exist in 'HEAD' 0 <HEAD:no-such-path>Perhaps you want --verify (or --revs-only) there, i.e.
sha1=$(git rev-parse --verify HEAD:sub1 || :) &&or
Quoted 7 lines
sha1=$(git rev-parse --revs-only HEAD:sub1) &&Review
Quoted 3 lines
(quoted diff) +2
-0+ if test -n "$sha1" && + sha1=$(git rev-parse "$commit:$submodule") &&And here too.
Thanks, I squashed your "SQUASH???" commit (currently in pu) into this version.
t/lib-submodule-update.sh | 632 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 632 insertions(+) create mode 100755 t/lib-submodule-update.sh
t/lib-submodule-update.sh new file +632 -0
@@ -0,0 +1,632 @@ +# Create a submodule layout used for all tests below. +# +# The following use cases are covered: +# - New submodule (no_submodule => add_sub1) +# - Removed submodule (add_sub1 => remove_sub1) +# - Updated submodule (add_sub1 => modify_sub1) +# - Submodule updated to invalid commit (add_sub1 => invalid_sub1) +# - Submodule updated from invalid commit (invalid_sub1 => valid_sub1) +# - Submodule replaced by tracked files in directory (add_sub1 => +# replace_sub1_with_directory) +# - Directory containing tracked files replaced by submodule +# (replace_sub1_with_directory => replace_directory_with_sub1) +# - Submodule replaced by tracked file with the same name (add_sub1 => +# replace_sub1_with_file) +# - Tracked file replaced by submodule (replace_sub1_with_file => +# replace_file_with_sub1) +# +# --O-----O +# / ^ replace_directory_with_sub1 +# / replace_sub1_with_directory +# /----O +# / ^ +# / modify_sub1 +# O------O-------O +# ^ ^\ ^ +# | | \ remove_sub1 +# | | -----O-----O +# | | \ ^ replace_file_with_sub1 +# | | \ replace_sub1_with_file +# | add_sub1 --O-----O +# no_submodule ^ valid_sub1 +# invalid_sub1 +# +create_lib_submodule_repo () { + git init submodule_update_repo && + ( + cd submodule_update_repo && + echo "expect" >>.gitignore && + echo "actual" >>.gitignore && + echo "x" >file1 && + echo "y" >file2 && + git add .gitignore file1 file2 && + git commit -m "Base" && + git branch "no_submodule" && + + git checkout -b "add_sub1" && + git submodule add ./. sub1 && + git config -f .gitmodules submodule.sub1.ignore all && + git config submodule.sub1.ignore all && + git add .gitmodules && + git commit -m "Add sub1" && + git checkout -b remove_sub1 && + git revert HEAD && + + git checkout -b "modify_sub1" "add_sub1" && + git submodule update && + ( + cd sub1 && + git fetch && + git checkout -b "modifications" && + echo "z" >file2 && + echo "x" >file3 && + git add file2 file3 && + git commit -m "modified file2 and added file3" && + git push origin modifications + ) && + git add sub1 && + git commit -m "Modify sub1" && + + git checkout -b "replace_sub1_with_directory" "add_sub1" && + git submodule update && + ( + cd sub1 && + git checkout modifications + ) && + git rm --cached sub1 && + rm sub1/.git* && + git config -f .gitmodules --remove-section "submodule.sub1" && + git add .gitmodules sub1/* && + git commit -m "Replace sub1 with directory" && + git checkout -b replace_directory_with_sub1 && + git revert HEAD && + + git checkout -b "replace_sub1_with_file" "add_sub1" && + git rm sub1 && + echo "content" >sub1 && + git add sub1 && + git commit -m "Replace sub1 with file" && + git checkout -b replace_file_with_sub1 && + git revert HEAD && + + git checkout -b "invalid_sub1" "add_sub1" && + git update-index --cacheinfo 160000 0123456789012345678901234567890123456789 sub1 && + git commit -m "Invalid sub1 commit" && + git checkout -b valid_sub1 && + git revert HEAD && + git checkout master + ) +} + +# Helper function to replace gitfile with .git directory +replace_gitfile_with_git_dir () { + ( + cd "$1" && + git_dir="$(git rev-parse --git-dir)" && + rm -f .git && + cp -R "$git_dir" .git && + GIT_WORK_TREE=. git config --unset core.worktree + ) +} + +# Test that the .git directory in the submodule is unchanged (except for the +# core.worktree setting, which we temporarily restore). Call this function +# before test_submodule_content as the latter might write the index file +# leading to false positive index differences. +test_git_directory_is_unchanged () { + ( + cd "$1" && + git config core.worktree "../../../$1" + ) && + diff -r ".git/modules/$1" "$1/.git" && + ( + cd "$1" && + GIT_WORK_TREE=. git config --unset core.worktree + ) +} + +# Helper function to be executed at the start of every test below, it sets up +# the submodule repo if it doesn't exist and configures the most problematic +# settings for diff.ignoreSubmodules. +prolog () { + (test -d submodule_update_repo || create_lib_submodule_repo) && + test_config_global diff.ignoreSubmodules all && + test_config diff.ignoreSubmodules all +} + +# Helper function to bring work tree back into the state given by the +# commit. This includes trying to populate sub1 accordingly if it exists and +# should be updated to an existing commit. +reset_work_tree_to () { + rm -rf submodule_update && + git clone submodule_update_repo submodule_update && + ( + cd submodule_update && + rm -rf sub1 && + git checkout -f "$1" && + git status -u -s >actual && + test_must_be_empty actual && + sha1=$(git rev-parse --revs-only HEAD:sub1) && + if test -n "$sha1" && + test $(cd "sub1" && git rev-parse --verify "$sha1^{commit}") + then + git submodule update --init --recursive "sub1" + fi + ) +} + +# Test that the superproject contains the content according to commit "$1" +# (the work tree must match the index for everything but submodules but the +# index must exactly match the given commit including any submodule SHA-1s). +test_superproject_content () { + git diff-index --cached "$1" >actual && + test_must_be_empty actual && + git diff-files --ignore-submodules >actual && + test_must_be_empty actual +} + +# Test that the given submodule at path "$1" contains the content according +# to the submodule commit recorded in the superproject's commit "$2" +test_submodule_content () { + if test $# != 2 + then + echo "test_submodule_content needs two arguments" + return 1 + fi && + submodule="$1" && + commit="$2" && + test -d "$submodule"/ && + if ! test -f "$submodule"/.git && ! test -d "$submodule"/.git + then + echo "Submodule $submodule is not populated" + return 1 + fi && + sha1=$(git rev-parse --verify "$commit:$submodule") && + if test -z "$sha1" + then + echo "Couldn't retrieve SHA-1 of $submodule for $commit" + return 1 + fi && + ( + cd "$submodule" && + git status -u -s >actual && + test_must_be_empty actual && + git diff "$sha1" >actual && + test_must_be_empty actual + ) +} + +# Test that the following transitions are correctly handled: +# - Updated submodule +# - New submodule +# - Removed submodule +# - Directory containing tracked files replaced by submodule +# - Submodule replaced by tracked files in directory +# - Submodule replaced by tracked file with the same name +# - tracked file replaced by submodule +# +# The default is that submodule contents aren't changed until "git submodule +# update" is run. And even then that command doesn't delete the work tree of +# a removed submodule. +# +# Removing a submodule containing a .git directory must fail even when forced +# to protect the history! +# + +# Test that submodule contents are currently not updated when switching +# between commits that change a submodule. +test_submodule_switch () { + command="$1" + ######################### Appearing submodule ######################### + # Switching to a commit letting a submodule appear creates empty dir ... + test_expect_success "$command: added submodule creates empty directory" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... and doesn't care if it already exists ... + test_expect_success "$command: added submodule leaves existing empty directory alone" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + mkdir sub1 && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... unless there is an untracked file in its place. + test_expect_success "$command: added submodule doesn't remove untracked unignored file with same name" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + echo -n >sub1 && + test_must_fail $command add_sub1 && + test_superproject_content origin/no_submodule && + test_must_be_empty sub1 + ) + ' + # Replacing a tracked file with a submodule produces an empty + # directory ... + test_expect_success "$command: replace tracked file with submodule creates empty directory" ' + prolog && + reset_work_tree_to replace_sub1_with_file && + ( + cd submodule_update && + git branch -t replace_file_with_sub1 origin/replace_file_with_sub1 && + $command replace_file_with_sub1 && + test_superproject_content origin/replace_file_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_file_with_sub1 + ) + ' + # ... as does removing a directory with tracked files with a + # submodule. + test_expect_success "$command: replace directory with submodule" ' + prolog && + reset_work_tree_to replace_sub1_with_directory && + ( + cd submodule_update && + git branch -t replace_directory_with_sub1 origin/replace_directory_with_sub1 && + $command replace_directory_with_sub1 && + test_superproject_content origin/replace_directory_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_directory_with_sub1 + ) + ' + + ######################## Disappearing submodule ####################### + # Removing a submodule doesn't remove its work tree ... + test_expect_success "$command: removed submodule leaves submodule directory and its contents in place" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_success "$command: removed submodule leaves submodule containing a .git directory alone" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + replace_gitfile_with_git_dir sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing a submodule with files in a directory must fail as the + # submodule work tree isn't removed ... + test_expect_success "$command: replace submodule with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_success "$command: replace submodule containing a .git directory with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing it with a file must fail as it could throw away any local + # work tree changes ... + test_expect_failure "$command: replace submodule with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... or even destroy unpushed parts of submodule history if that + # still uses a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + + ########################## Modified submodule ######################### + # Updating a submodule sha1 doesn't update the submodule's work tree + test_expect_success "$command: modified submodule does not update submodule work tree" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t modify_sub1 origin/modify_sub1 && + $command modify_sub1 && + test_superproject_content origin/modify_sub1 && + test_submodule_content sub1 origin/add_sub1 && + git submodule update && + test_submodule_content sub1 origin/modify_sub1 + ) + ' + + # Updating a submodule to an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will fail + test_expect_success "$command: modified submodule does not update submodule work tree to invalid commit" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t invalid_sub1 origin/invalid_sub1 && + $command invalid_sub1 && + test_superproject_content origin/invalid_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_must_fail git submodule update && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Updating a submodule from an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will succeed + test_expect_success "$command: modified submodule does not update submodule work tree from invalid commit" ' + prolog && + reset_work_tree_to invalid_sub1 && + ( + cd submodule_update && + git branch -t valid_sub1 origin/valid_sub1 && + $command valid_sub1 && + test_superproject_content origin/valid_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/valid_sub1 + ) + ' +} + +# Test that submodule contents are currently not updated when switching +# between commits that change a submodule, but throwing away local changes in +# the superproject is allowed. +test_submodule_forced_switch () { + command="$1" + ######################### Appearing submodule ######################### + # Switching to a commit letting a submodule appear creates empty dir ... + test_expect_success "$command: added submodule creates empty directory" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... and doesn't care if it already exists ... + test_expect_success "$command: added submodule leaves existing empty directory alone" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + mkdir sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... unless there is an untracked file in its place. + test_expect_success "$command: added submodule does remove untracked unignored file with same name when forced" ' + prolog && + reset_work_tree_to no_submodule && + ( + cd submodule_update && + git branch -t add_sub1 origin/add_sub1 && + echo -n >sub1 && + $command add_sub1 && + test_superproject_content origin/add_sub1 && + test_dir_is_empty sub1 + ) + ' + # Replacing a tracked file with a submodule produces an empty + # directory ... + test_expect_success "$command: replace tracked file with submodule creates empty directory" ' + prolog && + reset_work_tree_to replace_sub1_with_file && + ( + cd submodule_update && + git branch -t replace_file_with_sub1 origin/replace_file_with_sub1 && + $command replace_file_with_sub1 && + test_superproject_content origin/replace_file_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_file_with_sub1 + ) + ' + # ... as does removing a directory with tracked files with a + # submodule. + test_expect_success "$command: replace directory with submodule" ' + prolog && + reset_work_tree_to replace_sub1_with_directory && + ( + cd submodule_update && + git branch -t replace_directory_with_sub1 origin/replace_directory_with_sub1 && + $command replace_directory_with_sub1 && + test_superproject_content origin/replace_directory_with_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/replace_directory_with_sub1 + ) + ' + + ######################## Disappearing submodule ####################### + # Removing a submodule doesn't remove its work tree ... + test_expect_success "$command: removed submodule leaves submodule directory and its contents in place" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_success "$command: removed submodule leaves submodule containing a .git directory alone" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t remove_sub1 origin/remove_sub1 && + replace_gitfile_with_git_dir sub1 && + $command remove_sub1 && + test_superproject_content origin/remove_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing a submodule with files in a directory must fail as the + # submodule work tree isn't removed ... + test_expect_failure "$command: replace submodule with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... especially when it contains a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a directory must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_directory origin/replace_sub1_with_directory && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_directory && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Replacing it with a file must fail as it could throw away any local + # work tree changes ... + test_expect_failure "$command: replace submodule with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # ... or even destroy unpushed parts of submodule history if that + # still uses a .git directory. + test_expect_failure "$command: replace submodule containing a .git directory with a file must fail" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t replace_sub1_with_file origin/replace_sub1_with_file && + replace_gitfile_with_git_dir sub1 && + test_must_fail $command replace_sub1_with_file && + test_superproject_content origin/add_sub1 && + test_git_directory_is_unchanged sub1 && + test_submodule_content sub1 origin/add_sub1 + ) + ' + + ########################## Modified submodule ######################### + # Updating a submodule sha1 doesn't update the submodule's work tree + test_expect_success "$command: modified submodule does not update submodule work tree" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t modify_sub1 origin/modify_sub1 && + $command modify_sub1 && + test_superproject_content origin/modify_sub1 && + test_submodule_content sub1 origin/add_sub1 && + git submodule update && + test_submodule_content sub1 origin/modify_sub1 + ) + ' + # Updating a submodule to an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will fail + test_expect_success "$command: modified submodule does not update submodule work tree to invalid commit" ' + prolog && + reset_work_tree_to add_sub1 && + ( + cd submodule_update && + git branch -t invalid_sub1 origin/invalid_sub1 && + $command invalid_sub1 && + test_superproject_content origin/invalid_sub1 && + test_submodule_content sub1 origin/add_sub1 && + test_must_fail git submodule update && + test_submodule_content sub1 origin/add_sub1 + ) + ' + # Updating a submodule from an invalid sha1 doesn't update the + # submodule's work tree, subsequent update will succeed + test_expect_success "$command: modified submodule does not update submodule work tree from invalid commit" ' + prolog && + reset_work_tree_to invalid_sub1 && + ( + cd submodule_update && + git branch -t valid_sub1 origin/valid_sub1 && + $command valid_sub1 && + test_superproject_content origin/valid_sub1 && + test_dir_is_empty sub1 && + git submodule update --init --recursive && + test_submodule_content sub1 origin/valid_sub1 + ) + ' +}
Signature · 1 line
2.0.1.458.gf680257
PATCH 3/14 checkout: call the new submodule update test framework
In reply to Jens LehmannTest that the checkout command updates the work tree as expected with and without the '-f' flag.
--- t/t2013-checkout-submodule.sh | 5 +++++ 1 file changed, 5 insertions(+)
t/t2013-checkout-submodule.sh +5 -0
@@ -3,6 +3,7 @@ test_description='checkout can handle submodules' . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh test_expect_success 'setup' ' mkdir submodule &&
@@ -62,4 +63,8 @@ test_expect_success '"checkout <submodule>" honors submodule.*.ignore from .git/ ! test -s actual ' +test_submodule_switch "git checkout" + +test_submodule_forced_switch "git checkout -f" + test_done
Signature · 1 line
2.0.0.275.gc479268
PATCH 4/14 apply: add t4137 for submodule updates
In reply to Jens LehmannTest that the apply command updates the work tree as expected for the '--index' and the '--3way' options (for submodule changes which don't result in conflicts).
--- t/t4137-apply-submodule.sh | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 t/t4137-apply-submodule.sh
t/t4137-apply-submodule.sh new file +20 -0
@@ -0,0 +1,20 @@ +#!/bin/sh + +test_description='git apply handling submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +apply_index () { + git diff --ignore-submodules=dirty "..$1" | git apply --index - +} + +test_submodule_switch "apply_index" + +apply_3way () { + git diff --ignore-submodules=dirty "..$1" | git apply --3way - +} + +test_submodule_switch "apply_3way" + +test_done
Signature · 1 line
2.0.0.275.gc479268
PATCH 5/14 read-tree: add t1013 for submodule updates
In reply to Jens LehmannTest that the read-tree command updates the work tree as expected for changes which don't result in conflicts with the '-m' and '--reset' flag.
--- t/t1013-read-tree-submodule.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100755 t/t1013-read-tree-submodule.sh
t/t1013-read-tree-submodule.sh new file +12 -0
@@ -0,0 +1,12 @@ +#!/bin/sh + +test_description='read-tree can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +test_submodule_switch "git read-tree -u -m" + +test_submodule_forced_switch "git read-tree -u --reset" + +test_done
Signature · 1 line
2.0.0.275.gc479268
PATCH 6/14 reset: add t7112 for submodule updates
In reply to Jens LehmannTest that the reset command updates the work tree as expected for changes with '--keep', '--merge' (for changes which don't result in conflicts) and '--hard'.
--- t/t7112-reset-submodule.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100755 t/t7112-reset-submodule.sh
t/t7112-reset-submodule.sh new file +14 -0
@@ -0,0 +1,14 @@ +#!/bin/sh + +test_description='reset can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +test_submodule_switch "git reset --keep" + +test_submodule_switch "git reset --merge" + +test_submodule_forced_switch "git reset --hard" + +test_done
Signature · 1 line
2.0.0.275.gc479268
PATCH 7/14 bisect: add t6041 for submodule updates
In reply to Jens LehmannTest that the bisect command updates the work tree as expected. To make that work with the new submodule test framework a git_bisect helper function is added. This adds a commit after the one given to be switched to and makes that one the bad commit. The starting point is then given to bisect as the good commit which makes bisect change the work tree to the commit in between, which is the commit given.
--- t/t6041-bisect-submodule.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 t/t6041-bisect-submodule.sh
t/t6041-bisect-submodule.sh new file +32 -0
@@ -0,0 +1,32 @@ +#!/bin/sh + +test_description='bisect can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +git_bisect () { + git status -su >expected && + ls -1pR * >>expected && + tar czf "$TRASH_DIRECTORY/tmp.tgz" * && + GOOD=$(git rev-parse --verify HEAD) && + git checkout "$1" && + echo "foo" >bar && + git add bar && + git commit -m "bisect bad" && + BAD=$(git rev-parse --verify HEAD) && + git reset --hard HEAD^^ && + git submodule update && + git bisect start && + git bisect good $GOOD && + rm -rf * && + tar xzf "$TRASH_DIRECTORY/tmp.tgz" && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expected actual && + git bisect bad $BAD +} + +test_submodule_switch "git_bisect" + +test_done
Signature · 1 line
2.0.0.275.gc479268
PATCH v2 7/14 bisect: add t6041 for submodule updates
Test that the bisect command updates the work tree as expected. To make that work with the new submodule test framework a git_bisect helper function is added. This adds a commit after the one given to be switched to and makes that one the bad commit. The starting point is then given to bisect as the good commit which makes bisect change the work tree to the commit in between, which is the commit given.
---
Changes to v1:
*) use "expect" instead of "expected"
t/t6041-bisect-submodule.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 t/t6041-bisect-submodule.sh
t/t6041-bisect-submodule.sh new file +32 -0
@@ -0,0 +1,32 @@ +#!/bin/sh + +test_description='bisect can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +git_bisect () { + git status -su >expect && + ls -1pR * >>expect && + tar czf "$TRASH_DIRECTORY/tmp.tgz" * && + GOOD=$(git rev-parse --verify HEAD) && + git checkout "$1" && + echo "foo" >bar && + git add bar && + git commit -m "bisect bad" && + BAD=$(git rev-parse --verify HEAD) && + git reset --hard HEAD^^ && + git submodule update && + git bisect start && + git bisect good $GOOD && + rm -rf * && + tar xzf "$TRASH_DIRECTORY/tmp.tgz" && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expect actual && + git bisect bad $BAD +} + +test_submodule_switch "git_bisect" + +test_done
Signature · 1 line
2.0.0.406.gf4dce28
PATCH 8/14 merge: add t7613 for submodule updates
In reply to Jens LehmannTest that the merge command updates the work tree as expected (for submodule changes which don't result in conflicts) when used without arguments or with the '--ff', '--ff-only' and '--no-ff' flag.
Implement the KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR switch to expect the known failure that --no-ff merges do not create the empty submodule directory.
The KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES switch is also implemented to expect the known failure that --no-ff merges attempt to merge the new files in the former submodule directory with those of the removed submodule.
--- t/lib-submodule-update.sh | 24 +++++++++++++++++++++--- t/t7613-merge-submodule.sh | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100755 t/t7613-merge-submodule.sh
t/lib-submodule-update.sh +21 -3
@@ -275,7 +275,16 @@ test_submodule_switch () { ' # ... as does removing a directory with tracked files with a # submodule. - test_expect_success "$command: replace directory with submodule" ' + if test "$KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR" = 1 + then + # Non fast-forward merges fail with "Directory sub1 doesn't + # exist. sub1" because the empty submodule directory is not + # created + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: replace directory with submodule" ' prolog && reset_work_tree_to replace_sub1_with_directory && (
@@ -318,7 +327,16 @@ test_submodule_switch () { ' # Replacing a submodule with files in a directory must fail as the # submodule work tree isn't removed ... - test_expect_success "$command: replace submodule with a directory must fail" ' + if test "$KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES" = 1 + then + # Non fast-forward merges attempt to merge the former + # submodule files with the newly checked out ones in the + # directory of the same name while it shouldn't. + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: replace submodule with a directory must fail" ' prolog && reset_work_tree_to add_sub1 && (
@@ -330,7 +348,7 @@ test_submodule_switch () { ) ' # ... especially when it contains a .git directory. - test_expect_success "$command: replace submodule containing a .git directory with a directory must fail" ' + test_expect_$RESULT "$command: replace submodule containing a .git directory with a directory must fail" ' prolog && reset_work_tree_to add_sub1 && (
t/t7613-merge-submodule.sh new file +19 -0
@@ -0,0 +1,19 @@ +#!/bin/sh + +test_description='merge can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +# merges without conflicts +test_submodule_switch "git merge" + +test_submodule_switch "git merge --ff" + +test_submodule_switch "git merge --ff-only" + +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1 +test_submodule_switch "git merge --no-ff" + +test_done
Signature · 1 line
2.0.0.275.gc479268
PATCH 9/14 rebase: add t3426 for submodule updates
In reply to Jens LehmannTest that the rebase command updates the work tree as expected for changes which don't result in conflicts. To make that work add two helper functions that add a commit only touching files and then revert it. This allows to rebase the target commit over these two and to compare the result.
Set KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR to document that "replace directory with submodule" fails for an interactive rebase because a directory "sub1" already exists.
--- t/t3426-rebase-submodule.sh | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 t/t3426-rebase-submodule.sh
t/t3426-rebase-submodule.sh new file +46 -0
@@ -0,0 +1,46 @@ +#!/bin/sh + +test_description='rebase can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh +. "$TEST_DIRECTORY"/lib-rebase.sh + +git_rebase () { + git status -su >expected && + ls -1pR * >>expected && + git checkout -b ours HEAD && + echo x >>file1 && + git add file1 && + git commit -m add_x && + git revert HEAD && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expected actual && + git rebase "$1" +} + +test_submodule_switch "git_rebase" + +git_rebase_interactive () { + git status -su >expected && + ls -1pR * >>expected && + git checkout -b ours HEAD && + echo x >>file1 && + git add file1 && + git commit -m add_x && + git revert HEAD && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expected actual && + set_fake_editor && + echo "fake-editor.sh" >.git/info/exclude + git rebase -i "$1" +} + +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +# The real reason "replace directory with submodule" fails is because a +# directory "sub1" exists, but we reuse the suppression added for merge here +test_submodule_switch "git_rebase_interactive" + +test_done
Signature · 1 line
2.0.0.275.gc479268
Re: [PATCH 09/14] rebase: add t3426 for submodule updates
Quoted 49 lines · Jens Lehmann
Test that the rebase command updates the work tree as expected for changes which don't result in conflicts. To make that work add two helper functions that add a commit only touching files and then revert it. This allows to rebase the target commit over these two and to compare the result.
Set
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIRto document that "replace directory with submodule" fails for an interactive rebase because a directory "sub1" already exists.Signed-off-by Jens Lehmann <[email protected]>--- t/t3426-rebase-submodule.sh | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 t/t3426-rebase-submodule.sht/t3426-rebase-submodule.sh new file +27
-0@@ -0,0 +1,46 @@ +#!/bin/sh + +test_description='rebase can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh +. "$TEST_DIRECTORY"/lib-rebase.sh + +git_rebase () { + git status -su >expected && + ls -1pR * >>expected && + git checkout -b ours HEAD && + echo x >>file1 && + git add file1 && + git commit -m add_x && + git revert HEAD && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expected actual && + git rebase "$1" +} + +test_submodule_switch "git_rebase" + +git_rebase_interactive () { + git status -su >expected && + ls -1pR * >>expected &&
t/t3426-rebase-submodule.sh line 37
Quoted 10 lines
t/t3426-rebase-submodule.sh new file +10
-0+ git checkout -b ours HEAD && + echo x >>file1 && + git add file1 && + git commit -m add_x && + git revert HEAD && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expected actual && + set_fake_editor && + echo "fake-editor.sh" >.git/info/exclude
Broken &&-chain.
Quoted 11 lines
t/t3426-rebase-submodule.sh new file +9
-1+ git rebase -i "$1" +} + +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +# The real reason "replace directory with submodule" fails is because a +# directory "sub1" exists, but we reuse the suppression added for merge here +test_submodule_switch "git_rebase_interactive" + +test_done --2.0.0.275.gc479268
Re: [PATCH 09/14] rebase: add t3426 for submodule updates
Am 16.06.2014 11:57, schrieb Eric Sunshine:
Quoted 54 lines · Jens Lehmann
Quoted 53 lines
Test that the rebase command updates the work tree as expected for changes which don't result in conflicts. To make that work add two helper functions that add a commit only touching files and then revert it. This allows to rebase the target commit over these two and to compare the result.
Set
KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIRto document that "replace directory with submodule" fails for an interactive rebase because a directory "sub1" already exists.Signed-off-by Jens Lehmann <[email protected]>--- t/t3426-rebase-submodule.sh | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 t/t3426-rebase-submodule.sht/t3426-rebase-submodule.sh new file +31
-0@@ -0,0 +1,46 @@ +#!/bin/sh + +test_description='rebase can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh +. "$TEST_DIRECTORY"/lib-rebase.sh + +git_rebase () { + git status -su >expected && + ls -1pR * >>expected && + git checkout -b ours HEAD && + echo x >>file1 && + git add file1 && + git commit -m add_x && + git revert HEAD && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expected actual && + git rebase "$1" +} + +test_submodule_switch "git_rebase" + +git_rebase_interactive () { + git status -su >expected && + ls -1pR * >>expected && + git checkout -b ours HEAD && + echo x >>file1 && + git add file1 && + git commit -m add_x &&
Quoted 8 lines
t/t3426-rebase-submodule.sh line 37
Quoted 6 lines
t/t3426-rebase-submodule.sh new file +6
-0+ git revert HEAD && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expected actual && + set_fake_editor && + echo "fake-editor.sh" >.git/info/excludeBroken &&-chain.
Thanks for spotting!
Quoted 16 lines
Quoted 11 lines
t/t3426-rebase-submodule.sh new file +9
-1+ git rebase -i "$1" +} + +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +# The real reason "replace directory with submodule" fails is because a +# directory "sub1" exists, but we reuse the suppression added for merge here +test_submodule_switch "git_rebase_interactive" + +test_done --2.0.0.275.gc479268
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 9/14 rebase: add t3426 for submodule updates
In reply to Jens LehmannTest that the rebase command updates the work tree as expected for changes which don't result in conflicts. To make that work add two helper functions that add a commit only touching files and then revert it. This allows to rebase the target commit over these two and to compare the result.
Set KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR to document that "replace directory with submodule" fails for an interactive rebase because a directory "sub1" already exists.
---
Changes to v1:
*) fix broken &&-chain (you have this as "SQUASH???" commit in pu)
*) use "expect" instead of "expected"
t/t3426-rebase-submodule.sh | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 t/t3426-rebase-submodule.sh
t/t3426-rebase-submodule.sh new file +46 -0
@@ -0,0 +1,46 @@ +#!/bin/sh + +test_description='rebase can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh +. "$TEST_DIRECTORY"/lib-rebase.sh + +git_rebase () { + git status -su >expect && + ls -1pR * >>expect && + git checkout -b ours HEAD && + echo x >>file1 && + git add file1 && + git commit -m add_x && + git revert HEAD && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expect actual && + git rebase "$1" +} + +test_submodule_switch "git_rebase" + +git_rebase_interactive () { + git status -su >expect && + ls -1pR * >>expect && + git checkout -b ours HEAD && + echo x >>file1 && + git add file1 && + git commit -m add_x && + git revert HEAD && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expect actual && + set_fake_editor && + echo "fake-editor.sh" >.git/info/exclude && + git rebase -i "$1" +} + +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +# The real reason "replace directory with submodule" fails is because a +# directory "sub1" exists, but we reuse the suppression added for merge here +test_submodule_switch "git_rebase_interactive" + +test_done
Signature · 1 line
2.0.0.406.gf4dce28
PATCH 10/14 pull: add t5572 for submodule updates
In reply to Jens LehmannTest that the pull command updates the work tree as expected (for submodule changes which don't result in conflicts) when used without arguments or with the '--ff', '--ff-only' and '--no-ff' flag each. Add helper functions to reset the branch to be updated to to the current HEAD so that pull is doing the transition from HEAD to the given branch.
Set KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES and KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR to document that pull has the same --no-ff known failures merge has.
--- t/t5572-pull-submodule.sh | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100755 t/t5572-pull-submodule.sh
t/t5572-pull-submodule.sh new file +45 -0
@@ -0,0 +1,45 @@ +#!/bin/sh + +test_description='pull can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +reset_branch_to_HEAD () { + git branch -D "$1" && + git checkout -b "$1" HEAD && + git branch --set-upstream-to="origin/$1" "$1" +} + +git_pull () { + reset_branch_to_HEAD "$1" && + git pull +} + +# pulls without conflicts +test_submodule_switch "git_pull" + +git_pull_ff () { + reset_branch_to_HEAD "$1" && + git pull --ff +} + +test_submodule_switch "git_pull_ff" + +git_pull_ff_only () { + reset_branch_to_HEAD "$1" && + git pull --ff-only +} + +test_submodule_switch "git_pull_ff_only" + +git_pull_noff () { + reset_branch_to_HEAD "$1" && + git pull --no-ff +} + +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1 +test_submodule_switch "git_pull_noff" + +test_done
Signature · 1 line
2.0.0.275.gba02dd0
PATCH 11/14 cherry-pick: add t3512 for submodule updates
In reply to Jens LehmannTest that the cherry-pick command updates the work tree as expected (for submodule changes which don't result in conflicts).
Set KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES and KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR to document that cherry-pick has the same --no-ff known failures merge has.
Implement the KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT switch to expect the known failure that while cherry picking just a SHA-1 update for an ignored submodule the commit incorrectly fails with "The previous cherry-pick is now empty, possibly due to conflict resolution.".
--- t/lib-submodule-update.sh | 15 ++++++++++++--- t/t3512-cherry-pick-submodule.sh | 13 +++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) create mode 100755 t/t3512-cherry-pick-submodule.sh
t/lib-submodule-update.sh +12 -3
@@ -392,7 +392,16 @@ test_submodule_switch () { ########################## Modified submodule ######################### # Updating a submodule sha1 doesn't update the submodule's work tree - test_expect_success "$command: modified submodule does not update submodule work tree" ' + if test "$KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT" = 1 + then + # When cherry picking a SHA-1 update for an ignored submodule + # the commit incorrectly fails with "The previous cherry-pick + # is now empty, possibly due to conflict resolution." + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: modified submodule does not update submodule work tree" ' prolog && reset_work_tree_to add_sub1 && (
@@ -408,7 +417,7 @@ test_submodule_switch () { # Updating a submodule to an invalid sha1 doesn't update the # submodule's work tree, subsequent update will fail - test_expect_success "$command: modified submodule does not update submodule work tree to invalid commit" ' + test_expect_$RESULT "$command: modified submodule does not update submodule work tree to invalid commit" ' prolog && reset_work_tree_to add_sub1 && (
@@ -423,7 +432,7 @@ test_submodule_switch () { ' # Updating a submodule from an invalid sha1 doesn't update the # submodule's work tree, subsequent update will succeed - test_expect_success "$command: modified submodule does not update submodule work tree from invalid commit" ' + test_expect_$RESULT "$command: modified submodule does not update submodule work tree from invalid commit" ' prolog && reset_work_tree_to invalid_sub1 && (
t/t3512-cherry-pick-submodule.sh new file +13 -0
@@ -0,0 +1,13 @@ +#!/bin/sh + +test_description='cherry-pick can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1 +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1 +test_submodule_switch "git cherry-pick" + +test_done
Signature · 1 line
2.0.0.275.gc479268
PATCH 12/14 am: add t4255 for submodule updates
In reply to Jens LehmannTest that the am command updates the work tree as expected (for submodule changes which don't result in conflicts). To make that work add two helper functions that use format-patch to create the input for am.
Add the KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES switch to expect the known failure that --no-ff merges attempt to merge the new files in the former submodule directory with those of the removed submodule.
--- t/t4255-am-submodule.sh | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100755 t/t4255-am-submodule.sh
t/t4255-am-submodule.sh new file +21 -0
@@ -0,0 +1,21 @@ +#!/bin/sh + +test_description='git am handling submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +am () { + git format-patch --stdout --ignore-submodules=dirty "..$1" | git am - +} + +test_submodule_switch "am" + +am_3way () { + git format-patch --stdout --ignore-submodules=dirty "..$1" | git am --3way - +} + +KNOWN_FAILURE_NOFF_MERGE_ATTEMPTS_TO_MERGE_REMOVED_SUBMODULE_FILES=1 +test_submodule_switch "am_3way" + +test_done
Signature · 1 line
2.0.0.275.gc479268
PATCH 13/14 stash: add t3906 for submodule updates
In reply to Jens LehmannTest that the stash apply command updates the work tree as expected for changes which don't result in conflicts. To make that work add a helper function that uses read-tree to apply the changes of the target commit to the work tree, then stashes these changes and at last applies that stash.
Implement the KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES switch and reuse two other already present switches to expect the known failure that stash does ignore submodule changes.
--- t/lib-submodule-update.sh | 23 ++++++++++++++++++----- t/t3906-stash-submodule.sh | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100755 t/t3906-stash-submodule.sh
t/lib-submodule-update.sh +18 -5
@@ -217,7 +217,14 @@ test_submodule_switch () { command="$1" ######################### Appearing submodule ######################### # Switching to a commit letting a submodule appear creates empty dir ... - test_expect_success "$command: added submodule creates empty directory" ' + if test "$KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES" = 1 + then + # Restoring stash fails to restore submodule index entry + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: added submodule creates empty directory" ' prolog && reset_work_tree_to no_submodule && (
@@ -231,7 +238,7 @@ test_submodule_switch () { ) ' # ... and doesn't care if it already exists ... - test_expect_success "$command: added submodule leaves existing empty directory alone" ' + test_expect_$RESULT "$command: added submodule leaves existing empty directory alone" ' prolog && reset_work_tree_to no_submodule && (
@@ -260,7 +267,7 @@ test_submodule_switch () { ' # Replacing a tracked file with a submodule produces an empty # directory ... - test_expect_success "$command: replace tracked file with submodule creates empty directory" ' + test_expect_$RESULT "$command: replace tracked file with submodule creates empty directory" ' prolog && reset_work_tree_to replace_sub1_with_file && (
@@ -300,7 +307,13 @@ test_submodule_switch () { ######################## Disappearing submodule ####################### # Removing a submodule doesn't remove its work tree ... - test_expect_success "$command: removed submodule leaves submodule directory and its contents in place" ' + if test "$KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES" = 1 + then + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: removed submodule leaves submodule directory and its contents in place" ' prolog && reset_work_tree_to add_sub1 && (
@@ -312,7 +325,7 @@ test_submodule_switch () { ) ' # ... especially when it contains a .git directory. - test_expect_success "$command: removed submodule leaves submodule containing a .git directory alone" ' + test_expect_$RESULT "$command: removed submodule leaves submodule containing a .git directory alone" ' prolog && reset_work_tree_to add_sub1 && (
t/t3906-stash-submodule.sh new file +24 -0
@@ -0,0 +1,24 @@ +#!/bin/sh + +test_description='stash apply can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +git_stash () { + git status -su >expected && + ls -1pR * >>expected && + git read-tree -u -m "$1" && + git stash && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expected actual && + git stash apply +} + +KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES=1 +KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1 +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +test_submodule_switch "git_stash" + +test_done
Signature · 1 line
2.0.0.275.gc479268
PATCH v2 13/14 stash: add t3906 for submodule updates
Test that the stash apply command updates the work tree as expected for changes which don't result in conflicts. To make that work add a helper function that uses read-tree to apply the changes of the target commit to the work tree, then stashes these changes and at last applies that stash.
Implement the KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES switch and reuse two other already present switches to expect the known failure that stash does ignore submodule changes.
---
Changes to v1:
*) use "expect" instead of "expected"
t/lib-submodule-update.sh | 23 ++++++++++++++++++----- t/t3906-stash-submodule.sh | 24 ++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 5 deletions(-) create mode 100755 t/t3906-stash-submodule.sh
t/lib-submodule-update.sh +18 -5
@@ -219,7 +219,14 @@ test_submodule_switch () { command="$1" ######################### Appearing submodule ######################### # Switching to a commit letting a submodule appear creates empty dir ... - test_expect_success "$command: added submodule creates empty directory" ' + if test "$KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES" = 1 + then + # Restoring stash fails to restore submodule index entry + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: added submodule creates empty directory" ' prolog && reset_work_tree_to no_submodule && (
@@ -233,7 +240,7 @@ test_submodule_switch () { ) ' # ... and doesn't care if it already exists ... - test_expect_success "$command: added submodule leaves existing empty directory alone" ' + test_expect_$RESULT "$command: added submodule leaves existing empty directory alone" ' prolog && reset_work_tree_to no_submodule && (
@@ -262,7 +269,7 @@ test_submodule_switch () { ' # Replacing a tracked file with a submodule produces an empty # directory ... - test_expect_success "$command: replace tracked file with submodule creates empty directory" ' + test_expect_$RESULT "$command: replace tracked file with submodule creates empty directory" ' prolog && reset_work_tree_to replace_sub1_with_file && (
@@ -302,7 +309,13 @@ test_submodule_switch () { ######################## Disappearing submodule ####################### # Removing a submodule doesn't remove its work tree ... - test_expect_success "$command: removed submodule leaves submodule directory and its contents in place" ' + if test "$KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES" = 1 + then + RESULT="failure" + else + RESULT="success" + fi + test_expect_$RESULT "$command: removed submodule leaves submodule directory and its contents in place" ' prolog && reset_work_tree_to add_sub1 && (
@@ -314,7 +327,7 @@ test_submodule_switch () { ) ' # ... especially when it contains a .git directory. - test_expect_success "$command: removed submodule leaves submodule containing a .git directory alone" ' + test_expect_$RESULT "$command: removed submodule leaves submodule containing a .git directory alone" ' prolog && reset_work_tree_to add_sub1 && (
t/t3906-stash-submodule.sh new file +24 -0
@@ -0,0 +1,24 @@ +#!/bin/sh + +test_description='stash apply can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +git_stash () { + git status -su >expect && + ls -1pR * >>expect && + git read-tree -u -m "$1" && + git stash && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expect actual && + git stash apply +} + +KNOWN_FAILURE_STASH_DOES_IGNORE_SUBMODULE_CHANGES=1 +KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1 +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +test_submodule_switch "git_stash" + +test_done
Signature · 1 line
2.0.0.406.gf4dce28
PATCH 14/14 revert: add t3513 for submodule updates
In reply to Jens LehmannTest that the revert command updates the work tree as expected (for submodule changes which don't result in conflicts). Add a helper function to first revert the checked out target commit to make the last revert produce the to-be-tested work tree.
Set the KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT and KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR switches to document that revert has the similar failures.
--- t/t3513-revert-submodule.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 t/t3513-revert-submodule.sh
t/t3513-revert-submodule.sh new file +32 -0
@@ -0,0 +1,32 @@ +#!/bin/sh + +test_description='revert can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +# Create a revert that moves from HEAD (including any test modifications to +# the work tree) to $1 by first checking out $1 and reverting it. Reverting +# the revert is the transition we test for. We tar the current work tree +# first so we can restore the work tree test setup after doing the checkout +# and revert. We test here that the restored work tree content is identical +# to that at the beginning. The last revert is then tested by the framework. +git_revert () { + git status -su >expected && + ls -1pR * >>expected && + tar czf "$TRASH_DIRECTORY/tmp.tgz" * && + git checkout "$1" && + git revert HEAD && + rm -rf * && + tar xzf "$TRASH_DIRECTORY/tmp.tgz" && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expected actual && + git revert HEAD +} + +KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1 +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +test_submodule_switch "git_revert" + +test_done
Signature · 1 line
2.0.0.275.gc479268
PATCH v2 14/14 revert: add t3513 for submodule updates
Test that the revert command updates the work tree as expected (for submodule changes which don't result in conflicts). Add a helper function to first revert the checked out target commit to make the last revert produce the to-be-tested work tree.
Set the KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT and KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR switches to document that revert has the similar failures.
---
Changes to v1:
*) use "expect" instead of "expected"
t/t3513-revert-submodule.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100755 t/t3513-revert-submodule.sh
t/t3513-revert-submodule.sh new file +32 -0
@@ -0,0 +1,32 @@ +#!/bin/sh + +test_description='revert can handle submodules' + +. ./test-lib.sh +. "$TEST_DIRECTORY"/lib-submodule-update.sh + +# Create a revert that moves from HEAD (including any test modifications to +# the work tree) to $1 by first checking out $1 and reverting it. Reverting +# the revert is the transition we test for. We tar the current work tree +# first so we can restore the work tree test setup after doing the checkout +# and revert. We test here that the restored work tree content is identical +# to that at the beginning. The last revert is then tested by the framework. +git_revert () { + git status -su >expect && + ls -1pR * >>expect && + tar czf "$TRASH_DIRECTORY/tmp.tgz" * && + git checkout "$1" && + git revert HEAD && + rm -rf * && + tar xzf "$TRASH_DIRECTORY/tmp.tgz" && + git status -su >actual && + ls -1pR * >>actual && + test_cmp expect actual && + git revert HEAD +} + +KNOWN_FAILURE_CHERRY_PICK_SEES_EMPTY_COMMIT=1 +KNOWN_FAILURE_NOFF_MERGE_DOESNT_CREATE_EMPTY_SUBMODULE_DIR=1 +test_submodule_switch "git_revert" + +test_done
Signature · 1 line
2.0.0.406.gf4dce28
(Not sure if this is the right thread)
(I haven't checked if this is fixed in your latest version)
On what I have on pu 7a0da7902cbbc9a876b90c9, Tue Jul 1 14:51:53 2014 -0700
Many submodule tests are broken.
One problem is here:
lib-submodule-update.sh:264: possible problem: echo -n is not portable (please use printf): echo -n >sub1 &&
lib-submodule-update.sh:507: possible problem: echo -n is not portable (please use printf): echo -n >sub1 &&
You can remove the "empty" "echo -n" to create an empty file:
Quoted 1 line
sub1 &&
Am 02.07.2014 16:54, schrieb Torsten Bögershausen:
Quoted 2 lines
(Not sure if this is the right thread)
(I haven't checked if this is fixed in your latest version)
Yes, this is the right thread and no, it isn't fixed yet.
Quoted 10 lines
On what I have on pu
7a0da7902cbbc9a876b90c9, Tue Jul 1 14:51:53 2014 -0700Many submodule tests are broken.
One problem is here:lib-submodule-update.sh:264: possible problem: echo -n is not portable (please use printf): echo -n >sub1 &&
lib-submodule-update.sh:507: possible problem: echo -n is not portable (please use printf): echo -n >sub1 &&You can remove the "empty" "echo -n" to create an empty file:
Quoted 1 line
sub1 &&
Thanks for spotting and diagnosing this. Running "make lint" in the test directory only feeds the tests to check-non-portable-shell.pl, but not the *lib*.sh helper scripts, which made me miss this one.
The following diff should fix it for you. Am I understanding you correctly that you are experiencing other failures too? I see no other incompatibilities when running ./check-non-portable-shell.pl on all the shell scripts in the repo.
-----8<----
t/lib-submodule-update.sh +2 -2
@@ -304,7 +304,7 @@ test_submodule_switch () { ( cd submodule_update && git branch -t add_sub1 origin/add_sub1 && - echo -n >sub1 && + >sub1 && test_must_fail $command add_sub1 && test_superproject_content origin/no_submodule && test_must_be_empty sub1
@@ -547,7 +547,7 @@ test_submodule_forced_switch () { ( cd submodule_update && git branch -t add_sub1 origin/add_sub1 && - echo -n >sub1 && + >sub1 && $command add_sub1 && test_superproject_content origin/add_sub1 && test_dir_is_empty sub1
Signature · 1 line
2.0.1.458.gf680257.dirty
Quoted 15 lines · Jens Lehmann
Am 02.07.2014 16:54, schrieb Torsten Bögershausen:
Quoted 2 lines
(Not sure if this is the right thread)
(I haven't checked if this is fixed in your latest version)Yes, this is the right thread and no, it isn't fixed yet.
Quoted 10 lines
On what I have on pu
7a0da7902cbbc9a876b90c9, Tue Jul 1 14:51:53 2014 -0700Many submodule tests are broken.
One problem is here:lib-submodule-update.sh:264: possible problem: echo -n is not portable (please use printf): echo -n >sub1 &&
lib-submodule-update.sh:507: possible problem: echo -n is not portable (please use printf): echo -n >sub1 &&You can remove the "empty" "echo -n" to create an empty file:
Quoted 1 line
sub1 &&
Quoted 8 lines
Thanks for spotting and diagnosing this. Running "make lint" in the test directory only feeds the tests to check-non-portable-shell.pl, but not the *lib*.sh helper scripts, which made me miss this one.
The following diff should fix it for you. Am I understanding you correctly that you are experiencing other failures too? I see no other incompatibilities when running ./check-non-portable-shell.pl on all the shell scripts in the repo.
The longer story is that I run the test suite once a week or so. Most often under Mac OS, sometimes cygwin or Linux. Whenever there is a breakage under Mac OS which I can not debug within some minutes, I run it under Linux to see if there is the same breakage.
The ./check-non-portable-shell.pl can sometimes give an indication why some test fail.
You can run it from command line:
./check-non-portable-shell.pl *.sh
and it will find the "echo -n" which I reported.
On the longer run it could probably check all *.sh files,
not only the ones under t/
I do not have the time to test the snipped patch below, but I can check pu when the next round of your patch is in and give you some more info.
Am 03.07.2014 07:56, schrieb Torsten Bögershausen:
Quoted 24 lines · Jens Lehmann
Quoted 15 lines
Am 02.07.2014 16:54, schrieb Torsten Bögershausen:
Quoted 2 lines
(Not sure if this is the right thread)
(I haven't checked if this is fixed in your latest version)Yes, this is the right thread and no, it isn't fixed yet.
Quoted 10 lines
On what I have on pu
7a0da7902cbbc9a876b90c9, Tue Jul 1 14:51:53 2014 -0700Many submodule tests are broken.
One problem is here:lib-submodule-update.sh:264: possible problem: echo -n is not portable (please use printf): echo -n >sub1 &&
lib-submodule-update.sh:507: possible problem: echo -n is not portable (please use printf): echo -n >sub1 &&You can remove the "empty" "echo -n" to create an empty file:
Quoted 1 line
sub1 &&
Quoted 8 lines
Thanks for spotting and diagnosing this. Running "make lint" in the test directory only feeds the tests to check-non-portable-shell.pl, but not the *lib*.sh helper scripts, which made me miss this one.
The following diff should fix it for you. Am I understanding you correctly that you are experiencing other failures too? I see no other incompatibilities when running ./check-non-portable-shell.pl on all the shell scripts in the repo.
Quoted 5 lines
The longer story is that I run the test suite once a week or so. Most often under Mac OS, sometimes cygwin or Linux. Whenever there is a breakage under Mac OS which I can not debug within some minutes, I run it under Linux to see if there is the same breakage.
Thanks, that really helps a lot and is more than I could ask for.
Quoted 7 lines
The ./check-non-portable-shell.pl can sometimes give an indication why some test fail.
You can run it from command line:
./check-non-portable-shell.pl *.sh
and it will find the "echo -n" which I reported.
On the longer run it could probably check all *.sh files, not only the ones under t/
That is exactly what I thought when I tried to find out why I missed this. Will cook up a patch to at least check the test helpers too.
Quoted 2 lines
I do not have the time to test the snipped patch below, but I can check pu when the next round of your patch is in and give you some more info.
That'd be great!
Junio, do you want me to resend 02/14 without the non-portable "echo -n" or could you just squash the following diff in?
-----8<----
t/lib-submodule-update.sh +2 -2
@@ -304,7 +304,7 @@ test_submodule_switch () { ( cd submodule_update && git branch -t add_sub1 origin/add_sub1 && - echo -n >sub1 && + >sub1 && test_must_fail $command add_sub1 && test_superproject_content origin/no_submodule && test_must_be_empty sub1
@@ -547,7 +547,7 @@ test_submodule_forced_switch () { ( cd submodule_update && git branch -t add_sub1 origin/add_sub1 && - echo -n >sub1 && + >sub1 && $command add_sub1 && test_superproject_content origin/add_sub1 && test_dir_is_empty sub1
-- 2.0.1.458.gf680257.dirty
Quoted 2 lines · Jens Lehmann
Junio, do you want me to resend 02/14 without the non-portable "echo -n" or could you just squash the following diff in?
Amended locally here already; thanks, both.
Quoted 25 lines
-----8<----
t/lib-submodule-update.sh +2
-3@@ -304,7 +304,7 @@ test_submodule_switch () { ( cd submodule_update && git branch -t add_sub1 origin/add_sub1 && - echo -n >sub1 && + >sub1 && test_must_fail $command add_sub1 && test_superproject_content origin/no_submodule && test_must_be_empty sub1@@ -547,7 +547,7 @@ test_submodule_forced_switch () { ( cd submodule_update && git branch -t add_sub1 origin/add_sub1 && - echo -n >sub1 && + >sub1 && $command add_sub1 && test_superproject_content origin/add_sub1 && test_dir_is_empty sub1 -- 2.0.1.458.gf680257.dirty
Quoted 6 lines · Junio C Hamano
Quoted 2 lines · Jens Lehmann
Junio, do you want me to resend 02/14 without the non-portable "echo -n" or could you just squash the following diff in?
Amended locally here already; thanks, both.
There seems to be some other trouble under Mac OS, not yet fully tracked down, (may be related to the "diff -r")
And Msysgit complains
error: fchmod on c:/xxxt/trash directory.t7613-merge-submodule/submodule_update_repo/.git/modules/sub1/config.lock failed: Function not implemented
Am 07.07.2014 21:40, schrieb Torsten Bögershausen:
Quoted 10 lines · Junio C Hamano
Quoted 6 lines
Quoted 2 lines · Jens Lehmann
Junio, do you want me to resend 02/14 without the non-portable "echo -n" or could you just squash the following diff in?
Amended locally here already; thanks, both.
There seems to be some other trouble under Mac OS, not yet fully tracked down, (may be related to the "diff -r")
Torsten sees failures of this kind under Mac OS:
diff -r .git/modules/sub1/config sub1/.git/config
6d5
< worktree = ../../../sub1
8a8
Quoted 1 line
worktree = ../../../sub1
So the config contains the same content, but the worktree setting moved to a different line. This seems to be the result of setting core.worktree in the test_git_directory_is_unchanged function just before the "diff -r", but only under Mac OS.
Quoted 2 lines
And Msysgit complains
error: fchmod on c:/xxxt/trash directory.t7613-merge-submodule/submodule_update_repo/.git/modules/sub1/config.lock failed: Function not implemented
I'm not sure what this is about, seems to happen during the "cp -R" of the repo under .git/modules into the submodule.
I'm currently investigating both issues (the next steps probably being to install msysgit and to do some Git hacking on a Mac in the family).
Quoted 25 lines · Jens Lehmann
Am 07.07.2014 21:40, schrieb Torsten Bögershausen:
Quoted 10 lines · Junio C Hamano
Quoted 6 lines
Quoted 2 lines · Jens Lehmann
Junio, do you want me to resend 02/14 without the non-portable "echo -n" or could you just squash the following diff in?
Amended locally here already; thanks, both.
There seems to be some other trouble under Mac OS, not yet fully tracked down, (may be related to the "diff -r")
Torsten sees failures of this kind under Mac OS:
diff -r .git/modules/sub1/config sub1/.git/config
6d5
< worktree = ../../../sub1
8a8Quoted 1 line
worktree = ../../../sub1So the config contains the same content, but the worktree setting moved to a different line. This seems to be the result of setting core.worktree in the
test_git_directory_is_unchangedfunction just before the "diff -r", but only under Mac OS.
Quoted 5 lines
Quoted 2 lines
And Msysgit complains
error: fchmod on c:/xxxt/trash directory.t7613-merge-submodule/submodule_update_repo/.git/modules/sub1/config.lock failed: Function not implementedI'm not sure what this is about, seems to happen during the "cp -R" of the repo under .git/modules into the submodule.
I haven't looked into this at all, but from the above message, and noting that fchmod() is not implemented in mingw (see compat/mingw.h line 91), and the following:
$ git grep -n fchmod
compat/mingw.h:91:static inline int fchmod(int fildes, mode_t mode)
config.c:1639: if (fchmod(fd, st.st_mode & 07777) < 0) {
config.c:1640: error("fchmod on %s failed: %s",
config.c:1818: if (fchmod(out_fd, st.st_mode & 07777) < 0) {
config.c:1819: ret = error("fchmod on %s failed: %s",
$ [I happen to be on the pu branch at the moment, so YMMV!]
Both calls to fchmod() above are on config lock files, one in git_config_set_multivar_in_file() and the other in git_config_rename_section_in_file().
ATB,
Ramsay Jones
Quoted 44 lines · Ramsay Jones
Quoted 25 lines · Jens Lehmann
Am 07.07.2014 21:40, schrieb Torsten Bögershausen:
Quoted 10 lines · Junio C Hamano
Quoted 6 lines
Quoted 2 lines · Jens Lehmann
Junio, do you want me to resend 02/14 without the non-portable "echo -n" or could you just squash the following diff in?
Amended locally here already; thanks, both.
There seems to be some other trouble under Mac OS, not yet fully tracked down, (may be related to the "diff -r")
Torsten sees failures of this kind under Mac OS:
diff -r .git/modules/sub1/config sub1/.git/config
6d5
< worktree = ../../../sub1
8a8Quoted 1 line
worktree = ../../../sub1So the config contains the same content, but the worktree setting moved to a different line. This seems to be the result of setting core.worktree in the
test_git_directory_is_unchangedfunction just before the "diff -r", but only under Mac OS.Quoted 5 lines
Quoted 2 lines
And Msysgit complains
error: fchmod on c:/xxxt/trash directory.t7613-merge-submodule/submodule_update_repo/.git/modules/sub1/config.lock failed: Function not implementedI'm not sure what this is about, seems to happen during the "cp -R" of the repo under .git/modules into the submodule.
I haven't looked into this at all, but from the above message, and noting that
fchmod()is not implemented in mingw (seecompat/mingw.hline 91), and the following:$ git grep -n fchmod compat/mingw.h:91:static inline int fchmod(int fildes, mode_t mode) config.c:1639: if (fchmod(fd, st.st_mode & 07777) < 0) { config.c:1640: error("fchmod on %s failed: %s", config.c:1818: if (fchmod(out_fd, st.st_mode & 07777) < 0) { config.c:1819: ret = error("fchmod on %s failed: %s", $
Quoted 6 lines
[I happen to be on the pu branch at the moment, so YMMV!]
Both calls to
fchmod()above are on config lock files, one ingit_config_set_multivar_in_file()and the other ingit_config_rename_section_in_file().
See commit daa22c6f8 ("config: preserve config file permissions on edits", 06-05-2014).
ATB,
Ramsay Jones
No fchmod() under msygit - Was: Re: [PATCH 00/14] Add submodule test harness
In reply to Ramsay JonesQuoted 44 lines · Ramsay Jones
Quoted 21 lines · Jens Lehmann
Am 07.07.2014 21:40, schrieb Torsten Bögershausen:
Quoted 8 lines · Junio C Hamano
Quoted 5 lines
Quoted 2 lines · Jens Lehmann
Junio, do you want me to resend 02/14 without the non-portable "echo -n" or could you just squash the following diff in?
Amended locally here already; thanks, both.
There seems to be some other trouble under Mac OS, not yet fully tracked down, (may be related to the "diff -r")
Torsten sees failures of this kind under Mac OS:
diff -r .git/modules/sub1/config sub1/.git/config
6d5
< worktree = ../../../sub1
8a8Quoted 1 line
worktree = ../../../sub1So the config contains the same content, but the worktree setting moved to a different line. This seems to be the result of setting core.worktree in the
test_git_directory_is_unchangedfunction just before the "diff -r", but only under Mac OS.Quoted 4 lines
Quoted 2 lines
And Msysgit complains
error: fchmod on c:/xxxt/trash directory.t7613-merge-submodule/submodule_update_repo/.git/modules/sub1/config.lock failed: Function not implementedI'm not sure what this is about, seems to happen during the "cp -R" of the repo under .git/modules into the submodule.
I haven't looked into this at all, but from the above message, and noting that
fchmod()is not implemented in mingw (seecompat/mingw.hline 91), and the following:$ git grep -n fchmodcommit daa22c6f8da466bd7a438f1bc27375fd737ffcf3 Author: Eric Wong <[email protected]> Date: Tue May 6 00:17:14 2014 +0000config: preserve config file permissions on edits
compat/mingw.h:91:static inline int
fchmod(int fildes, mode_t mode)
config.c:1639: if (fchmod(fd, st.st_mode & 07777)< 0) {
config.c:1640: error("fchmod on %s failed: %s",
config.c:1818: if (fchmod(out_fd, st.st_mode & 07777)< 0) {
config.c:1819: ret = error("fchmod on %s failed: %s",
$
Quoted 7 lines
[I happen to be on the pu branch at the moment, so YMMV!]
Both calls to
fchmod()above are on config lock files, one ingit_config_set_multivar_in_file()and the other ingit_config_rename_section_in_file().
commit daa22c6f8da466bd7a438f1bc27375fd737ffcf3
Author: Eric Wong <[email protected]> Date: Tue May 6 00:17:14 2014 +0000
config: preserve config file permissions on edits
(And why is it "& 07777" and not "& 0777")
Can we avoid the fchmod() all together ?
Re: No fchmod() under msygit - Was: Re: [PATCH 00/14] Add submodule test harness
Quoted 1 line · Torsten Bögershausen
(And why is it "& 07777" and not "& 0777")
This is to preserve the uncommon sticky/sgid/suid bits. Probably not needed, but better to keep as much intact as possible.
Quoted 1 line
Can we avoid the
fchmod()all together ?
For single-user systems, sure.
For multi-user systems with git-imap-send users and passwords in $GIT_CONFIG, I suggest not.
Re: No fchmod() under msygit - Was: Re: [PATCH 00/14] Add submodule test harness
Quoted 6 lines · Eric Wong
Quoted 1 line · Torsten Bögershausen
(And why is it "& 07777" and not "& 0777")
This is to preserve the uncommon sticky/sgid/suid bits. Probably not needed, but better to keep as much intact as possible.
Quoted 6 lines
Quoted 1 line
Can we avoid the
fchmod()all together ?For single-user systems, sure.
For multi-user systems with git-imap-send users and passwords in $GIT_CONFIG, I suggest not.
You're saying this as if Windows is a single-user system. It's not, but it uses ACLs rather than POSIX permissions to manage file-system permissions. So far we've opted to ignore ACLs in Git for Windows, though.
Re: No fchmod() under msygit - Was: Re: [PATCH 00/14] Add submodule test harness
Quoted 8 lines · Erik Faye-Lund
Quoted 2 lines · Eric Wong
Torsten Bögershausen <[email protected]> wrote:
You're saying this as if Windows is a single-user system. It's not, but it uses ACLs rather than POSIX permissions to manage file-system permissions. So far we've opted to ignore ACLs in Git for Windows, though.
The clever thing to do (that some versions of ZFS do nowadays) is to use the new mask to "edit" the ACL as follows:
- leave any DENY ACEs as-is; for all others continue
- remove (reset) from any ACEs for Everyone (and/or Authenticated
Users) any bits corresponding to zero'ed bits in the new mask's other bits
- remove from any other ACEs that are not for the owner (@OWNER in
NFSv4 speak) any bits corresponding to zero'ed bits in the new mask's group bits
- remove from the owner's ACEs any bits corresponding to zero'ed bits
in the new mask's owner bits, but with some exceptions, in particular the owner must retain the right to edit the ACL
- add (set) to the Everyone (and/or Authenticated Users) ACEs a set
of bits corresponding to the set bits in the new mask's other bits
- add (set) either only to the ACE for the file's group
(alternatively, to all non-owner, non-Everyone/Authenticated Users ACEs) a set of bits corresponding to the set bits in the new mask's group bits
...
I.e., use the chmod mask to decrease/increase access without changing the "shape" of the ACL.
Determining a file's mode_t from an ACL is similar, though it must take DENY entries into account: make a set of users/groups referred to by any ACEs in the ACL, divide them into owner, other (Everyone and/or Authenticated Users), and group (all others), find the maximal access granted.
Still, git might like to know what ACLs to apply to files at checkout time. That would be a vast new feature, I think, and probably not worth it, particularly since that would require dealing with the different types of ACLs: NTFS/NFSv4/ZFS on the one hand, POSIX Draft on the other, plus AFS and who knows what else -- ETOOMUCH IMO.
Nico
--
Re: No fchmod() under msygit - Was: Re: [PATCH 00/14] Add submodule test harness
Quoted 5 lines
Still, git might like to know what ACLs to apply to files at checkout time. That would be a vast new feature, I think, and probably not worth it, particularly since that would require dealing with the different types of ACLs: NTFS/NFSv4/ZFS on the one hand, POSIX Draft on the other, plus AFS and who knows what else -- ETOOMUCH IMO.
To complete that thought...
Inheritable ACLs + chmod should suffice. The user should setup inheritable ACLs for the directory where a repo is to be cloned, then on checkout git should just apply mode changes in such a way as to leave ACL "shapes" unchanged, only adding or removing bits from non-DENY ACEs according to the saved file modes.
Inheritable ACEs should be left as-is, since git doesn't track directory permissions (right?), or if it did, then those should be edited just like normal ACEs.
Nico
--
Re: No fchmod() under msygit - Was: Re: [PATCH 00/14] Add submodule test harness
In reply to Eric WongAm 09.07.2014 22:00, schrieb Eric Wong:
Quoted 8 lines
Quoted 1 line · Torsten Bögershausen
(And why is it "& 07777" and not "& 0777")
This is to preserve the uncommon sticky/sgid/suid bits. Probably not needed, but better to keep as much intact as possible.
Quoted 1 line
Can we avoid the
fchmod()all together ?
Quoted 9 lines
For single-user systems, sure.
For multi-user systems with git-imap-send users and passwords in $GIT_CONFIG, I suggest not.
--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
The Windows fchmod() problem is easily solved by using chmod() instead of fchmod(). The file name is known in both cases (and even used in the error message).
However, IMO there are more fundamental problems with your patch (not related to Windows):
1.) Permissions of files in .git are controlled by the core.sharedRepository setting, and your patch seems to break that (i.e. if someone accidentally has made .git/config world readable, git-config no longer fixes that, even if core.sharedRepository=0600).
2.) Sensitive data such as passwords doesn't belong in config files in the first place, that's what git-credentials is good for.
Re: No fchmod() under msygit - Was: Re: [PATCH 00/14] Add submodule test harness
Quoted 4 lines · Karsten Blees
1.) Permissions of files in .git are controlled by the core.sharedRepository setting, and your patch seems to break that (i.e. if someone accidentally has made .git/config world readable, git-config no longer fixes that, even if core.sharedRepository=0600).
For any repository, when you further run "git config" to update it, .git/config always exists with the permission bits initialized when "git init" was run there. And Eric's change is to propagate that same bits to a new file, so there wouldn't be any difference, no?
And $HOME/.gitconfig should not be governed by "sharedRepository", and that was the primary focus of Eric's change, I would think.
Quoted 9 lines
Quoted 3 lines
There seems to be some other trouble under Mac OS, not yet fully tracked down, (may be related to the "diff -r")
Torsten sees failures of this kind under Mac OS:
diff -r .git/modules/sub1/config sub1/.git/config
6d5
< worktree = ../../../sub1
8a8
Quoted 6 lines
Quoted 1 line
worktree = ../../../sub1So the config contains the same content, but the worktree setting moved to a different line. This seems to be the result of setting core.worktree in the
test_git_directory_is_unchangedfunction just before the "diff -r", but only under Mac OS.
So I was suspecting diff -r beinng non-portable, but that doesn't seem to be the problem here. (But I wouldn't be surprised if there where problems with diff -r on some Unix systems) Anyway, checking all the files in the working tree seems to be a good thing to do, but that does not necessarily work for .git/config.
A "brute force" approach could be to simply run the config file(s) through sort and compare them:
sort <.git/modules/sub1/config >expect &&
sort <sub1/.git/config >actual &&test_cmp expect actual &&
rm expect actual &&
cp git/modules/sub1/config sub1/.git/config
[end of scriptlet]
And here the "dumps" of the 2 config files:
.......
Branch remove_sub1 set up to track remote branch remove_sub1 from origin.
warning: unable to rmdir sub1: Directory not empty
Updating 68c8810..81b9f6a
Fast-forward
.gitmodules | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .gitmodules
---------------------
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
worktree = ../../../sub1
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = /Users/tb/projects/git/tb.140704_JensLehman/t/trash
directory.t7613-merge-submodule/submodule_update_repo/.
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
----------------
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
worktree = ../../../sub1
[remote "origin"]
url = /Users/tb/projects/git/tb.140704_JensLehman/t/trash
directory.t7613-merge-submodule/submodule_update_repo/.
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
=====================
diff -r .git/modules/sub1/config sub1/.git/config 6d5
< worktree = ../../../sub1
8a8
Quoted 1 line
worktree = ../../../sub1
not ok 7 - git merge: removed submodule leaves submodule containing a .git directory alone
Am 09.07.2014 08:14, schrieb Torsten Bögershausen:
Quoted 15 lines
Quoted 9 lines
Quoted 3 lines
There seems to be some other trouble under Mac OS, not yet fully tracked down, (may be related to the "diff -r")
Torsten sees failures of this kind under Mac OS:
diff -r .git/modules/sub1/config sub1/.git/config
6d5
< worktree = ../../../sub1
8a8Quoted 6 lines
Quoted 1 line
worktree = ../../../sub1So the config contains the same content, but the worktree setting moved to a different line. This seems to be the result of setting core.worktree in the
test_git_directory_is_unchangedfunction just before the "diff -r", but only under Mac OS.
Quoted 4 lines
So I was suspecting diff -r beinng non-portable, but that doesn't seem to be the problem here. (But I wouldn't be surprised if there where problems with diff -r on some Unix systems) Anyway, checking all the files in the working tree seems to be a good thing to do, but that does not necessarily work for .git/config.
I agree, but this case is special. The test asserts that nobody added, modified or removed *anything* inside the .git directory. The reason for problem we are seeing here is that I have to remove the core.worktree setting when moving the git directory from .git/modules into the submodule work tree. So the test adds it again to be able to diff it, and this happens in a different line only on Mac OS as comparing the two core sections shows:
Quoted 10 lines
---------------------
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
worktree = ../../../sub1
ignorecase = true
precomposeunicode = true
[remote "origin"]
vs.
Quoted 10 lines
----------------
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
worktree = ../../../sub1
[remote "origin"]
And now it's clear what happens here: On Mac OS the ignorecase and precomposeunicode settings are added behind the worktree line, then re-adding worktree later for the comparison adds it after these two.
Could you please test the following? It should avoid this kind of problem by removing the core.worktree setting temporarily from the original config in .git/modules instead of adding it temporarily to .git/config:
-----------------------8<-----------------------
t/lib-submodule-update.sh +5 -5
@@ -143,18 +143,18 @@ replace_gitfile_with_git_dir () { } # Test that the .git directory in the submodule is unchanged (except for the -# core.worktree setting, which we temporarily restore). Call this function +# core.worktree setting, which we temporarily remove). Call this function # before test_submodule_content as the latter might write the index file # leading to false positive index differences. test_git_directory_is_unchanged () { ( - cd "$1" && - git config core.worktree "../../../$1" + cd ".git/modules/$1" && + git config --unset core.worktree ) && diff -r ".git/modules/$1" "$1/.git" && ( - cd "$1" && - GIT_WORK_TREE=. git config --unset core.worktree + cd ".git/modules/$1" && + git config core.worktree "../../../$1" ) }
Quoted 5 lines · Jens Lehmann
I agree, but this case is special. The test asserts that nobody added, modified or removed *anything* inside the .git directory. The reason for problem we are seeing here is that I have to remove the core.worktree setting when moving the git directory from .git/modules into the submodule work tree.
Hmph. Comparing the files with core.worktree removed sounds like a workaround that knows too much about the implementation detail of what is being tested. I am just wondering if core.worktree will stay forever be the only thing that is special, or there may come other things (perhaps as a fallout of integrating things like Duy's multiple-worktree stuff).
But perhaps we cannot do better than this.
Quoted 32 lines
Could you please test the following? It should avoid this kind of problem by removing the core.worktree setting temporarily from the original config in .git/modules instead of adding it temporarily to .git/config:
-----------------------8<-----------------------t/lib-submodule-update.sh +5
-5@@ -143,18 +143,18 @@ replace_gitfile_with_git_dir () { } # Test that the .git directory in the submodule is unchanged (except for the -# core.worktree setting, which we temporarily restore). Call this function +# core.worktree setting, which we temporarily remove). Call this function # before test_submodule_content as the latter might write the index file # leading to false positive index differences. test_git_directory_is_unchanged () { ( - cd "$1" && - git config core.worktree "../../../$1" + cd ".git/modules/$1" && + git config --unset core.worktree ) && diff -r ".git/modules/$1" "$1/.git" && ( - cd "$1" && - GIT_WORK_TREE=. git config --unset core.worktree + cd ".git/modules/$1" && + git config core.worktree "../../../$1" ) }
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Jens Lehmann
I agree, but this case is special. The test asserts that nobody added, modified or removed *anything* inside the .git directory. The reason for problem we are seeing here is that I have to remove the core.worktree setting when moving the git directory from .git/modules into the submodule work tree.
Quoted 8 lines
Hmph. Comparing the files with core.worktree removed sounds like a workaround that knows too much about the implementation detail of what is being tested. I am just wondering if core.worktree will stay forever be the only thing that is special, or there may come other things (perhaps as a fallout of integrating things like Duy's multiple-worktree stuff).
But perhaps we cannot do better than this.
One thing we should be able to do (and must do) better is to validate that core.worktree in the relocated config file actually points at the right place. Unsetting before comparing may let us compare the relocated one in .git/modules/$1/config with the one that is embedded in the working tree (hence no .git/config), but the way your "how about this?" patch does, we wouldn't catch a possible breakage to the relocation code to point core.worktree to a bogus location, I'm afraid.
Perhaps squashing this to 7e8e5af9 instead?
t/lib-submodule-update.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)
t/lib-submodule-update.sh +12 -7
@@ -110,18 +110,23 @@ replace_gitfile_with_git_dir () { } # Test that the .git directory in the submodule is unchanged (except for the -# core.worktree setting, which we temporarily restore). Call this function -# before test_submodule_content as the latter might write the index file -# leading to false positive index differences. +# core.worktree setting, which appears only in $GIT_DIR/modules/$1/config). +# Call this function before test_submodule_content as the latter might +# write the index file leading to false positive index differences. test_git_directory_is_unchanged () { ( - cd "$1" && - git config core.worktree "../../../$1" + cd ".git/modules/$1" && + # does core.worktree point at the right place? + test "$(git config core.worktree)" = "../../../$1" && + # remove it temporarily before comparing, as + # "$1/.git/config" lacks it... + git config --unset core.worktree ) && diff -r ".git/modules/$1" "$1/.git" && ( - cd "$1" && - GIT_WORK_TREE=. git config --unset core.worktree + # ... and then restore. + cd ".git/modules/$1" && + git config core.worktree "../../../$1" ) }
Am 10.07.2014 22:52, schrieb Junio C Hamano:
Quoted 19 lines
Quoted 8 lines · Junio C Hamano
Quoted 5 lines · Jens Lehmann
I agree, but this case is special. The test asserts that nobody added, modified or removed *anything* inside the .git directory. The reason for problem we are seeing here is that I have to remove the core.worktree setting when moving the git directory from .git/modules into the submodule work tree.
Quoted 8 lines
Hmph. Comparing the files with core.worktree removed sounds like a workaround that knows too much about the implementation detail of what is being tested. I am just wondering if core.worktree will stay forever be the only thing that is special, or there may come other things (perhaps as a fallout of integrating things like Duy's multiple-worktree stuff).
But perhaps we cannot do better than this.
Quoted 8 lines
One thing we should be able to do (and must do) better is to validate that core.worktree in the relocated config file actually points at the right place. Unsetting before comparing may let us compare the relocated one in .git/modules/$1/config with the one that is embedded in the working tree (hence no .git/config), but the way your "how about this?" patch does, we wouldn't catch a possible breakage to the relocation code to point core.worktree to a bogus location, I'm afraid.
Indeed.
Quoted 1 line
Perhaps squashing this to
7e8e5af9instead?
Yes please, this is much better than my first attempt.
Quoted 39 lines
t/lib-submodule-update.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)t/lib-submodule-update.sh +12
-7@@ -110,18 +110,23 @@ replace_gitfile_with_git_dir () { } # Test that the .git directory in the submodule is unchanged (except for the -# core.worktree setting, which we temporarily restore). Call this function -# before test_submodule_content as the latter might write the index file -# leading to false positive index differences. +# core.worktree setting, which appears only in $GIT_DIR/modules/$1/config). +# Call this function before test_submodule_content as the latter might +# write the index file leading to false positive index differences. test_git_directory_is_unchanged () { ( - cd "$1" && - git config core.worktree "../../../$1" + cd ".git/modules/$1" && + # does core.worktree point at the right place? + test "$(git config core.worktree)" = "../../../$1" && + # remove it temporarily before comparing, as + # "$1/.git/config" lacks it... + git config --unset core.worktree ) && diff -r ".git/modules/$1" "$1/.git" && ( - cd "$1" && - GIT_WORK_TREE=. git config --unset core.worktree + # ... and then restore. + cd ".git/modules/$1" && + git config core.worktree "../../../$1" ) }
Quoted 3 lines · Jens Lehmann
Quoted 1 line
Perhaps squashing this to
7e8e5af9instead?Yes please, this is much better than my first attempt.
One thing that I found troubling is the ../../../ "three levels up" is hardcoded. Would it be always true for any value of "$1"? If the submodule is bound to the superproject at sub/dir/, not at dir/, for example, would it have to change?
I am not saying that we must support artibrary cases, but if there is such a limitation in the implementation, people who will use the helper in their new tests want it at least documented, I think.
Quoted 39 lines
Quoted 39 lines
t/lib-submodule-update.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)t/lib-submodule-update.sh +12
-7@@ -110,18 +110,23 @@ replace_gitfile_with_git_dir () { } # Test that the .git directory in the submodule is unchanged (except for the -# core.worktree setting, which we temporarily restore). Call this function -# before test_submodule_content as the latter might write the index file -# leading to false positive index differences. +# core.worktree setting, which appears only in $GIT_DIR/modules/$1/config). +# Call this function before test_submodule_content as the latter might +# write the index file leading to false positive index differences. test_git_directory_is_unchanged () { ( - cd "$1" && - git config core.worktree "../../../$1" + cd ".git/modules/$1" && + # does core.worktree point at the right place? + test "$(git config core.worktree)" = "../../../$1" && + # remove it temporarily before comparing, as + # "$1/.git/config" lacks it... + git config --unset core.worktree ) && diff -r ".git/modules/$1" "$1/.git" && ( - cd "$1" && - GIT_WORK_TREE=. git config --unset core.worktree + # ... and then restore. + cd ".git/modules/$1" && + git config core.worktree "../../../$1" ) }
Am 14.07.2014 03:01, schrieb Junio C Hamano:
Quoted 10 lines
Quoted 3 lines · Jens Lehmann
Quoted 1 line
Perhaps squashing this to
7e8e5af9instead?Yes please, this is much better than my first attempt.
One thing that I found troubling is the ../../../ "three levels up" is hardcoded. Would it be always true for any value of "$1"? If the submodule is bound to the superproject at sub/dir/, not at dir/, for example, would it have to change?
Yes. And the code currently also doesn't handle submodules whose name and path differ.
Quoted 3 lines
I am not saying that we must support artibrary cases, but if there is such a limitation in the implementation, people who will use the helper in their new tests want it at least documented, I think.
Ah, I didn't think about other tests reusing that and only wrote this as a local helper. But you're right, it would make sense to reuse this function instead of coding that again (even though I'd prefer to extract the generic helpers to t/lib-submodule.sh for that purpose).
So what about adding "Currently only submodules living in the root directory of the superproject with the default name (same as the path) are supported." to the comment above the function?
Quoted 40 lines
Quoted 39 lines
Quoted 39 lines
t/lib-submodule-update.sh | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-)t/lib-submodule-update.sh +12
-7@@ -110,18 +110,23 @@ replace_gitfile_with_git_dir () { } # Test that the .git directory in the submodule is unchanged (except for the -# core.worktree setting, which we temporarily restore). Call this function -# before test_submodule_content as the latter might write the index file -# leading to false positive index differences. +# core.worktree setting, which appears only in $GIT_DIR/modules/$1/config). +# Call this function before test_submodule_content as the latter might +# write the index file leading to false positive index differences. test_git_directory_is_unchanged () { ( - cd "$1" && - git config core.worktree "../../../$1" + cd ".git/modules/$1" && + # does core.worktree point at the right place? + test "$(git config core.worktree)" = "../../../$1" && + # remove it temporarily before comparing, as + # "$1/.git/config" lacks it... + git config --unset core.worktree ) && diff -r ".git/modules/$1" "$1/.git" && ( - cd "$1" && - GIT_WORK_TREE=. git config --unset core.worktree + # ... and then restore. + cd ".git/modules/$1" && + git config core.worktree "../../../$1" ) }
Quoted 3 lines · Jens Lehmann
So what about adding "Currently only submodules living in the root directory of the superproject with the default name (same as the path) are supported." to the comment above the function?
OK, done, and merged to 'next'.
Thanks.
Quoted 6 lines · Torsten Bögershausen
A "brute force" approach could be to simply run the config file(s) through sort and compare them:
sort <.git/modules/sub1/config >expect &&
sort <sub1/.git/config >actual &&test_cmpexpect actual &&
Or "git config --list" from these files, perhaps?
Am 08.07.2014 21:34, schrieb Jens Lehmann:
Quoted 5 lines
Quoted 2 lines
And Msysgit complains
error: fchmod on c:/xxxt/trash directory.t7613-merge-submodule/submodule_update_repo/.git/modules/sub1/config.lock failed: Function not implementedI'm not sure what this is about, seems to happen during the "cp -R" of the repo under .git/modules into the submodule.
No. It happens because fchmod() is not implemented in our Windows port.
Please see my band-aid patch at
http://thread.gmane.org/gmane.comp.version-control.git/248154/focus=20266
The sub-thread ended inconclusive.
-- Hannes
Quoted 4 lines · Johannes Sixt
Am 08.07.2014 21:34, schrieb Jens Lehmann:
Quoted 3 lines
Quoted 2 lines
And Msysgit complains
error: fchmod on c:/xxxt/trash directory.t7613-merge-submodule/submodule_update_repo/.git/modules/sub1/config.lock failed: Function not implemented
Quoted 8 lines
Quoted 2 lines
I'm not sure what this is about, seems to happen during the "cp -R" of the repo under .git/modules into the submodule.
No. It happens because
fchmod()is not implemented in our Windows port.Please see my band-aid patch at
http://thread.gmane.org/gmane.comp.version-control.git/248154/focus=20266
The sub-thread ended inconclusive.
We need to start somewhere, and a no-op fchmod() in your patch may be as a good place to start as anything. At least we would then keep the old behaviour without introducing any new failure.
An alternative might be to use chmod() after we are done writing to the config.lock in order to avoid the use of fchmod() altogether, which I think can replace the existing two callsites of fchmod(). That approach might be a more expedient, but may turn out to be undesirable in the longer term.
I also wonder if this "carry forward the original permission bits when updating an existing file by first writing the updated contents into a lockfile and then renaming it after we are done" pattern ought to be done in the lockfile API at commit_lock_file() time (Duy and Michael Cc'ed for their input, as they have recently touched lockfile API implementation in their series somewhat), not at the level of the user of the lockfile API like Eric's patch daa22c6f (config: preserve config file permissions on edits, 2014-05-06) did only for the config file.
Quoted 10 lines · Junio C Hamano
Quoted 9 lines · Johannes Sixt
Am 08.07.2014 21:34, schrieb Jens Lehmann:
Quoted 5 lines
Quoted 2 lines
And Msysgit complains
error: fchmod on c:/xxxt/trash directory.t7613-merge-submodule/submodule_update_repo/.git/modules/sub1/config.lock failed: Function not implementedI'm not sure what this is about, seems to happen during the "cp -R" of the repo under .git/modules into the submodule.
No. It happens because
fchmod()is not implemented in our Windows port.
Quoted 7 lines
Quoted 3 lines
Please see my band-aid patch at
http://thread.gmane.org/gmane.comp.version-control.git/248154/focus=20266
The sub-thread ended inconclusive.We need to start somewhere, and a no-op
fchmod()in your patch may be as a good place to start as anything. At least we would then keep the old behaviour without introducing any new failure.
Right, this likely makes the most sense for single-user systems or systesm without a *nix-like permission system.
Quoted 5 lines
An alternative might be to use
chmod()after we are done writing to the config.lock in order to avoid the use offchmod()altogether, which I think can replace the existing two callsites offchmod(). That approach might be a more expedient, but may turn out to be undesirable in the longer term.
In that case, we would need to open with mode=0600 to avoid a window where the file may be world-readable with any data in it.
Quoted 22 lines · Eric Wong
Quoted 10 lines · Junio C Hamano
Quoted 9 lines · Johannes Sixt
Am 08.07.2014 21:34, schrieb Jens Lehmann:
Quoted 5 lines
Quoted 2 lines
And Msysgit complains
error: fchmod on c:/xxxt/trash directory.t7613-merge-submodule/submodule_update_repo/.git/modules/sub1/config.lock failed: Function not implementedI'm not sure what this is about, seems to happen during the "cp -R" of the repo under .git/modules into the submodule.
No. It happens because
fchmod()is not implemented in our Windows port.Quoted 7 lines
Quoted 3 lines
Please see my band-aid patch at
http://thread.gmane.org/gmane.comp.version-control.git/248154/focus=20266
The sub-thread ended inconclusive.We need to start somewhere, and a no-op
fchmod()in your patch may be as a good place to start as anything. At least we would then keep the old behaviour without introducing any new failure.Right, this likely makes the most sense for single-user systems or systesm without a *nix-like permission system.
Quoted 8 lines
Quoted 5 lines
An alternative might be to use
chmod()after we are done writing to the config.lock in order to avoid the use offchmod()altogether, which I think can replace the existing two callsites offchmod(). That approach might be a more expedient, but may turn out to be undesirable in the longer term.In that case, we would need to open with mode=0600 to avoid a window where the file may be world-readable with any data in it.
Yes, of course.
To elaborate what I was alluding to at the end of the message you are responding to a bit more, if we were to move this "grab perms from existing file (if there is any) and propagate to the new one" into the lockfile API,
- in hold_lock_file_for_update(), we would record the permission of the original file, if any, to a new field in "struct lock_file";
- open with 0600 or tighter in lock_file(), and
- either before closing the file use fchmod() or after closing and moving the file use chmod() to propagate the permission.
If the original did not exist, we would pass 0666 to open as before in lock_file() and do not bother chmod/fchmod at the end.
Or something like that, perhaps.
No fchmd. was: Re: [PATCH 00/14] Add submodule test harness
Quoted 38 lines · Junio C Hamano
Quoted 18 lines · Eric Wong
Quoted 6 lines · Junio C Hamano
Quoted 5 lines · Johannes Sixt
Am 08.07.2014 21:34, schrieb Jens Lehmann:
Quoted 4 lines
Quoted 2 lines
And Msysgit complains
error: fchmod on c:/xxxt/trash directory.t7613-merge-submodule/submodule_update_repo/.git/modules/sub1/config.lock failed: Function not implementedI'm not sure what this is about, seems to happen during the "cp -R" of the repo under .git/modules into the submodule.
Quoted 8 lines
Quoted 5 lines
No. It happens because
fchmod()is not implemented in our Windows port.Please see my band-aid patch at
http://thread.gmane.org/gmane.comp.version-control.git/248154/focus=20266
The sub-thread ended inconclusive.We need to start somewhere, and a no-op
fchmod()in your patch may be as a good place to start as anything. At least we would then keep the old behaviour without introducing any new failure.Right, this likely makes the most sense for single-user systems or systesm without a *nix-like permission system.
Quoted 7 lines
Quoted 5 lines
An alternative might be to use
chmod()after we are done writing to the config.lock in order to avoid the use offchmod()altogether, which I think can replace the existing two callsites offchmod(). That approach might be a more expedient, but may turn out to be undesirable in the longer term.In that case, we would need to open with mode=0600 to avoid a window where the file may be world-readable with any data in it.
Yes, of course.
To elaborate what I was alluding to at the end of the message you are responding to a bit more, if we were to move this "grab perms from existing file (if there is any) and propagate to the new one" into the lockfile API,
- in
hold_lock_file_for_update(), we would record the permission ofthe original file, if any, to a new field in "struct lock_file";- open with 0600 or tighter in
lock_file(), and
Quoted 7 lines
- either before closing the file use
fchmod()or after closing and moving the file usechmod()to propagate the permission.If the original did not exist, we would pass 0666 to open as before in
lock_file()and do not bother chmod/fchmod at the end.Or something like that, perhaps.
Isn't the whole problem starting here:
in config.c:
fd = hold_lock_file_for_update(lock, config_filename, 0);
In lockfile.c:
/* This should return a meaningful errno on failure */
int hold_lock_file_for_update(struct lock_file *lk, const char *path,
int flags)
{
int fd = lock_file(lk, path, flags);
which leads to
static int lock_file(struct lock_file *lk, const char *path, int flags)
[]
lk->fd = open(lk->filename.buf, O_RDWR | O_CREAT | O_EXCL, 0666);There is no way to tell which permissions the new lockfile should have. That is somewhat unlucky.
On the other hand, shouldn't we call adjust_shared_perm(const char *path) from path.c on the config file?
And to all files which are fiddled through the lock_file API?
In other words, the lockfile could be created with the restrictive permissions 600, and once the lockfile had been closed and renamed into the final name we apply adjust_shared_perm() on it ?
Or probably directly after close() ?
I think there are 2 different things missing here:
- Be able to specify permissions to hold_lock_file_for_update(), especially restrictive ones, like 600 and not 666.
- Adjust the permissions for "shared files" in a shared repo. This is probably needed for a shared repo, when the user itself has a umask which is too restrictive and adjust_shared_perm() must be run to widen the permissions.
Do I miss something ?
Re: No fchmd. was: Re: [PATCH 00/14] Add submodule test harness
Quoted 8 lines · Torsten Bögershausen
Isn't the whole problem starting here:
inconfig.c:fd = hold_lock_file_for_update(lock, config_filename, 0);In
lockfile.c:
/* This should return a meaningful errno on failure */ int hold_lock_file_for_update(structlock_file*lk, const char
*path, int flags)
Quoted 8 lines
{ int fd = lock_file(lk, path, flags); which leads to static int lock_file(struct lock_file *lk, const char *path, int flags) [] lk->fd = open(lk->filename.buf, O_RDWR | O_CREAT | O_EXCL, 0666);There is no way to tell which permissions the new lockfile should have.
We follow whategver user's umask says with this code.
Quoted 4 lines
That is somewhat unlucky.
On the other hand, shouldn't we call
adjust_shared_perm(const char *path)frompath.con the config file?
Good question, but I am not sure. For $GIT_DIR/config, I tend to agree we should, but "git config --global foo bar" would not be a shared file anyway, and my understanding of Eric's original motivation is to keep $HOME/.gitconfig to be tighter than the user's umask normally would indicate.
Quoted 5 lines
And to all files which are fiddled through the
lock_fileAPI? In other words, the lockfile could be created with the restrictive permissions
600, and once the lockfile had been closed and renamed into the final name we applyadjust_shared_perm()on it ?
For all files that adjust-shared-perm should apply, yes, but I do not think it is relevant to the codepath in question.
Quoted 4 lines
I think there are 2 different things missing here:
- Be able to specify permissions to
hold_lock_file_for_update(), especially restrictive ones, like 600 and not 666.
Yes (in the sense that "yes we can add an extra parameter") and no (in the sense that "where would we get the value to pass to the extra parameter from? would it be worth to add configurations variables for different kinds of files?").
If we limit the case to "Inherit permissions from the file we are replacing by taking a lock on it", which is the topic of discussion in this thread, we do not have to worry about how to configure the value (we do not have to) and adding a new parameter to tell the mode to hold-lock-file-for-update is unneeded (the function will have a pathname of the original and can learn the current permission bits itself).
Quoted 4 lines
- Adjust the permissions for "shared files" in a shared repo. This is probably needed for a shared repo, when the user itself has a umask which is too restrictive and
adjust_shared_perm()must be run to widen the permissions.
Don't we already do that for $GIT_DIR/config? In any case that will not help $HOME/.gitconfig and other files that are not shared.
Re: No fchmd. was: Re: [PATCH 00/14] Add submodule test harness
On 2014-07-10 21.49, Junio C Hamano wrote:
[]
Quoted 7 lines
If we limit the case to "Inherit permissions from the file we are replacing by taking a lock on it", which is the topic of discussion in this thread, we do not have to worry about how to configure the value (we do not have to) and adding a new parameter to tell the mode to hold-lock-file-for-update is unneeded (the function will have a pathname of the original and can learn the current permission bits itself).
So something like this:
(I will probably not have the time to make a proper patch :-(
lockfile.c +6 -1
@@ -156,6 +156,11 @@ static void resolve_symlink(struct strbuf *path)/* Make sure errno contains a meaningful value on error */ static int lock_file (struct lock_file *lk,const char *path,int flags) { +int perms =0666 ; +struct stat st; +if (!lstat (path, &st)) + perms = st.st_mode &0777 ; +if (!lock_file_list) {/* One-time initialization */ sigchain_push_common (remove_lock_file_on_signal);
@@ -179,7 +184,7 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)if (!(flags &LOCK_NODEREF ))resolve_symlink (&lk->filename);strbuf_addstr (&lk->filename,LOCK_SUFFIX ); - lk->fd =open (lk->filename.buf,O_RDWR |O_CREAT |O_EXCL ,0666 ); + lk->fd =open (lk->filename.buf,O_RDWR |O_CREAT |O_EXCL , perms);if (lk->fd <0 ) {strbuf_reset (&lk->filename);return -1 ;
Re: No fchmd. was: Re: [PATCH 00/14] Add submodule test harness
Quoted 10 lines · Torsten Bögershausen
On 2014-07-10 21.49, Junio C Hamano wrote:
[]Quoted 7 lines
If we limit the case to "Inherit permissions from the file we are replacing by taking a lock on it", which is the topic of discussion in this thread, we do not have to worry about how to configure the value (we do not have to) and adding a new parameter to tell the mode to hold-lock-file-for-update is unneeded (the function will have a pathname of the original and can learn the current permission bits itself).
So something like this:
Yeah, I think something along those lines may be sufficient and we do not have to do anything when closing/committing, at least POSIX systems. I do not know if other filesystems we may care about let you open with 0400 and still write into it, though.
Quoted 1 line
(I will probably not have the time to make a proper patch :-(
That's OK. I see many names on Cc: who are all capable of helping us ;-)
Quoted 26 lines
lockfile.c +6
-1@@ -156,6 +156,11 @@ static void resolve_symlink(struct strbuf *path)/* Make sure errno contains a meaningful value on error */ static int lock_file (struct lock_file *lk,const char *path,int flags) { +int perms =0666 ; +struct stat st; +if (!lstat (path, &st)) + perms = st.st_mode &0777 ; +if (!lock_file_list) {/* One-time initialization */ sigchain_push_common (remove_lock_file_on_signal);@@ -179,7 +184,7 @@ static int lock_file(struct lock_file *lk, const char *path, int flags)if (!(flags &LOCK_NODEREF ))resolve_symlink (&lk->filename);strbuf_addstr (&lk->filename,LOCK_SUFFIX ); - lk->fd =open (lk->filename.buf,O_RDWR |O_CREAT |O_EXCL ,0666 ); + lk->fd =open (lk->filename.buf,O_RDWR |O_CREAT |O_EXCL , perms);if (lk->fd <0 ) {strbuf_reset (&lk->filename);return -1 ;