From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Patrick Steinhardt <ps@pks.im>,
Jens Lehmann <Jens.Lehmann@web.de>,
Heiko Voigt <hvoigt@hvoigt.net>
Subject: [RFC/PATCH 2/4] submodules: implement remote commands.
Date: Wed, 8 Apr 2015 12:58:23 +0200 [thread overview]
Message-ID: <1428490705-11586-3-git-send-email-ps@pks.im> (raw)
In-Reply-To: <1428490705-11586-1-git-send-email-ps@pks.im>
Add commands to modify a submodule's remote configuration. There
are commands to add and remove submodule remotes as well as to
modify the URL of a submodule remote.
---
git-submodule.sh | 225 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 223 insertions(+), 2 deletions(-)
diff --git a/git-submodule.sh b/git-submodule.sh
index 599a847..6904f29 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -12,7 +12,11 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re
or: $dashless [--quiet] update [--init] [--remote] [-N|--no-fetch] [-f|--force] [--checkout|--merge|--rebase] [--reference <repository>] [--recursive] [--] [<path>...]
or: $dashless [--quiet] summary [--cached|--files] [--summary-limit <n>] [commit] [--] [<path>...]
or: $dashless [--quiet] foreach [--recursive] <command>
- or: $dashless [--quiet] sync [--recursive] [--] [<path>...]"
+ or: $dashless [--quiet] sync [--recursive] [--] [<path>...]
+ or: $dashless [--quiet] remote add <path> <name> <url>
+ or: $dashless [--quiet] remote rm <path> <name>
+ or: $dashless [--quiet] remote show <path>
+ or: $dashless [--quiet] remote set-url [--push] <path> <name> <url>"
OPTIONS_SPEC=
SUBDIRECTORY_OK=Yes
. git-sh-setup
@@ -1270,6 +1274,223 @@ cmd_status()
}
#
+# Modify remote configuration in .gitmodules
+#
+cmd_remote()
+{
+ while test $# -ne 0
+ do
+ case "$1" in
+ -q|--quiet)
+ GIT_QUIET=1
+ shift
+ ;;
+ add|rm|show)
+ subcommand=$1
+ shift
+ ;;
+ set-url)
+ subcommand=set_url
+ shift
+ ;;
+ *)
+ break;;
+ esac
+ done
+
+ if test -z "$subcommand"
+ then
+ usage
+ fi
+
+ "cmd_remote_$subcommand" "$@"
+}
+
+#
+# Show remote configuration for a gitmodule
+#
+cmd_remote_show()
+{
+ while test $# -ne 0
+ do
+ case "$1" in
+ -v|--verbose)
+ verbose=1
+ shift
+ ;;
+ *)
+ sm_path="$1"
+ shift
+ break;;
+ esac
+ done
+
+ if test $# -ne 0
+ then
+ usage
+ fi
+
+ if test -z "$sm_path"
+ then
+ die "$(gettext "No submodule path specified")"
+ fi
+
+ sm_name=$(module_name "$sm_path") || exit
+
+ cd_to_toplevel
+
+ git config -f .gitmodules --get-regexp "submodule-remote\.$sm_name\..*\.url" 2>/dev/null |
+ while read key url
+ do
+ remote=$(echo "$key" | sed "s/submodule-remote\.$sm_name\.\(.*\)\.url/\1/")
+ section="submodule-remote.$sm_name.$remote"
+
+ if test -z "$verbose"
+ then
+ echo "$remote"
+ else
+ url=$(git config -f .gitmodules "$section.url" 2>/dev/null)
+ pushurl=$(git config -f .gitmodules "$section.pushurl" 2>/dev/null)
+
+ if test -z "$pushurl"
+ then
+ pushurl="$url"
+ fi
+
+ echo -e "$remote\t$url (fetch)"
+ echo -e "$remote\t$pushurl (push)"
+ fi
+ done
+}
+
+#
+# Add remote configuration to .gitmodules
+# This adds a new remote with the key
+# submodule-remote.$name.$remote.url set to the specified value
+# to .gitmodules.
+#
+cmd_remote_add()
+{
+ if test $# -ne 3
+ then
+ usage
+ fi
+
+ sm_path="$1"
+ remote_name="$2"
+ remote_url="$3"
+
+ sm_name=$(module_name "$sm_path") || exit
+ displaypath=$(relative_path "$sm_path")
+ key="submodule-remote.$sm_name.$remote_name.url"
+
+ if test -z "$remote_name"
+ then
+ die "$(eval_gettext "Empty remote name not allowed")"
+ fi
+
+ cd_to_toplevel
+
+ if git config -f .gitmodules "$key" >/dev/null 2>/dev/null
+ then
+ die "$(eval_gettext "Remote '\$remote_name' for submodule '\$sm_name' already present")"
+ fi
+
+ if git config -f .gitmodules "submodule-remote.$sm_name.$remote_name.url" "$remote_url"
+ then
+ say "$(eval_gettext "Remote '\$remote_name' added for path '\$displaypath'")"
+ else
+ die "$(eval_gettext "Remote '\$remote_name' could not be added for path '\$displaypath'")"
+ fi
+}
+
+#
+# Remove remote configuration from .gitmodules
+# This removes the remote for the specified submodule and remote
+# name.
+#
+cmd_remote_rm()
+{
+ if test $# -ne 2
+ then
+ usage
+ fi
+
+ sm_path="$1"
+ remote_name="$2"
+
+ sm_name=$(module_name "$sm_path") || exit
+ displaypath=$(relative_path "$sm_path")
+ section="submodule-remote.$sm_name.$remote_name"
+
+ if test -z "$remote_name"
+ then
+ die "$(eval_gettext "Empty remote name not allowed")"
+ fi
+
+ if ! git config -f .gitmodules "$section.url" >/dev/null 2>/dev/null
+ then
+ die "$(eval_gettext "No remote '\$remote_name' present for path '\$displaypath'")"
+ fi
+
+ if git config -f .gitmodules --remove-section "$section" >/dev/null 2>/dev/null
+ then
+ say "$(eval_gettext "Remote '\$remote_name' removed for path '\$displaypath'")"
+ else
+ die "$(eval_gettext "Remote '\$remote_name' could not be removed for path '\$displaypath'")"
+ fi
+}
+
+#
+# Change remote URL configuration in .gitmodules
+# This sets the values submodule-remote.$name.$remote.url and
+# submodule-remote.$name.$remote.pushurl in .gitmodules.
+#
+cmd_remote_set_url()
+{
+ if test $# -lt 3
+ then
+ usage
+ fi
+
+ if test "$1" = "--push"
+ then
+ push=1
+ shift
+ fi
+
+ sm_path="$1"
+ remote_name="$2"
+ url="$3"
+
+ sm_name=$(module_name "$sm_path") || exit
+ displaypath=$(relative_path "$sm_path")
+
+ if test -z "$remote_name"
+ then
+ die "$(eval_gettext "Empty remote name not allowed")"
+ fi
+
+ section="submodule-remote.$sm_name.$remote_name"
+ if test -z $push
+ then
+ key="$section.url"
+ else
+ key="$section.pushurl"
+ fi
+
+ if ! git config -f .gitmodules "$section.url" >/dev/null 2>/dev/null
+ then
+ die "$(eval_gettext "No remote '\$remote_name' specified for path '\$displaypath'")"
+ fi
+
+ if ! git config -f .gitmodules "$key" "$url"
+ then
+ die "$(eval_gettext "could not set URL for '\$displaypath'")"
+ fi
+}
+
+#
# Sync remote urls for submodules
# This makes the value for remote.$remote.url match the value
# specified in .gitmodules.
@@ -1386,7 +1607,7 @@ cmd_sync()
while test $# != 0 && test -z "$command"
do
case "$1" in
- add | foreach | init | deinit | update | status | summary | sync)
+ add | foreach | init | deinit | update | status | summary | sync | remote)
command=$1
;;
-q|--quiet)
--
2.3.5
next prev parent reply other threads:[~2015-04-08 11:17 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-08 10:58 [RFC/PATCH 0/4] submodule remotes Patrick Steinhardt
2015-04-08 10:58 ` [RFC/PATCH 1/4] submodules: implement synchronizing of remotes Patrick Steinhardt
2015-04-08 15:46 ` Junio C Hamano
2015-04-09 11:57 ` Patrick Steinhardt
2015-04-08 10:58 ` Patrick Steinhardt [this message]
2015-04-08 10:58 ` [RFC/PATCH 3/4] submodules: update docs to reflect remotes Patrick Steinhardt
2015-04-08 10:58 ` [RFC/PATCH 4/4] submodules: add bash completion for remotes Patrick Steinhardt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1428490705-11586-3-git-send-email-ps@pks.im \
--to=ps@pks.im \
--cc=Jens.Lehmann@web.de \
--cc=git@vger.kernel.org \
--cc=hvoigt@hvoigt.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).