[-f|--force] [--reference <repository>] [--] <repository> [<path>]
'git submodule' [--quiet] status [--cached] [--recursive] [--] [<path>...]
'git submodule' [--quiet] init [--] [<path>...]
-'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--rebase]
+'git submodule' [--quiet] update [--init] [-N|--no-fetch] [--branch] [--rebase]
[--reference <repository>] [--merge] [--recursive] [--] [<path>...]
'git submodule' [--quiet] summary [--cached|--files] [(-n|--summary-limit) <n>]
[commit] [--] [<path>...]
update::
Update the registered submodules, i.e. clone missing submodules and
- checkout the commit specified in the index of the containing repository.
- This will make the submodules HEAD be detached unless `--rebase` or
- `--merge` is specified or the key `submodule.$name.update` is set to
- `rebase`, `merge` or `none`. `none` can be overridden by specifying
- `--checkout`.
+ checkout the commit specified in the index of the containing
+ repository. This will make the submodules HEAD be detached unless
+ `--branch`, `--rebase`, `--merge` is specified or the key
+ `submodule.$name.update` is set to `branch`, `rebase`, `merge` or
+ `none`. `none` can be overridden by specifying `--checkout`.
+
If the submodule is not yet initialized, and you just want to use the
setting as stored in .gitmodules, you can automatically initialize the
-b::
--branch::
- Branch of repository to add as submodule.
+ When used with the add command, gives the branch of repository to
+ add as submodule.
++
+When used with the update command, checks out a branch named
+`submodule.<name>.branch` (as set by `--local-branch`) pointing at the
+current HEAD SHA-1. This is useful for commands like `update
+--rebase` that do not work on detached heads.
--local-branch::
Record a branch name used as `submodule.<path>.branch` in
USAGE="[--quiet] add [-b branch] [--local-branch[=<branch>]] [-f|--force] [--reference <repository>] [--] <repository> [<path>]
or: $dashless [--quiet] status [--cached] [--recursive] [--] [<path>...]
or: $dashless [--quiet] init [--] [<path>...]
- or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
+ or: $dashless [--quiet] update [--init] [-N|--no-fetch] [-f|--force] [--branch] [--rebase] [--reference <repository>] [--merge] [--recursive] [--] [<path>...]
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: $dashless [--quiet] foreach [--recursive] <command>
or: $dashless [--quiet] sync [--] [<path>...]"
-f|--force)
force=$1
;;
+ -b|--branch)
+ update="branch"
+ ;;
-r|--rebase)
update="rebase"
;;
fi
name=$(module_name "$sm_path") || exit
url=$(git config submodule."$name".url)
+ branch=$(git config submodule."$name".branch)
if ! test -z "$update"
then
update_module=$update
die "$(eval_gettext "Unable to find current revision in submodule path '\$sm_path'")"
fi
- if test "$subsha1" != "$sha1" -o -n "$force"
+ if test "$subsha1" != "$sha1" -o -n "$force" -o "$update_module" = "branch"
then
subforce=$force
# If we don't already have a -f flag and the submodule has never been checked out
case ";$cloned_modules;" in
*";$name;"*)
# then there is no local change to integrate
- update_module= ;;
+ case "$update_module" in
+ rebase|merge)
+ update_module=
+ ;;
+ esac
+ ;;
esac
must_die_on_failure=
case "$update_module" in
rebase)
command="git rebase"
- die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$sm_path'")"
+ die_msg="$(eval_gettext "Unable to rebase '\$sha1' in submodule path '\$sm_path'")"
say_msg="$(eval_gettext "Submodule path '\$sm_path': rebased into '\$sha1'")"
- must_die_on_failure=yes
+ must_die_on_failure=yes
;;
merge)
command="git merge"
;;
esac
- if (clear_local_git_env; cd "$sm_path" && $command "$sha1")
+ if test "$subsha1" != "$sha1" -o -n "$force"
then
- say "$say_msg"
- elif test -n "$must_die_on_failure"
+ if (clear_local_git_env; cd "$sm_path" && $command "$sha1")
+ then
+ say "$say_msg"
+ elif test -n "$must_die_on_failure"
+ then
+ die_with_status 2 "$die_msg"
+ else
+ err="${err};$die_msg"
+ continue
+ fi
+ fi
+
+ if test "$update_module" = "branch" -a -n "$branch"
then
- die_with_status 2 "$die_msg"
- else
- err="${err};$die_msg"
- continue
+ if (clear_local_git_env; cd "$sm_path" &&
+ git branch -f "$branch" "$sha1" &&
+ git checkout "$branch")
+ then
+ say "$(eval_gettext "Submodule path '\$sm_path': checked out branch '\$branch'")"
+ else
+ err="${err};$(eval_gettext "Unable to checkout branch '\$branch' in submodule path '\$sm_path'")"
+ fi
fi
fi
test_description='Test updating submodules
This test verifies that "git submodule update" detaches the HEAD of the
-submodule and "git submodule update --rebase/--merge" does not detach the HEAD.
+submodule and "git submodule update --branch/--rebase/--merge" does not
+detach the HEAD.
'
. ./test-lib.sh
)
'
+test_expect_success 'submodule update --branch detaches without submodule.<name>.branch' '
+ (cd super/submodule &&
+ git checkout master
+ ) &&
+ (cd super &&
+ (cd submodule &&
+ compare_head
+ ) &&
+ git submodule update --branch submodule &&
+ (cd submodule &&
+ test "$(git status -s file)" = ""
+ )
+ )
+'
+
+test_expect_success 'submodule update --branch staying on master' '
+ (cd super/submodule &&
+ git checkout master
+ ) &&
+ (cd super &&
+ (cd submodule &&
+ compare_head
+ ) &&
+ git config submodule.submodule.branch master
+ git submodule update --branch submodule &&
+ cd submodule &&
+ test "refs/heads/master" = "$(git symbolic-ref -q HEAD)" &&
+ compare_head
+ )
+'
+
+test_expect_success 'submodule update --branch creating a new branch' '
+ (cd super/submodule &&
+ git checkout master
+ ) &&
+ (cd super &&
+ (cd submodule &&
+ compare_head
+ ) &&
+ git config submodule.submodule.branch new-branch
+ git submodule update --branch submodule &&
+ cd submodule &&
+ test "refs/heads/new-branch" = "$(git symbolic-ref -q HEAD)" &&
+ compare_head
+ )
+'
+
test_expect_success 'submodule update --rebase staying on master' '
(cd super/submodule &&
git checkout master