diff --git a/dim b/dim index f24535672b82c44666d0dec74556fa7d0f889f6b..35f209040dfc0429f19a669aafe9c62e8570cde1 100755 --- a/dim +++ b/dim @@ -79,6 +79,9 @@ DIM_TEMPLATE_HELLO=${DIM_TEMPLATE_HELLO:-$HOME/.dim.template.hello} # signature pull request template DIM_TEMPLATE_SIGNATURE=${DIM_TEMPLATE_SIGNATURE:-$HOME/.dim.template.signature} +# preferred protocol when adding remotes +DIM_PREFERRED_PROTOCOL=${DIM_PREFERRED_PROTOCOL:-} + # # Internal configuration. Global dim_ prefixed variables. # @@ -269,6 +272,10 @@ function url_to_remote # url [url ...] for old_url in ${drm_old_urls[$repo]} ; do remote=$(url_to_remote_from_git "$old_url") if [[ -n "$remote" ]]; then + if [[ -n "$DIM_PREFERRED_PROTOCOL" ]]; then + url=$(pick_protocol_url "$DIM_PREFERRED_PROTOCOL" ${url_list}) + fi + if ! ask_user "Update $remote to new $url?"; then echoerr "Old branch setup found but not updated, aborting" return 1 @@ -297,9 +304,14 @@ function url_to_remote # url [url ...] repo="drm-tip" else remote="$repo" + # possibly amend the passed in URLs if any matched a repo + url_list=${drm_tip_repos[$repo]} fi echoerr "Adding remote for ${repo} repo from URLs: $url_list" + if [[ -n "$DIM_PREFERRED_PROTOCOL" ]]; then + url=$(pick_protocol_url "$DIM_PREFERRED_PROTOCOL" $url_list) + fi if [ $ASK_USER_ASSUME_YES -ne 1 ]; then read -r -i "$remote" -e -p "Enter a name to auto-add this remote, leave blank to abort: " remote @@ -2493,11 +2505,17 @@ function parse_opt_dim_setup # options function dim_setup # options { - local remote drm_tip_ssh url_list + local remote drm_tip_ssh url_list url parse_opt_dim_setup "$@" url_list=("git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git" "https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git") + if [[ -n "$DIM_PREFERRED_PROTOCOL" ]]; then + # shellcheck disable=SC2068 + url=$(pick_protocol_url "$DIM_PREFERRED_PROTOCOL" ${url_list[@]}) + else + url=${url_list[0]} + fi if [[ ! -d "$DIM_PREFIX" ]]; then if ask_user "The DIM_PREFIX repository directory '$DIM_PREFIX' doesn't exist. Create?"; then @@ -2515,7 +2533,7 @@ function dim_setup # options if [[ ! -d "$DIM_REPO" ]]; then if ask_user "The DIM_REPO maintainer kernel repository '$DIM_REPO' doesn't exist. Clone upstream?"; then git clone --reference-if-able "$DIM_KERNEL_REFERENCE" --dissociate \ - "${url_list[0]}" "$DIM_REPO" + "$url" "$DIM_REPO" fi fi @@ -2523,7 +2541,7 @@ function dim_setup # options echoerr "No kernel git checkout found in '$DIM_REPO'." echoerr "Please set up your DIM_REPO maintainer kernel repository at '$DIM_REPO' with:" echoerr " cd $DIM_PREFIX" - echoerr " git clone ${url_list[0]} $DIM_REPO" + echoerr " git clone $url $DIM_REPO" echoerr "or update your configuration (see dimrc.sample)." exit 1 fi diff --git a/dim.rst b/dim.rst index 6bef2a180f2b7f2a236bce3b83660a6ba05512b3..ffa6537c0c2b5656c2a2e0b9a4ee9a464f6033ab 100644 --- a/dim.rst +++ b/dim.rst @@ -496,6 +496,11 @@ DIM_GPG_KEYID GPG key ID to use for signing tags. If set, tags will be signed. If unset, the default, tags will not be signed. +DIM_PREFERRED_PROTOCOL +---------------------- +Preferred protocol when adding remotes: ssh or https. If not set, each tree may +use a different protocol according to maintainer's preference. + dim_alias_<alias> ----------------- Make **<alias>** an alias for the subcommand defined as the value. For example, diff --git a/dimrc.sample b/dimrc.sample index b061d2bf0c55f8f4c51721db48238e4f8c208d97..e71de2af71ce1101cbc90aee46f7bd7d3464899c 100644 --- a/dimrc.sample +++ b/dimrc.sample @@ -17,3 +17,6 @@ # Command to run after dim apply #DIM_POST_APPLY_ACTION= + +# Preferred protocol when adding remotes +#DIM_PREFERRED_PROTOCOL=[ssh|https]