Re: [WIP/PATCH 3/9] Teach checkout the --[no-]recurse-submodules option
Am 03.02.2014 23:56, schrieb Junio C Hamano: Jens Lehmann jens.lehm...@web.de writes: +set_config_update_recurse_submodules( + parse_update_recurse_submodules_arg(--recurse-submodules-default, +recurse_submodules_default), +recurse_submodules); I think I saw these exact lines in another patch. Perhaps the whole thing can become a helper function that lets the caller avoid typing the whole long strings that needs a strange/unfortunate line break? Right, that'd be better. diff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh index 06b18f8..bc3e1ca 100755 --- a/t/t2013-checkout-submodule.sh +++ b/t/t2013-checkout-submodule.sh @@ -4,17 +4,57 @@ test_description='checkout can handle submodules' . ./test-lib.sh +submodule_creation_must_succeed() { Style: SP before (), i.e. submodule_creation_must_succeed () { +# checkout base ($1) +git checkout -f --recurse-submodules $1 +git diff-files --quiet +git diff-index --quiet --cached $1 Please make it a habit to quote a parameter that is intended not to be split at $IFS (e.g. write these as $1 not as $1). Otherwise the reader has to wonder if this can be called with a foo bar and the expects it to be split into two. +# checkout target ($2) +if test -d submodule; then Style: no semicolons in standard control structure, i.e. if test -d submodule then +echo changesubmodule/first.t Style: SP before but not after redirection operator, i.e. echo foo bar +submodule_removal_must_succeed() { Likewise. +# checkout base ($1) +git checkout -f --recurse-submodules $1 Likewise. +echo first file Likewise. +test_expect_success 'checkout --recurse-submodules replaces submodule with files' ' +git checkout -f base +git checkout -b replace_submodule_with_dir +git update-index --force-remove submodule +rm -rf submodule/.git .gitmodules +git add .gitmodules submodule/* +git commit -m submodule replaced +git checkout -f base +git submodule update -f +git checkout --recurse-submodules replace_submodule_with_dir +test -d submodule +! test -e submodule/.git +test -f submodule/first.t +test -f submodule/second.t +' H. Is it sufficient for these files to just exist, or do we want to make sure they have expected contents? Thanks, will consider all you remarks above in the ongoing work for testing framework which should replace these tests. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
[WIP/PATCH 3/9] Teach checkout the --[no-]recurse-submodules option
This new option will allow the user to not only update the work tree of the superproject according to the checked out commit but to also update the work tree of all initialized submodules (so they match the SHA-1 recorded in the superproject). But this commit only adds the option without any functionality, that will be added to unpack_trees() in subsequent commits. Signed-off-by: Jens Lehmann jens.lehm...@web.de --- Documentation/git-checkout.txt | 2 + builtin/checkout.c | 14 +++ t/t2013-checkout-submodule.sh | 215 - 3 files changed, 228 insertions(+), 3 deletions(-) diff --git a/Documentation/git-checkout.txt b/Documentation/git-checkout.txt index 91294f8..6c7d31f 100644 --- a/Documentation/git-checkout.txt +++ b/Documentation/git-checkout.txt @@ -225,6 +225,8 @@ This means that you can use `git checkout -p` to selectively discard edits from your current working tree. See the ``Interactive Mode'' section of linkgit:git-add[1] to learn how to operate the `--patch` mode. +include::recurse-submodules-update.txt[] + branch:: Branch to checkout; if it refers to a branch (i.e., a name that, when prepended with refs/heads/, is a valid ref), then that diff --git a/builtin/checkout.c b/builtin/checkout.c index 5df3837..e4ef0ba 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -21,6 +21,9 @@ #include submodule.h #include argv-array.h +static const char *recurse_submodules_default = off; +static int recurse_submodules = RECURSE_SUBMODULES_DEFAULT; + static const char * const checkout_usage[] = { N_(git checkout [options] branch), N_(git checkout [options] [branch] -- file...), @@ -,6 +1114,12 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) N_(do not limit pathspecs to sparse entries only)), OPT_HIDDEN_BOOL(0, guess, dwim_new_local_branch, N_(second guess 'git checkout no-such-branch')), + { OPTION_CALLBACK, 0, recurse-submodules, recurse_submodules, + checkout, control recursive updating of submodules, + PARSE_OPT_OPTARG, option_parse_update_submodules }, + { OPTION_STRING, 0, recurse-submodules-default, + recurse_submodules_default, NULL, + default mode for recursion, PARSE_OPT_HIDDEN }, OPT_END(), }; @@ -1132,6 +1141,11 @@ int cmd_checkout(int argc, const char **argv, const char *prefix) git_xmerge_config(merge.conflictstyle, conflict_style, NULL); } + set_config_update_recurse_submodules( + parse_update_recurse_submodules_arg(--recurse-submodules-default, + recurse_submodules_default), + recurse_submodules); + if ((!!opts.new_branch + !!opts.new_branch_force + !!opts.new_orphan_branch) 1) die(_(-b, -B and --orphan are mutually exclusive)); diff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh index 06b18f8..bc3e1ca 100755 --- a/t/t2013-checkout-submodule.sh +++ b/t/t2013-checkout-submodule.sh @@ -4,17 +4,57 @@ test_description='checkout can handle submodules' . ./test-lib.sh +submodule_creation_must_succeed() { + # checkout base ($1) + git checkout -f --recurse-submodules $1 + git diff-files --quiet + git diff-index --quiet --cached $1 + + # checkout target ($2) + if test -d submodule; then + echo changesubmodule/first.t + test_must_fail git checkout --recurse-submodules $2 + git checkout -f --recurse-submodules $2 + else + git checkout --recurse-submodules $2 + fi + test -e submodule/.git + test -f submodule/first.t + test -f submodule/second.t + git diff-files --quiet + git diff-index --quiet --cached $2 +} + +submodule_removal_must_succeed() { + # checkout base ($1) + git checkout -f --recurse-submodules $1 + git submodule update -f + test -e submodule/.git + git diff-files --quiet + git diff-index --quiet --cached $1 + + # checkout target ($2) + echo changesubmodule/first.t + test_must_fail git checkout --recurse-submodules $2 + git checkout -f --recurse-submodules $2 + git diff-files --quiet + git diff-index --quiet --cached $2 + ! test -d submodule +} + test_expect_success 'setup' ' mkdir submodule (cd submodule git init test_commit first) - git add submodule + echo first file + git add file submodule test_tick git commit -m superproject (cd submodule test_commit second) - git add submodule + echo second file + git add file submodule
Re: [WIP/PATCH 3/9] Teach checkout the --[no-]recurse-submodules option
Jens Lehmann jens.lehm...@web.de writes: + set_config_update_recurse_submodules( + parse_update_recurse_submodules_arg(--recurse-submodules-default, + recurse_submodules_default), + recurse_submodules); I think I saw these exact lines in another patch. Perhaps the whole thing can become a helper function that lets the caller avoid typing the whole long strings that needs a strange/unfortunate line break? diff --git a/t/t2013-checkout-submodule.sh b/t/t2013-checkout-submodule.sh index 06b18f8..bc3e1ca 100755 --- a/t/t2013-checkout-submodule.sh +++ b/t/t2013-checkout-submodule.sh @@ -4,17 +4,57 @@ test_description='checkout can handle submodules' . ./test-lib.sh +submodule_creation_must_succeed() { Style: SP before (), i.e. submodule_creation_must_succeed () { + # checkout base ($1) + git checkout -f --recurse-submodules $1 + git diff-files --quiet + git diff-index --quiet --cached $1 Please make it a habit to quote a parameter that is intended not to be split at $IFS (e.g. write these as $1 not as $1). Otherwise the reader has to wonder if this can be called with a foo bar and the expects it to be split into two. + # checkout target ($2) + if test -d submodule; then Style: no semicolons in standard control structure, i.e. if test -d submodule then + echo changesubmodule/first.t Style: SP before but not after redirection operator, i.e. echo foo bar +submodule_removal_must_succeed() { Likewise. + # checkout base ($1) + git checkout -f --recurse-submodules $1 Likewise. + echo first file Likewise. +test_expect_success 'checkout --recurse-submodules replaces submodule with files' ' + git checkout -f base + git checkout -b replace_submodule_with_dir + git update-index --force-remove submodule + rm -rf submodule/.git .gitmodules + git add .gitmodules submodule/* + git commit -m submodule replaced + git checkout -f base + git submodule update -f + git checkout --recurse-submodules replace_submodule_with_dir + test -d submodule + ! test -e submodule/.git + test -f submodule/first.t + test -f submodule/second.t +' H. Is it sufficient for these files to just exist, or do we want to make sure they have expected contents? Thanks. -- To unsubscribe from this list: send the line unsubscribe git in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html