From: Junio C Hamano Date: Thu, 25 Apr 2019 07:41:18 +0000 (+0900) Subject: Merge branch 'dl/submodule-set-branch' X-Git-Tag: v2.22.0-rc0~55 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/01f8d78887d45dc10f29d3926d5cc52f78838846?ds=inline;hp=-c 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 " option defaults to 'master' --- 01f8d78887d45dc10f29d3926d5cc52f78838846 diff --combined Documentation/git-submodule.txt index ac8c6879dd,4daf144180..0ed5c24dc1 --- a/Documentation/git-submodule.txt +++ b/Documentation/git-submodule.txt @@@ -9,12 -9,12 +9,13 @@@ git-submodule - Initialize, update or i SYNOPSIS -------- [verse] +'git submodule' [--quiet] [--cached] 'git submodule' [--quiet] add [] [--] [] 'git submodule' [--quiet] status [--cached] [--recursive] [--] [...] 'git submodule' [--quiet] init [--] [...] 'git submodule' [--quiet] deinit [-f|--force] (--all|[--] ...) 'git submodule' [--quiet] update [] [--] [...] + 'git submodule' [--quiet] set-branch [] [--] 'git submodule' [--quiet] summary [] [--] [...] 'git submodule' [--quiet] foreach [--recursive] 'git submodule' [--quiet] sync [--recursive] [--] [...] @@@ -29,9 -29,6 +30,9 @@@ For more information about submodules, COMMANDS -------- +With no arguments, shows the status of existing submodules. Several +subcommands are available to perform operations on the submodules. + add [-b ] [-f|--force] [--name ] [--reference ] [--depth ] [--] []:: Add the given repository as a submodule at the given path to the changeset to be committed next to the current @@@ -42,7 -39,7 +43,7 @@@ This may be either an absolute URL, or or ../), the location relative to the superproject's default remote repository (Please note that to specify a repository 'foo.git' which is located right next to a superproject 'bar.git', you'll -have to use '../foo.git' instead of './foo.git' - as one might expect +have to use `../foo.git` instead of `./foo.git` - as one might expect when following the rules for relative URLs - because the evaluation of relative URLs in Git is identical to that of relative directories). + @@@ -172,6 -169,12 +173,12 @@@ submodule with the `--init` option If `--recursive` is specified, this command will recurse into the registered submodules, and update any nested submodules within. -- + set-branch ((-d|--default)|(-b|--branch )) [--] :: + Sets the default remote tracking branch for the submodule. The + `--branch` option allows the remote branch to be specified. The + `--default` option removes the submodule..branch configuration + key, which causes the tracking branch to default to 'master'. + summary [--cached|--files] [(-n|--summary-limit) ] [commit] [--] [...]:: Show commit summary between the given commit (defaults to HEAD) and working tree/index. For a submodule in question, a series of commits @@@ -259,13 -262,14 +266,14 @@@ OPTION This option is only valid for the deinit command. Unregister all submodules in the working tree. - -b:: - --branch:: + -b :: + --branch :: Branch of repository to add as submodule. The name of the branch is recorded as `submodule..branch` in `.gitmodules` for `update --remote`. A special value of `.` is used to indicate that the name of the branch in the submodule should be the - same name as the current branch in the current repository. + same name as the current branch in the current repository. If the + option is not specified, it defaults to 'master'. -f:: --force:: diff --combined builtin/submodule--helper.c index 8342b78add,33d9f82661..168be97ffb --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@@ -348,7 -348,7 +348,7 @@@ static int module_list_compute(int argc i++; } - if (ps_matched && report_path_error(ps_matched, pathspec, prefix)) + if (ps_matched && report_path_error(ps_matched, pathspec)) result = -1; free(ps_matched); @@@ -1816,10 -1816,11 +1816,10 @@@ static int update_submodules(struct sub { int i; - run_processes_parallel(suc->max_jobs, - update_clone_get_next_task, - update_clone_start_failure, - update_clone_task_finished, - suc); + run_processes_parallel_tr2(suc->max_jobs, update_clone_get_next_task, + update_clone_start_failure, + update_clone_task_finished, suc, "submodule", + "parallel/update"); /* * We saved the output and put it out all at once now. @@@ -2147,17 -2148,22 +2147,22 @@@ static int check_name(int argc, const c static int module_config(int argc, const char **argv, const char *prefix) { enum { - CHECK_WRITEABLE = 1 + CHECK_WRITEABLE = 1, + DO_UNSET = 2 } command = 0; struct option module_config_options[] = { OPT_CMDMODE(0, "check-writeable", &command, N_("check if it is safe to write to the .gitmodules file"), CHECK_WRITEABLE), + OPT_CMDMODE(0, "unset", &command, + N_("unset the config in the .gitmodules file"), + DO_UNSET), OPT_END() }; const char *const git_submodule_helper_usage[] = { - N_("git submodule--helper config name [value]"), + N_("git submodule--helper config []"), + N_("git submodule--helper config --unset "), N_("git submodule--helper config --check-writeable"), NULL }; @@@ -2169,15 -2175,17 +2174,17 @@@ return is_writing_gitmodules_ok() ? 0 : -1; /* Equivalent to ACTION_GET in builtin/config.c */ - if (argc == 2) + if (argc == 2 && command != DO_UNSET) return print_config_from_gitmodules(the_repository, argv[1]); /* Equivalent to ACTION_SET in builtin/config.c */ - if (argc == 3) { + if (argc == 3 || (argc == 2 && command == DO_UNSET)) { + const char *value = (argc == 3) ? argv[2] : NULL; + if (!is_writing_gitmodules_ok()) die(_("please make sure that the .gitmodules file is in the working tree")); - return config_set_in_gitmodules_file_gently(argv[1], argv[2]); + return config_set_in_gitmodules_file_gently(argv[1], value); } usage_with_options(git_submodule_helper_usage, module_config_options); diff --combined contrib/completion/git-completion.bash index 42a3c8e524,8b3b5a9d34..3eefbabdb1 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@@ -853,11 -853,6 +853,11 @@@ __git_compute_merge_strategies ( __git_merge_strategies=$(__git_list_merge_strategies) } +__git_merge_strategy_options="ours theirs subtree subtree= patience + histogram diff-algorithm= ignore-space-change ignore-all-space + ignore-space-at-eol renormalize no-renormalize no-renames + find-renames find-renames= rename-threshold=" + __git_complete_revlist_file () { local dequoted_word pfx ls ref cur_="$cur" @@@ -1001,21 -996,12 +1001,21 @@@ __git_complete_strategy ( -s|--strategy) __gitcomp "$__git_merge_strategies" return 0 + ;; + -X) + __gitcomp "$__git_merge_strategy_options" + return 0 + ;; esac case "$cur" in --strategy=*) __gitcomp "$__git_merge_strategies" "" "${cur##--strategy=}" return 0 ;; + --strategy-option=*) + __gitcomp "$__git_merge_strategy_options" "" "${cur##--strategy-option=}" + return 0 + ;; esac return 1 } @@@ -1024,7 -1010,7 +1024,7 @@@ __git_all_commands __git_compute_all_commands () { test -n "$__git_all_commands" || - __git_all_commands=$(git --list-cmds=main,others,alias,nohelpers) + __git_all_commands=$(__git --list-cmds=main,others,alias,nohelpers) } # Lists all set config variables starting with the given section prefix, @@@ -1177,7 -1163,6 +1177,7 @@@ __git_count_arguments ( } __git_whitespacelist="nowarn warn error error-all fix" +__git_patchformat="mbox stgit stgit-series hg mboxrd" __git_am_inprogress_options="--skip --continue --resolved --abort --quit --show-current-patch" _git_am () @@@ -1192,10 -1177,6 +1192,10 @@@ __gitcomp "$__git_whitespacelist" "" "${cur##--whitespace=}" return ;; + --patch-format=*) + __gitcomp "$__git_patchformat" "" "${cur##--patch-format=}" + return + ;; --*) __gitcomp_builtin am "" \ "$__git_am_inprogress_options" @@@ -1219,10 -1200,6 +1219,10 @@@ _git_apply ( _git_add () { case "$cur" in + --chmod=*) + __gitcomp "+x -x" "" "${cur##--chmod=}" + return + ;; --*) __gitcomp_builtin add return @@@ -1283,8 -1260,6 +1283,8 @@@ _git_bisect ( esac } +__git_ref_fieldlist="refname objecttype objectsize objectname upstream push HEAD symref" + _git_branch () { local i c=1 only_local_ref="n" has_r="n" @@@ -1368,9 -1343,6 +1368,9 @@@ _git_cherry_pick ( __gitcomp "$__git_cherry_pick_inprogress_options" return fi + + __git_complete_strategy && return + case "$cur" in --*) __gitcomp_builtin cherry-pick "" \ @@@ -1501,8 -1473,7 +1501,8 @@@ _git_diff ( } __git_mergetools_common="diffuse diffmerge ecmerge emerge kdiff3 meld opendiff - tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc codecompare + tkdiff vimdiff gvimdiff xxdiff araxis p4merge bc + codecompare smerge " _git_difftool () @@@ -1535,10 -1506,6 +1535,10 @@@ _git_fetch ( __gitcomp "$__git_fetch_recurse_submodules" "" "${cur##--recurse-submodules=}" return ;; + --filter=*) + __gitcomp "blob:none blob:limit= sparse:oid= sparse:path=" "" "${cur##--filter=}" + return + ;; --*) __gitcomp_builtin fetch return @@@ -1653,9 -1620,9 +1653,9 @@@ _git_help ( esac if test -n "$GIT_TESTING_ALL_COMMAND_LIST" then - __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(git --list-cmds=alias,list-guide) gitk" + __gitcomp "$GIT_TESTING_ALL_COMMAND_LIST $(__git --list-cmds=alias,list-guide) gitk" else - __gitcomp "$(git --list-cmds=main,nohelpers,alias,list-guide) gitk" + __gitcomp "$(__git --list-cmds=main,nohelpers,alias,list-guide) gitk" fi } @@@ -1735,8 -1702,8 +1735,8 @@@ __git_log_shortlog_options= --all-match --invert-grep " -__git_log_pretty_formats="oneline short medium full fuller email raw format:" -__git_log_date_formats="relative iso8601 rfc2822 short local default raw" +__git_log_pretty_formats="oneline short medium full fuller email raw format: mboxrd" +__git_log_date_formats="relative iso8601 iso8601-strict rfc2822 short local default raw unix format:" _git_log () { @@@ -2254,7 -2221,7 +2254,7 @@@ _git_config ( return ;; diff.submodule) - __gitcomp "log short" + __gitcomp "$__git_diff_submodule_formats" return ;; help.format) @@@ -2421,10 -2388,6 +2421,10 @@@ _git_remote ( _git_replace () { case "$cur" in + --format=*) + __gitcomp "short medium long" "" "${cur##--format=}" + return + ;; --*) __gitcomp_builtin replace return @@@ -2466,7 -2429,6 +2466,7 @@@ _git_revert ( __gitcomp "$__git_revert_inprogress_options" return fi + __git_complete_strategy && return case "$cur" in --*) __gitcomp_builtin revert "" \ @@@ -2611,7 -2573,7 +2611,7 @@@ _git_submodule ( { __git_has_doubledash && return - local subcommands="add status init deinit update summary foreach sync absorbgitdirs" - local subcommands="add status init deinit update set-branch summary foreach sync" ++ local subcommands="add status init deinit update set-branch summary foreach sync absorbgitdirs" local subcommand="$(__git_find_on_cmdline "$subcommands")" if [ -z "$subcommand" ]; then case "$cur" in @@@ -2642,6 -2604,9 +2642,9 @@@ --force --rebase --merge --reference --depth --recursive --jobs " ;; + set-branch,--*) + __gitcomp "--default --branch" + ;; summary,--*) __gitcomp "--cached --files --summary-limit" ;; @@@ -2926,7 -2891,7 +2929,7 @@@ __git_main ( then __gitcomp "$GIT_TESTING_PORCELAIN_COMMAND_LIST" else - __gitcomp "$(git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)" + __gitcomp "$(__git --list-cmds=list-mainporcelain,others,nohelpers,alias,list-complete,config)" fi ;; esac diff --combined git-submodule.sh index 2c0fb6d723,470f681573..99fba417b1 --- a/git-submodule.sh +++ b/git-submodule.sh @@@ -5,12 -5,12 +5,13 @@@ # Copyright (c) 2007 Lars Hjemli dashless=$(basename "$0" | sed -e 's/-/ /') -USAGE="[--quiet] add [-b ] [-f|--force] [--name ] [--reference ] [--] [] +USAGE="[--quiet] [--cached] + or: $dashless [--quiet] add [-b ] [-f|--force] [--name ] [--reference ] [--] [] or: $dashless [--quiet] status [--cached] [--recursive] [--] [...] or: $dashless [--quiet] init [--] [...] or: $dashless [--quiet] deinit [-f|--force] (--all| [--] ...) or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--[no-]recommend-shallow] [--reference ] [--recursive] [--] [...] + or: $dashless [--quiet] set-branch (--default|--branch ) [--] or: $dashless [--quiet] summary [--cached|--files] [--summary-limit ] [commit] [--] [...] or: $dashless [--quiet] foreach [--recursive] or: $dashless [--quiet] sync [--recursive] [--] [...] @@@ -594,7 -594,7 +595,7 @@@ cmd_update( # is not reachable from a ref. is_tip_reachable "$sm_path" "$sha1" || fetch_in_submodule "$sm_path" $depth || - say "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'")" + say "$(eval_gettext "Unable to fetch in submodule path '\$displaypath'; trying to directly fetch \$sha1:")" # Now we tried the usual fetch, but $sha1 may # not be reachable from any of the refs @@@ -685,6 -685,72 +686,72 @@@ } } + # + # 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 -1050,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 -1091,8 +1092,8 @@@ the 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 -1103,4 +1104,4 @@@ the usage fi - "cmd_$command" "$@" + "cmd_$(echo $command | sed -e s/-/_/g)" "$@"