aboutsummaryrefslogtreecommitdiff
path: root/git-submodule.sh
diff options
context:
space:
mode:
authorDavid Aguilar <davvid@gmail.com>2008-08-24 12:43:37 -0700
committerJunio C Hamano <gitster@pobox.com>2008-08-25 22:48:01 -0700
commit2327f61ecc4e9fbb6dd9fffdec0b043aeaca908f (patch)
tree529417e97ebcd5553e810e02f15321d91f516667 /git-submodule.sh
parent27a6ed492b3962d8214a196e57e8969ff9772249 (diff)
downloadgit-2327f61ecc4e9fbb6dd9fffdec0b043aeaca908f.tar.gz
git-2327f61ecc4e9fbb6dd9fffdec0b043aeaca908f.tar.xz
git-submodule: add "sync" command
When a submodule's URL changes upstream, existing submodules will be out of sync since their remote."$origin".url will still be set to the old value. This adds a "git submodule sync" command that reads submodules' URLs from .gitmodules and updates them accordingly. Signed-off-by: David Aguilar <davvid@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-submodule.sh')
-rwxr-xr-xgit-submodule.sh48
1 files changed, 46 insertions, 2 deletions
diff --git a/git-submodule.sh b/git-submodule.sh
index 59fe7b335..4a95035d8 100755
--- a/git-submodule.sh
+++ b/git-submodule.sh
@@ -6,7 +6,7 @@
USAGE="[--quiet] [--cached] \
[add <repo> [-b branch] <path>]|[status|init|update [-i|--init]|summary [-n|--summary-limit <n>] [<commit>]] \
-[--] [<path>...]|[foreach <command>]"
+[--] [<path>...]|[foreach <command>]|[sync [--] [<path>...]]"
OPTIONS_SPEC=
. git-sh-setup
. git-parse-remote
@@ -601,6 +601,50 @@ cmd_status()
fi
done
}
+#
+# Sync remote urls for submodules
+# This makes the value for remote.$remote.url match the value
+# specified in .gitmodules.
+#
+cmd_sync()
+{
+ while test $# -ne 0
+ do
+ case "$1" in
+ -q|--quiet)
+ quiet=1
+ shift
+ ;;
+ --)
+ shift
+ break
+ ;;
+ -*)
+ usage
+ ;;
+ *)
+ break
+ ;;
+ esac
+ done
+ cd_to_toplevel
+ module_list "$@" |
+ while read mode sha1 stage path
+ do
+ name=$(module_name "$path")
+ url=$(git config -f .gitmodules --get submodule."$name".url)
+ if test -e "$path"/.git
+ then
+ (
+ unset GIT_DIR
+ cd "$path"
+ remote=$(get_default_remote)
+ say "Synchronizing submodule url for '$name'"
+ git config remote."$remote".url "$url"
+ )
+ fi
+ done
+}
# This loop parses the command line arguments to find the
# subcommand name to dispatch. Parsing of the subcommand specific
@@ -611,7 +655,7 @@ cmd_status()
while test $# != 0 && test -z "$command"
do
case "$1" in
- add | foreach | init | update | status | summary)
+ add | foreach | init | update | status | summary | sync)
command=$1
;;
-q|--quiet)