by 'git submodule init'; edit them to override the
URL and other values found in the `.gitmodules` file. See
+submodule.<name>.remote::
submodule.<name>.branch::
- The remote branch name for a submodule, used by `git submodule
- update --remote`. Set this option to override the value found in
- the `.gitmodules` file. See linkgit:git-submodule[1] and
+ The remote repository and branch names for a submodule, used by `git
+ submodule update --remote`. Set these options to override the value
+ found in the `.gitmodules` file. See linkgit:git-submodule[1] and
linkgit:gitmodules[5] for details.
submodule.<name>.fetchRecurseSubmodules::
This option is only valid for the update command. Instead of using
the superproject's recorded SHA-1 to update the submodule, use the
status of the submodule's remote tracking branch. The remote used
- is branch's remote (`branch.<name>.remote`), defaulting to `origin`.
- The remote branch used defaults to `master`, but the branch name may
- be overridden by setting the `submodule.<name>.branch` option in
- either `.gitmodules` or `.git/config` (with `.git/config` taking
- precedence).
+ is branch's remote (`branch.<name>.remote`, defaulting to `origin`),
+ and the remote branch used defaults to `master`, but either may be
+ overridden by setting the `submodule.<name>.remote` or
+ `submodule.<name>.branch` option in `.gitmodules` or `.git/config`
+ (with `.git/config` taking precedence).
+
This works for any of the supported update procedures (`--checkout`,
`--rebase`, etc.). The only change is the source of the target SHA-1.
printf '%s' "${value:-$default}"
}
+#
+# Print the name of a submodule's configured remote
+#
+# $1 = submodule name
+#
+get_submodule_remote()
+{
+ name="$1"
+ remote=$(get_submodule_config "$name" remote)
+ if test -z "$remote"
+ then
+ remote=$(get_default_remote)
+ fi
+ printf '%s' "${remote}"
+}
#
# Map submodule path to submodule name
fi
name=$(module_name "$sm_path") || exit
url=$(git config submodule."$name".url)
+ remote_name=$(get_submodule_remote "$name")
branch=$(get_submodule_config "$name" branch master)
if ! test -z "$update"
then
if test -z "$nofetch"
then
# Fetch remote before determining tracking $sha1
- (clear_local_git_env; cd "$sm_path" && git-fetch) ||
- die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
+ (clear_local_git_env; cd "$sm_path" && git-fetch "$remote_name") ||
+ die "$(eval_gettext "Unable to fetch '\$remote_name' in submodule path '\$sm_path'")"
fi
- remote_name=$(get_default_remote)
sha1=$(clear_local_git_env; cd "$sm_path" &&
git rev-parse --verify "${remote_name}/${branch}") ||
die "$(eval_gettext "Unable to find current ${remote_name}/${branch} revision in submodule path '\$sm_path'")"
# is not reachable from a ref.
(clear_local_git_env; cd "$sm_path" &&
( (rev=$(git rev-list -n 1 $sha1 --not --all 2>/dev/null) &&
- test -z "$rev") || git-fetch)) ||
- die "$(eval_gettext "Unable to fetch in submodule path '\$sm_path'")"
+ test -z "$rev") || git-fetch "$remote_name")) ||
+ die "$(eval_gettext "Unable to fetch '\$remote_name' in submodule path '\$sm_path'")"
fi
# Is this something we just cloned?
(
clear_local_git_env
cd "$sm_path"
- remote=$(get_default_remote)
+ remote=$(get_submodule_remote "$name")
git config remote."$remote".url "$sub_origin_url"
)
fi
)
'
+test_expect_success 'local config should override .gitmodules remote' '
+ (cd submodule &&
+ echo line5-master >> file &&
+ git add file &&
+ test_tick &&
+ git commit -m "upstream line5-master"
+ ) &&
+ (cd super/submodule &&
+ git remote rename origin test-remote
+ ) &&
+ (cd super &&
+ git config submodule.submodule.remote test-remote &&
+ git submodule update --remote --force submodule &&
+ cd submodule &&
+ test "$(git log -1 --oneline)" = "$(GIT_DIR=../../submodule/.git git log -1 --oneline)"
+ )
+'
+
test_expect_success 'local config should override .gitmodules branch' '
(cd submodule &&
git checkout -b test-branch &&