summaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-04-25 07:41:18 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-04-25 07:41:18 (GMT)
commit01f8d78887d45dc10f29d3926d5cc52f78838846 (patch)
treebd36c10864e4a75d757732e8324e8e21b4d5b917 /git-submodule.sh
parentd9d65e9f6ab3f5f1525ae8c86dfbab5978adf846 (diff)
parentb57e8119e6e08f731308923ef2b033eb45152bc6 (diff)
downloadgit-01f8d78887d45dc10f29d3926d5cc52f78838846.zip
git-01f8d78887d45dc10f29d3926d5cc52f78838846.tar.gz
git-01f8d78887d45dc10f29d3926d5cc52f78838846.tar.bz2
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'
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh75
1 files changed, 71 insertions, 4 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index 2c0fb6d..99fba41 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -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>...]
@@ -686,6 +687,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
#
# If '--cached' is given, show summary between index and given commit,
@@ -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)" "$@"