Skip to content

Commit

Permalink
Merge branch 'da/submodule-sync'
Browse files Browse the repository at this point in the history
* da/submodule-sync:
  git-submodule: add "sync" command
  • Loading branch information
Junio C Hamano committed Aug 27, 2008
2 parents bb34ca5 + 2327f61 commit bb0d283
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
9 changes: 9 additions & 0 deletions Documentation/git-submodule.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SYNOPSIS
'git submodule' [--quiet] update [--init] [--] [<path>...]
'git submodule' [--quiet] summary [--summary-limit <n>] [commit] [--] [<path>...]
'git submodule' [--quiet] foreach <command>
'git submodule' [--quiet] sync [--] [<path>...]


DESCRIPTION
Expand Down Expand Up @@ -139,6 +140,14 @@ foreach::
As an example, "git submodule foreach 'echo $path `git rev-parse HEAD`' will
show the path and currently checked out commit for each submodule.

sync::
Synchronizes submodules' remote URL configuration setting
to the value specified in .gitmodules. This is useful when
submodule URLs change upstream and you need to update your local
repositories accordingly.
+
"git submodule sync" synchronizes all submodules while
"git submodule sync -- A" synchronizes submodule "A" only.

OPTIONS
-------
Expand Down
48 changes: 46 additions & 2 deletions git-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit bb0d283

Please sign in to comment.