From: Sven Verdoolaege <skimo@xxxxxxxxxx> Signed-off-by: Sven Verdoolaege <skimo@xxxxxxxxxx> --- t/t3042-subprojects-fetch.sh | 46 ++++++++++++++++++++++++++++++++++++++++++ unpack-trees.c | 26 +++++++++++++++++++++++ 2 files changed, 72 insertions(+), 0 deletions(-) create mode 100755 t/t3042-subprojects-fetch.sh diff --git a/t/t3042-subprojects-fetch.sh b/t/t3042-subprojects-fetch.sh new file mode 100755 index 0000000..1acc1bd --- /dev/null +++ b/t/t3042-subprojects-fetch.sh @@ -0,0 +1,46 @@ +#!/bin/sh + +test_description='submodule fetch' +. ./test-lib.sh + +test_create_repo orig + +test_expect_success 'submodule creation' \ + '(mkdir orig/A && cd orig/A && + git init && + echo 1 > a && + git add a && + git commit -m "create submodule" || exit $? )' + +test_expect_success 'supermodule creation' \ + '(cd orig && + git add A && + git commit -m "supermodule creation" && + git branch one && + git config 'submodule.A.url' $(pwd)/A || exit $?)' + +test_expect_success 'clone supermodule' \ + 'git clone --submodules orig clone && + echo 1 > expected && + git diff expected clone/A/a' + +test_expect_success 'submodule change' \ + '(cd orig/A && + echo 2 > a && + git add a && + git commit -m "change submodule" || exit $? )' + +test_expect_success 'supermodule change' \ + '(cd orig && + git add A && + git commit -m "supermodule change" || exit $? )' + +test_expect_success 'pull changes' \ + '(cd clone && + git pull || exit $? )' + +test_expect_success 'check pulled changes' \ + 'echo 2 > expected && + git diff expected clone/A/a' + +test_done diff --git a/unpack-trees.c b/unpack-trees.c index ddefb51..1a76a29 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -7,6 +7,7 @@ #include "progress.h" #include "refs.h" #include "submodules.h" +#include "run-command.h" #define DBRT_DEBUG 1 @@ -810,6 +811,9 @@ static int ensure_submodule(struct cache_entry *ce, { struct stat st; char *path; + const char *argv_check[10]; + const char *argv_fetch[] = {"fetch", NULL}; + int argc; if (!ce) return 0; @@ -826,10 +830,32 @@ static int ensure_submodule(struct cache_entry *ce, if (lstat(path, &st)) { if (clone_submodule(ce->name)) return -1; + /* may have been overwritten */ + path = git_path("submodules/%s/.git", ce->name); } } /* Now check that the commit is available and fetch if needed */ + argc = 0; + argv_check[argc++] = "cat-file"; + argv_check[argc++] = "-t"; + argv_check[argc++] = sha1_to_hex(ce->sha1); + argv_check[argc] = NULL; + + if (run_command_v_opt_cd(argv_check, + RUN_GIT_CMD|RUN_COMMAND_CLEAR_GIT_ENV|RUN_COMMAND_NO_STDOUT| + RUN_COMMAND_NO_STDERR, path)) { + if (run_command_v_opt_cd(argv_fetch, + RUN_GIT_CMD|RUN_COMMAND_CLEAR_GIT_ENV, path)) + return error("Unable to fetch submodule '%s'", ce->name); + + if (run_command_v_opt_cd(argv_check, + RUN_GIT_CMD|RUN_COMMAND_CLEAR_GIT_ENV|RUN_COMMAND_NO_STDOUT| + RUN_COMMAND_NO_STDERR, path)) + return error( + "Unable to fetch revision %s for submodule '%s'", + sha1_to_hex(ce->sha1), ce->name); + } return 0; } -- 1.5.2.784.g5532e - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html