* [PATCH 0/7] git-submodule enhancements @ 2008-03-13 17:56 Ping Yin 2008-03-13 17:56 ` [PATCH 1/7] git-submodule: Avoid 'fatal: cannot describe' message Ping Yin 2008-03-13 18:16 ` [PATCH 0/7] git-submodule enhancements Ping Yin 0 siblings, 2 replies; 10+ messages in thread From: Ping Yin @ 2008-03-13 17:56 UTC (permalink / raw) To: git; +Cc: gitster This patch series do following enhancements for git-submodule - Fall back on .gitmodules if info not found in $GIT_DIR/config - multi-level module definition - Don't die when command fails for one submodule with diffstat git-submodule.sh | 316 +++++++++++++++++++++++++++++++------------- t/t7400-submodule-basic.sh | 31 ++++- and commits git-submodule: Avoid 'fatal: cannot describe' message git-submodule: Extract functions module_info and module_url git-submodule: Extract absolute_url & move absolute url logic to module_clone git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config git-submodule: Extract module_add from cmd_add git-submodule: multi-level module definition git-submodule: Don't die when command fails for one submodule ^ permalink raw reply [flat|nested] 10+ messages in thread
* [PATCH 1/7] git-submodule: Avoid 'fatal: cannot describe' message 2008-03-13 17:56 [PATCH 0/7] git-submodule enhancements Ping Yin @ 2008-03-13 17:56 ` Ping Yin 2008-03-13 17:56 ` [PATCH 2/7] git-submodule: Extract functions module_info and module_url Ping Yin 2008-03-13 18:16 ` [PATCH 0/7] git-submodule enhancements Ping Yin 1 sibling, 1 reply; 10+ messages in thread From: Ping Yin @ 2008-03-13 17:56 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin When "git submodule status" command tries to show the name of the submodule HEAD revision more descriptively, but the submodule repository lacked a suitable tag to do so, it leaked "fatal: cannot describe" message to the UI. Squelch it by using '--always'. Signed-off-by: Ping Yin <pkufranky@gmail.com> --- git-submodule.sh | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 5f1d5ef..2f40620 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -327,7 +327,7 @@ set_name_rev () { cd "$1" && { git describe "$2" 2>/dev/null || git describe --tags "$2" 2>/dev/null || - git describe --contains --tags "$2" + git describe --contains --tags --always "$2" } ) ) test -z "$revname" || revname=" ($revname)" -- 1.5.4.4.653.g7cf1e ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 2/7] git-submodule: Extract functions module_info and module_url 2008-03-13 17:56 ` [PATCH 1/7] git-submodule: Avoid 'fatal: cannot describe' message Ping Yin @ 2008-03-13 17:56 ` Ping Yin 2008-03-13 17:56 ` [PATCH 3/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Ping Yin 0 siblings, 1 reply; 10+ messages in thread From: Ping Yin @ 2008-03-13 17:56 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin module_info is extracted to remove the logic redundance which acquires module names and urls by path filter in several places. module_url is also extracted to prepare for an alternative logic to get url by module name. Signed-off-by: Ping Yin <pkufranky@gmail.com> --- git-submodule.sh | 40 ++++++++++++++++++++++++++++------------ 1 files changed, 28 insertions(+), 12 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 2f40620..7545d1a 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -82,6 +82,25 @@ module_name() echo "$name" } +module_url() { + git config submodule.$1.url +} + +module_info() { + git ls-files --stage -- "$@" | grep -e '^160000 ' | + while read mode sha1 stage path + do + name=$(module_name "$path") + if test -n "$name" + then + url=$(module_url "$name") + echo "$sha1 $path $name $url" + else + echo "$sha1 $path " + fi + done +} + # # Clone a submodule # @@ -232,12 +251,11 @@ cmd_init() shift done - git ls-files --stage -- "$@" | grep -e '^160000 ' | - while read mode sha1 stage path + module_info "$@" | + while read sha1 path name url do + test -n "$name" || exit # Skip already registered paths - name=$(module_name "$path") || exit - url=$(git config submodule."$name".url) test -z "$url" || continue url=$(GIT_CONFIG=.gitmodules git config submodule."$name".url) @@ -286,11 +304,10 @@ cmd_update() shift done - git ls-files --stage -- "$@" | grep -e '^160000 ' | - while read mode sha1 stage path + module_info "$@" | + while read sha1 path name url do - name=$(module_name "$path") || exit - url=$(git config submodule."$name".url) + test -n "$name" || exit if test -z "$url" then # Only mention uninitialized submodules when its @@ -537,11 +554,10 @@ cmd_status() shift done - git ls-files --stage -- "$@" | grep -e '^160000 ' | - while read mode sha1 stage path + module_info "$@" | + while read sha1 path name url do - name=$(module_name "$path") || exit - url=$(git config submodule."$name".url) + test -n "$name" || exit if test -z "$url" || ! test -d "$path"/.git then say "-$sha1 $path" -- 1.5.4.4.653.g7cf1e ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 3/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone 2008-03-13 17:56 ` [PATCH 2/7] git-submodule: Extract functions module_info and module_url Ping Yin @ 2008-03-13 17:56 ` Ping Yin 2008-03-13 17:56 ` [PATCH 4/7] git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config Ping Yin 0 siblings, 1 reply; 10+ messages in thread From: Ping Yin @ 2008-03-13 17:56 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin Extract function absolute_url to remove code redundant and inconsistence in cmd_init and cmd_add when resolving relative url/path to absolute one. Also move resolving absolute url logic from cmd_add to module_clone which results in a litte behaviour change: cmd_update originally doesn't resolve absolute url but now it will. This behaviour change breaks t7400 which uses relative url './.subrepo'. However, this test originally doesn't mean to test relative url, so fix the url as '.subrepo'. Signed-off-by: Ping Yin <pkufranky@gmail.com> --- git-submodule.sh | 41 ++++++++++++++++++----------------------- t/t7400-submodule-basic.sh | 2 +- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 7545d1a..0e14078 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -65,6 +65,21 @@ resolve_relative_url () echo "$remoteurl/$url" } +# Resolve relative url/path to absolute one +absolute_url () { + case "$1" in + ./*|../*) + # dereference source url relative to parent's url + url="$(resolve_relative_url $1)" ;; + *) + # Turn the source into an absolute path if it is local + url=$(get_repo_base "$1") || + url=$1 + ;; + esac + echo "$url" +} + # # Map submodule path to submodule name # @@ -112,7 +127,7 @@ module_info() { module_clone() { path=$1 - url=$2 + url=$(absolute_url "$2") # If there already is a directory at the submodule path, # expect it to be empty (since that is the default checkout @@ -195,21 +210,7 @@ cmd_add() die "'$path' already exists and is not a valid git repo" fi else - case "$repo" in - ./*|../*) - # dereference source url relative to parent's url - realrepo="$(resolve_relative_url $repo)" ;; - *) - # Turn the source into an absolute path if - # it is local - if base=$(get_repo_base "$repo"); then - repo="$base" - fi - realrepo=$repo - ;; - esac - - module_clone "$path" "$realrepo" || exit + module_clone "$path" "$repo" || exit (unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) || die "Unable to checkout submodule '$path'" fi @@ -262,13 +263,7 @@ cmd_init() test -z "$url" && die "No url found for submodule path '$path' in .gitmodules" - # Possibly a url relative to parent - case "$url" in - ./*|../*) - url="$(resolve_relative_url "$url")" - ;; - esac - + url=$(absolute_url "$url") git config submodule."$name".url "$url" || die "Failed to register url for submodule path '$path'" diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index 2ef85a8..e5d59b8 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -75,7 +75,7 @@ test_expect_success 'init should register submodule url in .git/config' ' then echo "[OOPS] init succeeded but submodule url is wrong" false - elif ! git config submodule.example.url ./.subrepo + elif ! git config submodule.example.url .subrepo then echo "[OOPS] init succeeded but update of url failed" false -- 1.5.4.4.653.g7cf1e ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 4/7] git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config 2008-03-13 17:56 ` [PATCH 3/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Ping Yin @ 2008-03-13 17:56 ` Ping Yin 2008-03-13 17:56 ` [PATCH 5/7] git-submodule: Extract module_add from cmd_add Ping Yin 0 siblings, 1 reply; 10+ messages in thread From: Ping Yin @ 2008-03-13 17:56 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin Originally, the submodule workflow enforces 'git init' in the beginning which copies submodule config info from .gitmodules to $GIT_DIR/config. Then all subcommands except 'init' and 'add' fetch submodule info from $GIT_DIR/config and .gitmodules can be discarded. And there may be inconsistence between .git/config and .gitmodules when always using 'git init' at first. If upstream .gitmodules changes, it is not easy to sync the changes to $GIT_DIR/config. Running 'git init' again may not help. Since .git/config has a whole copy of .gitmodules, the user has no easy way to know which entries should follow the upstream changes and which entires shouldn't. Actually, .gitmodules which only acts as info hints can and should play a more important and essential role. As an analogy to .gitignore and .git/info/excludes which are for colleagues' and individual wishes separately, .gitmodules is for common requirements and $GIT_DIR/config is for special requirements. This patch implements a fall back strategy to satify both common and special requirements as follows. $GIT_DIR/config only keeps submodule info different from $GIT_DIR/config. And the info from $GIT_DIR/config take higher precedence. The code first consults $GIT_DIR/config and then fall back on in-tree .gitmodules file. With this patch, init subcommand becomes not forcefull and less meaningful. And now it becomes just a tool to help users copy info to $GIT_DIR/config (and then modify it) only when they need. Signed-off-by: Ping Yin <pkufranky@gmail.com> --- git-submodule.sh | 9 ++++----- t/t7400-submodule-basic.sh | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 0e14078..bd2934a 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -98,7 +98,8 @@ module_name() } module_url() { - git config submodule.$1.url + git config submodule.$1.url || + GIT_CONFIG=.gitmodules git config submodule.$1.url } module_info() { @@ -256,12 +257,10 @@ cmd_init() while read sha1 path name url do test -n "$name" || exit - # Skip already registered paths - test -z "$url" || continue - - url=$(GIT_CONFIG=.gitmodules git config submodule."$name".url) test -z "$url" && die "No url found for submodule path '$path' in .gitmodules" + # Skip already registered paths + git config submodule.$name.url && continue url=$(absolute_url "$url") git config submodule."$name".url "$url" || diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index e5d59b8..d9b48f7 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -174,6 +174,35 @@ test_expect_success 'status should be "up-to-date" after update' ' git-submodule status | grep "^ $rev1" ' +test_expect_success 'status should be "modified" after submodule reset --hard HEAD@{1}' ' + cd init && + git reset --hard HEAD@{1} + rev2=$(git rev-parse HEAD) && + cd .. && + if test -z "$rev2" + then + echo "[OOPS] submodule git rev-parse returned nothing" + false + fi && + git-submodule status | grep "^+$rev2" +' + +test_expect_success 'update should checkout rev1 when fall back' ' + git-config --unset submodule.example.url && + GIT_CONFIG=.gitmodules git config submodule.example.url .subrepo && + git-submodule update init && + head=$(cd init && git rev-parse HEAD) && + if test -z "$head" + then + echo "[OOPS] submodule git rev-parse returned nothing" + false + elif test "$head" != "$rev1" + then + echo "[OOPS] init did not checkout correct head" + false + fi +' + test_expect_success 'checkout superproject with subproject already present' ' git-checkout initial && git-checkout master -- 1.5.4.4.653.g7cf1e ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 5/7] git-submodule: Extract module_add from cmd_add 2008-03-13 17:56 ` [PATCH 4/7] git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config Ping Yin @ 2008-03-13 17:56 ` Ping Yin 2008-03-13 17:56 ` [PATCH 6/7] git-submodule: multi-level module definition Ping Yin 0 siblings, 1 reply; 10+ messages in thread From: Ping Yin @ 2008-03-13 17:56 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin cmd_add will later handle the case adding multiple modules, so extract module_add to add a single module. Signed-off-by: Ping Yin <pkufranky@gmail.com> --- git-submodule.sh | 67 +++++++++++++++++++++++++++++++---------------------- 1 files changed, 39 insertions(+), 28 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index bd2934a..dacd99a 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -155,34 +155,7 @@ module_clone() # # optional branch is stored in global branch variable # -cmd_add() -{ - # parse $args after "submodule ... add". - while test $# -ne 0 - do - case "$1" in - -b | --branch) - case "$2" in '') usage ;; esac - branch=$2 - shift - ;; - -q|--quiet) - quiet=1 - ;; - --) - shift - break - ;; - -*) - usage - ;; - *) - break - ;; - esac - shift - done - +module_add() { repo=$1 path=$2 @@ -226,6 +199,44 @@ cmd_add() } # +# Add a new submodule to the working tree, .gitmodules and the index +# +# $@ = repo [path] +# +# optional branch is stored in global branch variable +# +cmd_add() +{ + # parse $args after "submodule ... add". + while test $# -ne 0 + do + case "$1" in + -b | --branch) + case "$2" in '') usage ;; esac + branch=$2 + shift + ;; + -q|--quiet) + quiet=1 + ;; + --) + shift + break + ;; + -*) + usage + ;; + *) + break + ;; + esac + shift + done + + module_add "$1" "$2" +} + +# # Register submodules in .git/config # # $@ = requested paths (default to all) -- 1.5.4.4.653.g7cf1e ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 6/7] git-submodule: multi-level module definition 2008-03-13 17:56 ` [PATCH 5/7] git-submodule: Extract module_add from cmd_add Ping Yin @ 2008-03-13 17:56 ` Ping Yin 2008-03-13 17:56 ` [PATCH 7/7] git-submodule: Don't die when command fails for one submodule Ping Yin 2008-03-14 14:20 ` [PATCH 6/7] git-submodule: multi-level module definition Ping Yin 0 siblings, 2 replies; 10+ messages in thread From: Ping Yin @ 2008-03-13 17:56 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin This patch introduces multi-level module definition and '--module-name' option to designate submodules by logical names instead of path filters. Then the init/update/status/add subcommand is enhanced combined with this option. The multi-level module definition in .gitmodules was first suggested by Linus and etc. in mails "Let .git/config specify the url for submodules" (http://article.gmane.org/gmane.comp.version-control.git/48939). Following shows an example of such a .gitmodules which finally comes from the group notation of 'git remote' which is suggested by Johannes Schindelin. .gitmodules with multiple level of indirection ------------------------------------------------------ [submodules] service = crawler search crawler = util imcrawter search = util imsearch [submodule "util"] url = git://xyzzy/util.git [submodule "imsearch"] path = search/imsearch url = git://xyzzy/imsearch.git [submodule "imcrawler"] path = crawler/imcrawter url = git://xyzzy/imcrawter.git ------------------------------------------------------ By adding the 'submodules' section, we can define multi-level modules in an infinite levels of indirection. The "-m|--module-name" option is introduced with which submodules are designated by logical names instead of real paths as following shows. Identical commands forms with/without "--module-name" --------------------------------------------------- $ git submodule XXX util imcrawler (1) $ git submodule XXX -n crawler (2) $ git submodule XXX util imcrawler imsearch (3) $ git submodule XXX -n service (4) $ git submodule XXX -n crawler search (5) --------------------------------------------------- * XXX represents status, update or init, but not add * (1) and (2) are identical conditionally (explained below) * (3), (4) and (5) are identical conditionally There are still minor difference between these two forms. In the no "--module-name" form, the path parameter may be not the real submodule path, and it just acts as the filter for real submodule paths. While in the "--module-name" form, the name parameter must be the logical name, and the real paths corresponding to the logical name may be neither a submodule path nor even existent. This patch handles such a path for different subcommands as follows. - status: Output 0{40} as the sha1. Doing this can remind the user to add the path as submodule or delete the path from .gitmodules. - update: Skip that path and issue a "Not a submodule" warning - init: Also init for that path So in the example above, commands (1) and (2) are identical only when util and imcrawler are already submodules. The add subcommand is also enhanced. The former workflow to add submodules is adding one by one with "git submodule add url path" which then modifies .gitmodules. However, sometimes it is more convenient to work in the reverse way: edit .gitmodules first and then add submodules in batch. Now "git submodule add --module-name modulename" can help us to do that. It will find all submodules corresponding to the logical name and add them in batch by using the paths and urls from .gitmodules. Of course, it will skip the paths which have already been submodules. Signed-off-by: Ping Yin <pkufranky@gmail.com> --- git-submodule.sh | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 files changed, 81 insertions(+), 5 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index dacd99a..79fb30f 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -4,7 +4,7 @@ # # Copyright (c) 2007 Lars Hjemli -USAGE="[--quiet] [--cached] \ +USAGE="[--quiet] [--cached] [--module-name] \ [add <repo> [-b branch]|status|init|update|summary [-n|--summary-limit <n>] [<commit>]] \ [--] [<path>...]" OPTIONS_SPEC= @@ -15,6 +15,7 @@ command= branch= quiet= cached= +use_module_name= # # print stuff on stdout unless -q was specified @@ -97,12 +98,23 @@ module_name() echo "$name" } +module_path() { + git config submodule.$1.path || + GIT_CONFIG=.gitmodules git config submodule.$1.path || + echo "$1" +} + module_url() { git config submodule.$1.url || GIT_CONFIG=.gitmodules git config submodule.$1.url } module_info() { + if test -n "$use_module_name" + then + module_info_by_name "$@" + return + fi git ls-files --stage -- "$@" | grep -e '^160000 ' | while read mode sha1 stage path do @@ -118,6 +130,50 @@ module_info() { } # +# List all submodule info line by line by given names as follows +# sha1<tab>path<tab>name<tab>url +# +# Here we assume that module names and paths don't contain space +# characters +# +# $@ = module names +# When names is not given, list all module info +# +module_info_by_name() { + if test $# = 0 + then + names=$( + { + git config --get-regexp 'submodule.*.url' + git config -f .gitmodules --get-regexp 'submodule.*.url' + } | sed 's/submodule.\(.*\).url .*$/\1/' 2>/dev/null + ) + else + names=$(module_children_names "$@") + fi + for name in $names + do + url=$(module_url "$name") || continue + path=$(module_path "$name") + sha1=$(git ls-files --stage "$path" | + grep "$path$" | grep '^160000' | awk '{print $2}') + test -z "$sha1" && sha1=0000000000000000000000000000000000000000 + echo "$sha1 $path $name $url" + done +} + +module_children_names() { + for name + do + echo "$name" + module_children_names $( + git config "submodules.$name" + git config -f .gitmodules "submodules.$name" + ) + done | sort -u +} + +# # Clone a submodule # # Prior to calling, cmd_update checks that a possibly existing @@ -233,7 +289,17 @@ cmd_add() shift done - module_add "$1" "$2" + if test -n "$use_module_name" + then + module_info "$@" | + while read sha1 path name url + do + module_add "$url" "$path" + done + else + module_add "$1" "$2" + fi + } # @@ -313,7 +379,11 @@ cmd_update() while read sha1 path name url do test -n "$name" || exit - if test -z "$url" + if test $sha1 = 0000000000000000000000000000000000000000 + then + say "Not a submodule: $name @ $path" + continue + elif test -z "$url" then # Only mention uninitialized submodules when its # path have been specified @@ -558,12 +628,15 @@ cmd_status() esac shift done - module_info "$@" | while read sha1 path name url do test -n "$name" || exit - if test -z "$url" || ! test -d "$path"/.git + if test $sha1 = 0000000000000000000000000000000000000000 + then + say "*$sha1 $path" + continue + elif test -z "$url" || ! test -d "$path"/.git then say "-$sha1 $path" continue; @@ -609,6 +682,9 @@ do --cached) cached="$1" ;; + -m|--module-name) + use_module_name=1 + ;; --) break ;; -- 1.5.4.4.653.g7cf1e ^ permalink raw reply related [flat|nested] 10+ messages in thread
* [PATCH 7/7] git-submodule: Don't die when command fails for one submodule 2008-03-13 17:56 ` [PATCH 6/7] git-submodule: multi-level module definition Ping Yin @ 2008-03-13 17:56 ` Ping Yin 2008-03-14 14:20 ` [PATCH 6/7] git-submodule: multi-level module definition Ping Yin 1 sibling, 0 replies; 10+ messages in thread From: Ping Yin @ 2008-03-13 17:56 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin When handling multiple modules, init/update/status/add subcommand will exit when it fails for one submodule. This patch makes the subcommand continue bypassing the failure and keep right exit status. Signed-off-by: Ping Yin <pkufranky@gmail.com> --- git-submodule.sh | 87 +++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 63 insertions(+), 24 deletions(-) diff --git a/git-submodule.sh b/git-submodule.sh index 79fb30f..e78d797 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -193,15 +193,19 @@ module_clone() # succeed but the rmdir will fail. We might want to fix this. if test -d "$path" then - rmdir "$path" 2>/dev/null || - die "Directory '$path' exist, but is neither empty nor a git repository" + ! rmdir "$path" 2>/dev/null && + say "Directory '$path' exist, but is neither empty nor a git repository" && + return 1 fi test -e "$path" && - die "A file already exist at path '$path'" + say "A file already exist at path '$path'" && + return 1 - git-clone -n "$url" "$path" || - die "Clone of '$url' into submodule path '$path' failed" + ! git-clone -n "$url" "$path" && + say "Clone of '$url' into submodule path '$path' failed" && + return 1 + : } # @@ -227,7 +231,8 @@ module_add() { fi git ls-files --error-unmatch "$path" > /dev/null 2>&1 && - die "'$path' already exists in the index" + say "'$path' already exists in the index" && + return 1 # perhaps the path exists and is already a git repo, else clone it if test -e "$path" @@ -237,21 +242,26 @@ module_add() { then echo "Adding existing repo at '$path' to the index" else - die "'$path' already exists and is not a valid git repo" + say "'$path' already exists and is not a valid git repo" + return 1 fi else - module_clone "$path" "$repo" || exit - (unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) || - die "Unable to checkout submodule '$path'" + module_clone "$path" "$repo" || return 1 + ! (unset GIT_DIR; cd "$path" && git checkout -q ${branch:+-b "$branch" "origin/$branch"}) && + say "Unable to checkout submodule '$path'" && + return 1 fi - git add "$path" || - die "Failed to add submodule '$path'" + ! git add "$path" && + say "Failed to add submodule '$path'" && + return 1 GIT_CONFIG=.gitmodules git config submodule."$path".path "$path" && GIT_CONFIG=.gitmodules git config submodule."$path".url "$repo" && - git add .gitmodules || - die "Failed to register submodule '$path'" + ! git add .gitmodules && + say "Failed to register submodule '$path'" && + return 1 + : } # @@ -292,14 +302,17 @@ cmd_add() if test -n "$use_module_name" then module_info "$@" | + { + exit_status=0 while read sha1 path name url do - module_add "$url" "$path" + module_add "$url" "$path" || exit_status=1 done + test $exit_status = 0 + } else module_add "$1" "$2" fi - } # @@ -331,20 +344,30 @@ cmd_init() done module_info "$@" | + { + exit_status=0 while read sha1 path name url do - test -n "$name" || exit + test -z "$name" && exit_status=1 && continue test -z "$url" && - die "No url found for submodule path '$path' in .gitmodules" + say "No url found for submodule path '$path' in .gitmodules" && + exit_status=1 && + continue # Skip already registered paths git config submodule.$name.url && continue url=$(absolute_url "$url") git config submodule."$name".url "$url" || - die "Failed to register url for submodule path '$path'" + { + say "Failed to register url for submodule path '$path'" + exit_status=1 + continue + } say "Submodule '$name' ($url) registered for path '$path'" done + exit $exit_status + } } # @@ -376,9 +399,11 @@ cmd_update() done module_info "$@" | + { + exit_status=0 while read sha1 path name url do - test -n "$name" || exit + test -z "$name" && exit_status=1 && continue if test $sha1 = 0000000000000000000000000000000000000000 then say "Not a submodule: $name @ $path" @@ -394,23 +419,33 @@ cmd_update() if ! test -d "$path"/.git then - module_clone "$path" "$url" || exit + ! module_clone "$path" "$url" && exit_status=1 && continue subsha1= else subsha1=$(unset GIT_DIR; cd "$path" && git rev-parse --verify HEAD) || - die "Unable to find current revision in submodule path '$path'" + { + say "Unable to find current revision in submodule path '$path'" + exit_status=1 + continue + } fi if test "$subsha1" != "$sha1" then (unset GIT_DIR; cd "$path" && git-fetch && git-checkout -q "$sha1") || - die "Unable to checkout '$sha1' in submodule path '$path'" + { + say "Unable to checkout '$sha1' in submodule path '$path'" + exit_status=1 + continue + } say "Submodule path '$path': checked out '$sha1'" fi done + exit $exit_status + } } set_name_rev () { @@ -629,9 +664,11 @@ cmd_status() shift done module_info "$@" | + { + exit_status=0 while read sha1 path name url do - test -n "$name" || exit + test -z "$name" && exit_status=1 && continue if test $sha1 = 0000000000000000000000000000000000000000 then say "*$sha1 $path" @@ -654,6 +691,8 @@ cmd_status() say "+$sha1 $path$revname" fi done + exit $exit_status + } } # This loop parses the command line arguments to find the -- 1.5.4.4.653.g7cf1e ^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [PATCH 6/7] git-submodule: multi-level module definition 2008-03-13 17:56 ` [PATCH 6/7] git-submodule: multi-level module definition Ping Yin 2008-03-13 17:56 ` [PATCH 7/7] git-submodule: Don't die when command fails for one submodule Ping Yin @ 2008-03-14 14:20 ` Ping Yin 1 sibling, 0 replies; 10+ messages in thread From: Ping Yin @ 2008-03-14 14:20 UTC (permalink / raw) To: git; +Cc: gitster, Ping Yin On Fri, Mar 14, 2008 at 1:56 AM, Ping Yin <pkufranky@gmail.com> wrote: > In the no "--module-name" form, the path parameter may be not the real > submodule path, and it just acts as the filter for real submodule paths. > While in the "--module-name" form, the name parameter must be the logical > name, and the real paths corresponding to the logical name may be neither > a submodule path nor even existent. > > This patch handles such a path for different subcommands as follows. > > - status: Output 0{40} as the sha1. Doing this can remind the user to > add the path as submodule or delete the path from .gitmodules. > - update: Skip that path and issue a "Not a submodule" warning Sometime it's useful to also update (or clone) the non-submodule instead of "Not as submodule" warning. So we can add a --force option to allow this kind of behaviour. There are cases that we want to clone a group of repositories in batch. One way is to put all urls and paths of these repositories in .gitmodules which form a submodule group, for example "all", and then run "git submodule --module-name update --force all" which will clone all the repositories in batch even if they are not submodules yet. Another way is use the "git submodule --module-name recurse clone" (recurse patch series sent many days ago but not accept yet). But this needs some discuss since we have no place for the module group name "all" as the argument. There may be other ways. i don't know which way is better and don't care much now. What i care is whether the submodule subcommand should operate on the non-submodule path. More precisely, with --module-name, we can designate a group of names by a logical group name. However, some paths corresponding to these names may not be submodules yet. So should the submodule subcommands (especially update for now) operate on these paths? -- Ping Yin ^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH 0/7] git-submodule enhancements 2008-03-13 17:56 [PATCH 0/7] git-submodule enhancements Ping Yin 2008-03-13 17:56 ` [PATCH 1/7] git-submodule: Avoid 'fatal: cannot describe' message Ping Yin @ 2008-03-13 18:16 ` Ping Yin 1 sibling, 0 replies; 10+ messages in thread From: Ping Yin @ 2008-03-13 18:16 UTC (permalink / raw) To: git; +Cc: gitster On Fri, Mar 14, 2008 at 1:56 AM, Ping Yin <pkufranky@gmail.com> wrote: > This patch series do following enhancements for git-submodule > > - Fall back on .gitmodules if info not found in $GIT_DIR/config > - multi-level module definition > - Don't die when command fails for one submodule And it's built on next -- Ping Yin ^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2008-03-14 14:21 UTC | newest] Thread overview: 10+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2008-03-13 17:56 [PATCH 0/7] git-submodule enhancements Ping Yin 2008-03-13 17:56 ` [PATCH 1/7] git-submodule: Avoid 'fatal: cannot describe' message Ping Yin 2008-03-13 17:56 ` [PATCH 2/7] git-submodule: Extract functions module_info and module_url Ping Yin 2008-03-13 17:56 ` [PATCH 3/7] git-submodule: Extract absolute_url & move absolute url logic to module_clone Ping Yin 2008-03-13 17:56 ` [PATCH 4/7] git-submodule: Fall back on .gitmodules if info not found in $GIT_DIR/config Ping Yin 2008-03-13 17:56 ` [PATCH 5/7] git-submodule: Extract module_add from cmd_add Ping Yin 2008-03-13 17:56 ` [PATCH 6/7] git-submodule: multi-level module definition Ping Yin 2008-03-13 17:56 ` [PATCH 7/7] git-submodule: Don't die when command fails for one submodule Ping Yin 2008-03-14 14:20 ` [PATCH 6/7] git-submodule: multi-level module definition Ping Yin 2008-03-13 18:16 ` [PATCH 0/7] git-submodule enhancements Ping Yin
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).