Merge branch 'lh/submodule'
* lh/submodule: gitmodules(5): remove leading period from synopsis Add gitmodules(5) git-submodule: give submodules proper names Rename sections from "module" to "submodule" in .gitmodules git-submodule: remember to checkout after clone t7400: barf if git-submodule removes or replaces a file
This commit is contained in:
@ -2,7 +2,7 @@ MAN1_TXT= \
|
|||||||
$(filter-out $(addsuffix .txt, $(ARTICLES) $(SP_ARTICLES)), \
|
$(filter-out $(addsuffix .txt, $(ARTICLES) $(SP_ARTICLES)), \
|
||||||
$(wildcard git-*.txt)) \
|
$(wildcard git-*.txt)) \
|
||||||
gitk.txt
|
gitk.txt
|
||||||
MAN5_TXT=gitattributes.txt gitignore.txt
|
MAN5_TXT=gitattributes.txt gitignore.txt gitmodules.txt
|
||||||
MAN7_TXT=git.txt
|
MAN7_TXT=git.txt
|
||||||
|
|
||||||
DOC_HTML=$(patsubst %.txt,%.html,$(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT))
|
DOC_HTML=$(patsubst %.txt,%.html,$(MAN1_TXT) $(MAN5_TXT) $(MAN7_TXT))
|
||||||
|
62
Documentation/gitmodules.txt
Normal file
62
Documentation/gitmodules.txt
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
gitmodules(5)
|
||||||
|
=============
|
||||||
|
|
||||||
|
NAME
|
||||||
|
----
|
||||||
|
gitmodules - defining submodule properties
|
||||||
|
|
||||||
|
SYNOPSIS
|
||||||
|
--------
|
||||||
|
gitmodules
|
||||||
|
|
||||||
|
|
||||||
|
DESCRIPTION
|
||||||
|
-----------
|
||||||
|
|
||||||
|
The `.gitmodules` file, located in the top-level directory of a git
|
||||||
|
working tree, is a text file with a syntax matching the requirements
|
||||||
|
of gitlink:git-config[1].
|
||||||
|
|
||||||
|
The file contains one subsection per submodule, and the subsection value
|
||||||
|
is the name of the submodule. Each submodule section also contains the
|
||||||
|
following required keys:
|
||||||
|
|
||||||
|
submodule.<name>.path::
|
||||||
|
Defines the path, relative to the top-level directory of the git
|
||||||
|
working tree, where the submodule is expected to be checked out.
|
||||||
|
The path name must not end with a `/`. All submodule paths must
|
||||||
|
be unique within the .gitmodules file.
|
||||||
|
|
||||||
|
submodule.<name>.url::
|
||||||
|
Defines an url from where the submodule repository can be cloned.
|
||||||
|
|
||||||
|
|
||||||
|
EXAMPLES
|
||||||
|
--------
|
||||||
|
|
||||||
|
Consider the following .gitmodules file:
|
||||||
|
|
||||||
|
[submodule "libfoo"]
|
||||||
|
path = include/foo
|
||||||
|
url = git://foo.com/git/lib.git
|
||||||
|
|
||||||
|
[submodule "libbar"]
|
||||||
|
path = include/bar
|
||||||
|
url = git://bar.com/git/lib.git
|
||||||
|
|
||||||
|
|
||||||
|
This defines two submodules, `libfoo` and `libbar`. These are expected to
|
||||||
|
be checked out in the paths 'include/foo' and 'include/bar', and for both
|
||||||
|
submodules an url is specified which can be used for cloning the submodules.
|
||||||
|
|
||||||
|
SEE ALSO
|
||||||
|
--------
|
||||||
|
gitlink:git-submodule[1] gitlink:git-config[1]
|
||||||
|
|
||||||
|
DOCUMENTATION
|
||||||
|
-------------
|
||||||
|
Documentation by Lars Hjemli <hjemli@gmail.com>
|
||||||
|
|
||||||
|
GIT
|
||||||
|
---
|
||||||
|
Part of the gitlink:git[7] suite
|
@ -25,6 +25,19 @@ say()
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Map submodule path to submodule name
|
||||||
|
#
|
||||||
|
# $1 = path
|
||||||
|
#
|
||||||
|
module_name()
|
||||||
|
{
|
||||||
|
name=$(GIT_CONFIG=.gitmodules git-config --get-regexp '^submodule\..*\.path$' "$1" |
|
||||||
|
sed -nre 's/^submodule\.(.+)\.path .+$/\1/p')
|
||||||
|
test -z "$name" &&
|
||||||
|
die "No submodule mapping found in .gitmodules for path '$path'"
|
||||||
|
echo "$name"
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# Clone a submodule
|
# Clone a submodule
|
||||||
@ -49,7 +62,7 @@ module_clone()
|
|||||||
die "A file already exist at path '$path'"
|
die "A file already exist at path '$path'"
|
||||||
|
|
||||||
git-clone -n "$url" "$path" ||
|
git-clone -n "$url" "$path" ||
|
||||||
die "Clone of submodule '$path' failed"
|
die "Clone of '$url' into submodule path '$path' failed"
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
@ -63,17 +76,18 @@ modules_init()
|
|||||||
while read mode sha1 stage path
|
while read mode sha1 stage path
|
||||||
do
|
do
|
||||||
# Skip already registered paths
|
# Skip already registered paths
|
||||||
url=$(git-config submodule."$path".url)
|
name=$(module_name "$path") || exit
|
||||||
|
url=$(git-config submodule."$name".url)
|
||||||
test -z "$url" || continue
|
test -z "$url" || continue
|
||||||
|
|
||||||
url=$(GIT_CONFIG=.gitmodules git-config module."$path".url)
|
url=$(GIT_CONFIG=.gitmodules git-config submodule."$name".url)
|
||||||
test -z "$url" &&
|
test -z "$url" &&
|
||||||
die "No url found for submodule '$path' in .gitmodules"
|
die "No url found for submodule path '$path' in .gitmodules"
|
||||||
|
|
||||||
git-config submodule."$path".url "$url" ||
|
git-config submodule."$name".url "$url" ||
|
||||||
die "Failed to register url for submodule '$path'"
|
die "Failed to register url for submodule path '$path'"
|
||||||
|
|
||||||
say "Submodule '$path' registered with url '$url'"
|
say "Submodule '$name' ($url) registered for path '$path'"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,38 +101,40 @@ modules_update()
|
|||||||
git ls-files --stage -- "$@" | grep -e '^160000 ' |
|
git ls-files --stage -- "$@" | grep -e '^160000 ' |
|
||||||
while read mode sha1 stage path
|
while read mode sha1 stage path
|
||||||
do
|
do
|
||||||
url=$(git-config submodule."$path".url)
|
name=$(module_name "$path") || exit
|
||||||
|
url=$(git-config submodule."$name".url)
|
||||||
if test -z "$url"
|
if test -z "$url"
|
||||||
then
|
then
|
||||||
# Only mention uninitialized submodules when its
|
# Only mention uninitialized submodules when its
|
||||||
# path have been specified
|
# path have been specified
|
||||||
test "$#" != "0" &&
|
test "$#" != "0" &&
|
||||||
say "Submodule '$path' not initialized"
|
say "Submodule path '$path' not initialized"
|
||||||
continue
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! test -d "$path"/.git
|
if ! test -d "$path"/.git
|
||||||
then
|
then
|
||||||
module_clone "$path" "$url" || exit
|
module_clone "$path" "$url" || exit
|
||||||
|
subsha1=
|
||||||
|
else
|
||||||
|
subsha1=$(unset GIT_DIR && cd "$path" &&
|
||||||
|
git-rev-parse --verify HEAD) ||
|
||||||
|
die "Unable to find current revision in submodule path '$path'"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
subsha1=$(unset GIT_DIR && cd "$path" &&
|
|
||||||
git-rev-parse --verify HEAD) ||
|
|
||||||
die "Unable to find current revision of submodule '$path'"
|
|
||||||
|
|
||||||
if test "$subsha1" != "$sha1"
|
if test "$subsha1" != "$sha1"
|
||||||
then
|
then
|
||||||
(unset GIT_DIR && cd "$path" && git-fetch &&
|
(unset GIT_DIR && cd "$path" && git-fetch &&
|
||||||
git-checkout -q "$sha1") ||
|
git-checkout -q "$sha1") ||
|
||||||
die "Unable to checkout '$sha1' in submodule '$path'"
|
die "Unable to checkout '$sha1' in submodule path '$path'"
|
||||||
|
|
||||||
say "Submodule '$path': checked out '$sha1'"
|
say "Submodule path '$path': checked out '$sha1'"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# List all registered submodules, prefixed with:
|
# List all submodules, prefixed with:
|
||||||
# - submodule not initialized
|
# - submodule not initialized
|
||||||
# + different revision checked out
|
# + different revision checked out
|
||||||
#
|
#
|
||||||
@ -132,7 +148,9 @@ modules_list()
|
|||||||
git ls-files --stage -- "$@" | grep -e '^160000 ' |
|
git ls-files --stage -- "$@" | grep -e '^160000 ' |
|
||||||
while read mode sha1 stage path
|
while read mode sha1 stage path
|
||||||
do
|
do
|
||||||
if ! test -d "$path"/.git
|
name=$(module_name "$path") || exit
|
||||||
|
url=$(git-config submodule."$name".url)
|
||||||
|
if test -z "url" || ! test -d "$path"/.git
|
||||||
then
|
then
|
||||||
say "-$sha1 $path"
|
say "-$sha1 $path"
|
||||||
continue;
|
continue;
|
||||||
|
@ -18,7 +18,7 @@ subcommands of git-submodule.
|
|||||||
# -add directory lib to 'superproject', this creates a DIRLINK entry
|
# -add directory lib to 'superproject', this creates a DIRLINK entry
|
||||||
# -add a couple of regular files to enable testing of submodule filtering
|
# -add a couple of regular files to enable testing of submodule filtering
|
||||||
# -mv lib subrepo
|
# -mv lib subrepo
|
||||||
# -add an entry to .gitmodules for path 'lib'
|
# -add an entry to .gitmodules for submodule 'example'
|
||||||
#
|
#
|
||||||
test_expect_success 'Prepare submodule testing' '
|
test_expect_success 'Prepare submodule testing' '
|
||||||
mkdir lib &&
|
mkdir lib &&
|
||||||
@ -40,7 +40,19 @@ test_expect_success 'Prepare submodule testing' '
|
|||||||
git-add a lib z &&
|
git-add a lib z &&
|
||||||
git-commit -m "super commit 1" &&
|
git-commit -m "super commit 1" &&
|
||||||
mv lib .subrepo &&
|
mv lib .subrepo &&
|
||||||
GIT_CONFIG=.gitmodules git-config module.lib.url git://example.com/lib.git
|
GIT_CONFIG=.gitmodules git-config submodule.example.url git://example.com/lib.git
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'status should fail for unmapped paths' '
|
||||||
|
if git-submodule status
|
||||||
|
then
|
||||||
|
echo "[OOPS] submodule status succeeded"
|
||||||
|
false
|
||||||
|
elif ! GIT_CONFIG=.gitmodules git-config submodule.example.path lib
|
||||||
|
then
|
||||||
|
echo "[OOPS] git-config failed to update .gitmodules"
|
||||||
|
false
|
||||||
|
fi
|
||||||
'
|
'
|
||||||
|
|
||||||
test_expect_success 'status should only print one line' '
|
test_expect_success 'status should only print one line' '
|
||||||
@ -54,12 +66,12 @@ test_expect_success 'status should initially be "missing"' '
|
|||||||
|
|
||||||
test_expect_success 'init should register submodule url in .git/config' '
|
test_expect_success 'init should register submodule url in .git/config' '
|
||||||
git-submodule init &&
|
git-submodule init &&
|
||||||
url=$(git-config submodule.lib.url) &&
|
url=$(git-config submodule.example.url) &&
|
||||||
if test "$url" != "git://example.com/lib.git"
|
if test "$url" != "git://example.com/lib.git"
|
||||||
then
|
then
|
||||||
echo "[OOPS] init succeeded but submodule url is wrong"
|
echo "[OOPS] init succeeded but submodule url is wrong"
|
||||||
false
|
false
|
||||||
elif ! git-config submodule.lib.url ./.subrepo
|
elif ! git-config submodule.example.url ./.subrepo
|
||||||
then
|
then
|
||||||
echo "[OOPS] init succeeded but update of url failed"
|
echo "[OOPS] init succeeded but update of url failed"
|
||||||
false
|
false
|
||||||
@ -72,7 +84,7 @@ test_expect_success 'update should fail when path is used by a file' '
|
|||||||
then
|
then
|
||||||
echo "[OOPS] update should have failed"
|
echo "[OOPS] update should have failed"
|
||||||
false
|
false
|
||||||
elif test -f lib && test "$(cat lib)" != "hello"
|
elif test "$(cat lib)" != "hello"
|
||||||
then
|
then
|
||||||
echo "[OOPS] update failed but lib file was molested"
|
echo "[OOPS] update failed but lib file was molested"
|
||||||
false
|
false
|
||||||
|
Reference in New Issue
Block a user