Merge branch 'dl/submodule-set-branch'

"git submodule" learns "set-branch" subcommand that allows the
submodule.*.branch settings to be modified.

* dl/submodule-set-branch:
  submodule: teach set-branch subcommand
  submodule--helper: teach config subcommand --unset
  git-submodule.txt: "--branch <branch>" option defaults to 'master'
This commit is contained in:
Junio C Hamano
2019-04-25 16:41:18 +09:00
6 changed files with 200 additions and 13 deletions

View File

@ -11,6 +11,7 @@ USAGE="[--quiet] [--cached]
or: $dashless [--quiet] init [--] [<path>...]
or: $dashless [--quiet] deinit [-f|--force] (--all| [--] <path>...)
or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference <repository>] [--recursive] [--] [<path>...]
or: $dashless [--quiet] set-branch (--default|--branch <branch>) [--] <path>
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: $dashless [--quiet] foreach [--recursive] <command>
or: $dashless [--quiet] sync [--recursive] [--] [<path>...]
@ -685,6 +686,72 @@ cmd_update()
}
}
#
# Configures a submodule's default branch
#
# $@ = requested path
#
cmd_set_branch() {
unset_branch=false
branch=
while test $# -ne 0
do
case "$1" in
-q|--quiet)
# we don't do anything with this but we need to accept it
;;
-d|--default)
unset_branch=true
;;
-b|--branch)
case "$2" in '') usage ;; esac
branch=$2
shift
;;
--)
shift
break
;;
-*)
usage
;;
*)
break
;;
esac
shift
done
if test $# -ne 1
then
usage
fi
# we can't use `git submodule--helper name` here because internally, it
# hashes the path so a trailing slash could lead to an unintentional no match
name="$(git submodule--helper list "$1" | cut -f2)"
if test -z "$name"
then
exit 1
fi
test -n "$branch"; has_branch=$?
test "$unset_branch" = true; has_unset_branch=$?
if test $((!$has_branch != !$has_unset_branch)) -eq 0
then
usage
fi
if test $has_branch -eq 0
then
git submodule--helper config submodule."$name".branch "$branch"
else
git submodule--helper config --unset submodule."$name".branch
fi
}
#
# Show commit summary for submodules in index or working tree
#
@ -984,7 +1051,7 @@ cmd_absorbgitdirs()
while test $# != 0 && test -z "$command"
do
case "$1" in
add | foreach | init | deinit | update | status | summary | sync | absorbgitdirs)
add | foreach | init | deinit | update | set-branch | status | summary | sync | absorbgitdirs)
command=$1
;;
-q|--quiet)
@ -1025,8 +1092,8 @@ then
fi
fi
# "-b branch" is accepted only by "add"
if test -n "$branch" && test "$command" != add
# "-b branch" is accepted only by "add" and "set-branch"
if test -n "$branch" && (test "$command" != add || test "$command" != set-branch)
then
usage
fi
@ -1037,4 +1104,4 @@ then
usage
fi
"cmd_$command" "$@"
"cmd_$(echo $command | sed -e s/-/_/g)" "$@"