Skip to content

Commit

Permalink
Add the 'fetch.recursive' config setting
Browse files Browse the repository at this point in the history
This new boolean option can be used to override the default for "git
fetch" and "git pull", which is to recurse into populated submodules
and fetch all new commits there too.

Signed-off-by: Jens Lehmann <Jens.Lehmann@web.de>
  • Loading branch information
jlehmann committed Oct 5, 2010
1 parent 35d0577 commit 583e143
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 5 deletions.
4 changes: 4 additions & 0 deletions Documentation/config.txt
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,10 @@ diff.wordRegex::
sequences that match the regular expression are "words", all other
characters are *ignorable* whitespace.

fetch.recursive::
A boolean value which overrides the default behavior of fetch and
pull, which is to recursively fetch populated sumodules too.

fetch.unpackLimit::
If the number of objects fetched over the git native
transfer is below this
Expand Down
7 changes: 7 additions & 0 deletions submodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
struct string_list config_name_for_path;
struct string_list config_fetch_for_name;
struct string_list config_ignore_for_name;
static int config_fetch_recursive = 1;

static int add_submodule_odb(const char *path)
{
Expand Down Expand Up @@ -68,6 +69,10 @@ int submodule_config(const char *var, const char *value, void *cb)
{
if (!prefixcmp(var, "submodule."))
return parse_submodule_config_option(var, value);
if (!strcmp(var, "fetch.recursive")) {
config_fetch_recursive = git_config_bool(var, value);
return 0;
}
return 0;
}

Expand Down Expand Up @@ -287,6 +292,8 @@ int fetch_populated_submodules(int num_options, const char **options,
fetch_option = unsorted_string_list_lookup(&config_fetch_for_name, name);
if (fetch_option && !fetch_option->util)
continue;
if (!fetch_option && !config_fetch_recursive)
continue;
}

strbuf_addf(&submodule_path, "%s/%s", work_tree, ce->name);
Expand Down
56 changes: 51 additions & 5 deletions t/t5526-fetch-submodules.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ add_upstream_commit() {
git add subfile &&
git commit -m new subfile &&
head2=$(git rev-parse --short HEAD) &&
echo "From $pwd/submodule" > ../expect.err &&
echo " $head1..$head2 master -> origin/master" >> ../expect.err
echo "From $pwd/submodule" > ../expect_1st.err &&
echo " $head1..$head2 master -> origin/master" >> ../expect_1st.err
)
(
cd deepsubmodule &&
Expand All @@ -27,9 +27,10 @@ add_upstream_commit() {
git add deepsubfile &&
git commit -m new deepsubfile &&
head2=$(git rev-parse --short HEAD) &&
echo "From $pwd/deepsubmodule" >> ../expect.err &&
echo " $head1..$head2 master -> origin/master" >> ../expect.err
)
echo "From $pwd/deepsubmodule" > ../expect_2nd.err &&
echo " $head1..$head2 master -> origin/master" >> ../expect_2nd.err
) &&
cat expect_1st.err expect_2nd.err > expect.err
}

test_expect_success setup '
Expand Down Expand Up @@ -58,6 +59,7 @@ test_expect_success setup '
git submodule update --init --recursive
) &&
echo "Fetching submodule submodule" > expect.out &&
cp expect.out expect_1st.out &&
echo "Fetching submodule submodule/deepsubmodule" >> expect.out
'

Expand Down Expand Up @@ -160,4 +162,48 @@ test_expect_success "--recursive propagates to submodules" '
test_cmp expect.err actual.err
'

test_expect_success "fetch.recursive sets default and --recursive overrides it" '
add_upstream_commit &&
(
cd downstream &&
(
cd submodule &&
git config -f .gitmodules --unset submodule.deepsubmodule.fetch &&
git config fetch.recursive false
) &&
git fetch >../actual.out 2>../actual.err
) &&
test_cmp expect_1st.out actual.out &&
test_cmp expect_1st.err actual.err &&
(
cd downstream &&
git fetch --recursive >../actual.out 2>../actual.err
) &&
test_cmp expect.out actual.out &&
test_cmp expect_2nd.err actual.err
'

test_expect_success "fetch setting from .git/config overrides fetch.recursive config setting" '
add_upstream_commit &&
(
cd downstream &&
git config submodule.submodule.fetch true &&
git fetch >../actual.out 2>../actual.err
) &&
test_cmp expect_1st.out actual.out &&
test_cmp expect_1st.err actual.err &&
(
cd downstream &&
(
cd submodule &&
git config --unset fetch.recursive
) &&
git config fetch.recursive false &&
git config submodule.submodule.fetch true &&
git fetch >../actual.out 2>../actual.err
) &&
test_cmp expect.out actual.out &&
test_cmp expect_2nd.err actual.err
'

test_done

0 comments on commit 583e143

Please sign in to comment.