Skip to content

Commit

Permalink
submodule: fix handling of superproject origin URLs like foo, ./foo a…
Browse files Browse the repository at this point in the history
…nd ./foo/bar

Currently git submodule init and git submodule sync fail with an error
if the superproject origin URL is of the form foo but succeed if the
superproject origin URL is of the form ./foo or ./foo/bar or foo/bar.

This change makes handling of the foo case behave like the handling
of the ./foo case and also ensures that superfluous leading and
embedded ./'s are removed from the resulting derived URLs.

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jon Seymour authored and Junio C Hamano committed Jun 6, 2012
1 parent 967b2c6 commit 758615e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
14 changes: 12 additions & 2 deletions git-submodule.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,12 @@ resolve_relative_url ()
*:*|/*)
is_relative=
;;
./*|../*)
is_relative=t
;;
*)
is_relative=t
remoteurl="./$remoteurl"
;;
esac

Expand All @@ -79,7 +83,12 @@ resolve_relative_url ()
sep=:
;;
*)
die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")"
if test -z "$is_relative" || test "." = "$remoteurl"
then
die "$(eval_gettext "cannot strip one component off url '\$remoteurl'")"
else
remoteurl=.
fi
;;
esac
;;
Expand All @@ -90,7 +99,8 @@ resolve_relative_url ()
break;;
esac
done
echo "${is_relative:+${up_path}}$remoteurl$sep${url%/}"
remoteurl="$remoteurl$sep${url%/}"
echo "${is_relative:+${up_path}}${remoteurl#./}"
}

#
Expand Down
6 changes: 3 additions & 3 deletions t/t7400-submodule-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ test_expect_success '../subrepo works with scp-style URL - user@host:path/to/rep
)
'

test_expect_failure '../subrepo works with relative local path - foo' '
test_expect_success '../subrepo works with relative local path - foo' '
(
cd reltest &&
cp pristine-.git-config .git/config &&
Expand All @@ -587,7 +587,7 @@ test_expect_success '../subrepo works with relative local path - foo/bar' '
)
'

test_expect_failure '../subrepo works with relative local path - ./foo' '
test_expect_success '../subrepo works with relative local path - ./foo' '
(
cd reltest &&
cp pristine-.git-config .git/config &&
Expand All @@ -598,7 +598,7 @@ test_expect_failure '../subrepo works with relative local path - ./foo' '
)
'

test_expect_failure '../subrepo works with relative local path - ./foo/bar' '
test_expect_success '../subrepo works with relative local path - ./foo/bar' '
(
cd reltest &&
cp pristine-.git-config .git/config &&
Expand Down
6 changes: 3 additions & 3 deletions t/t7403-submodule-sync.sh
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ test_expect_success '"git submodule sync" should not vivify uninteresting submod
)
'

test_expect_failure '"git submodule sync" handles origin URL of the form foo' '
test_expect_success '"git submodule sync" handles origin URL of the form foo' '
(cd relative-clone &&
git remote set-url origin foo &&
git submodule sync &&
Expand All @@ -110,7 +110,7 @@ test_expect_success '"git submodule sync" handles origin URL of the form foo/bar
)
'

test_expect_failure '"git submodule sync" handles origin URL of the form ./foo' '
test_expect_success '"git submodule sync" handles origin URL of the form ./foo' '
(cd relative-clone &&
git remote set-url origin ./foo &&
git submodule sync &&
Expand All @@ -121,7 +121,7 @@ test_expect_failure '"git submodule sync" handles origin URL of the form ./foo'
)
'

test_expect_failure '"git submodule sync" handles origin URL of the form ./foo/bar' '
test_expect_success '"git submodule sync" handles origin URL of the form ./foo/bar' '
(cd relative-clone &&
git remote set-url origin ./foo/bar &&
git submodule sync &&
Expand Down

0 comments on commit 758615e

Please sign in to comment.