Use the new rev-parse --prefix option to process all paths given to the submodule command, dropping the requirement that it be run from the top-level of the repository. Signed-off-by: John Keeping <john@xxxxxxxxxxxxx> --- git-submodule.sh | 7 +++++++ t/t7400-submodule-basic.sh | 26 ++++++++++++++++++++++++++ t/t7401-submodule-summary.sh | 9 +++++++++ 3 files changed, 42 insertions(+) diff --git a/git-submodule.sh b/git-submodule.sh index 79bfaac..bbf7983 100755 --- a/git-submodule.sh +++ b/git-submodule.sh @@ -14,10 +14,13 @@ USAGE="[--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <re or: $dashless [--quiet] foreach [--recursive] <command> or: $dashless [--quiet] sync [--recursive] [--] [<path>...]" OPTIONS_SPEC= +SUBDIRECTORY_OK=Yes . git-sh-setup . git-sh-i18n . git-parse-remote require_work_tree +wt_prefix=$(git rev-parse --show-prefix) +cd_to_toplevel command= branch= @@ -112,6 +115,7 @@ resolve_relative_url () # module_list() { + eval "set $(git rev-parse --sq --prefix "$wt_prefix" -- "$@")" ( git ls-files --error-unmatch --stage -- "$@" || echo "unmatched pathspec exists" @@ -335,6 +339,8 @@ cmd_add() usage fi + sm_path="$wt_prefix$sm_path" + # assure repo is absolute or relative to parent case "$repo" in ./*|../*) @@ -942,6 +948,7 @@ cmd_summary() { fi cd_to_toplevel + eval "set $(git rev-parse --sq --prefix "$wt_prefix" -- "$@")" # Get modified modules cared by user modules=$(git $diff_cmd $cached --ignore-submodules=dirty --raw $head -- "$@" | sane_egrep '^:([0-7]* )?160000' | diff --git a/t/t7400-submodule-basic.sh b/t/t7400-submodule-basic.sh index ff26535..7795f21 100755 --- a/t/t7400-submodule-basic.sh +++ b/t/t7400-submodule-basic.sh @@ -212,6 +212,23 @@ test_expect_success 'submodule add with ./, /.. and // in path' ' test_cmp empty untracked ' +test_expect_success 'submodule add in subdir' ' + echo "refs/heads/master" >expect && + >empty && + ( + mkdir addtest/sub && + cd addtest/sub && + git submodule add "$submodurl" ../realsubmod3 && + git submodule init + ) && + + rm -f heads head untracked && + inspect addtest/realsubmod3 ../.. && + test_cmp expect heads && + test_cmp expect head && + test_cmp empty untracked +' + test_expect_success 'setup - add an example entry to .gitmodules' ' GIT_CONFIG=.gitmodules \ git config submodule.example.url git://example.com/init.git @@ -319,6 +336,15 @@ test_expect_success 'status should be "up-to-date" after update' ' grep "^ $rev1" list ' +test_expect_success 'status works correctly from a subdirectory' ' + mkdir sub && + ( + cd sub && + git submodule status >../list + ) && + grep "^ $rev1" list +' + test_expect_success 'status should be "modified" after submodule commit' ' ( cd init && diff --git a/t/t7401-submodule-summary.sh b/t/t7401-submodule-summary.sh index 30b429e..8f5c1e0 100755 --- a/t/t7401-submodule-summary.sh +++ b/t/t7401-submodule-summary.sh @@ -45,6 +45,15 @@ EOF test_cmp expected actual " +test_expect_success 'run summary from subdir' ' + mkdir sub && + ( + cd sub && + git submodule summary >../actual + ) && + test_cmp expected actual +' + commit_file sm1 && head2=$(add_file sm1 foo3) -- 1.8.2.694.ga76e9c3.dirty -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html