2015-02-09 00:16:00 +00:00
|
|
|
# vim: set ts=3 sw=3 noet ft=sh : bash
|
|
|
|
|
2015-02-17 04:56:00 +00:00
|
|
|
# fetch_git: Clones or pulls updates from a git repository into a local directory
|
2015-02-09 00:16:00 +00:00
|
|
|
#
|
|
|
|
# $1 The URI to fetch
|
|
|
|
# $2 The local directory to fetch to (relative)
|
2015-03-01 10:25:06 +00:00
|
|
|
# $3 Recurse submodules (yes, no, clone)
|
2015-02-15 18:23:46 +00:00
|
|
|
#
|
|
|
|
# NOTE: git _now_ has a -C argument that would replace the cd commands in
|
|
|
|
# this rule, but this is a fairly recent addition to git, so we can't
|
|
|
|
# use it here. --iKarith
|
2015-02-09 00:16:00 +00:00
|
|
|
fetch_git() {
|
|
|
|
fetch_dir="$WORKDIR/$2"
|
|
|
|
if [ -d "$fetch_dir/.git" ]; then
|
2015-02-26 08:14:05 +00:00
|
|
|
echo_cmd "cd \"$fetch_dir\""
|
|
|
|
echo_cmd "git pull"
|
2015-03-01 10:25:06 +00:00
|
|
|
if [ "$3" = "yes" ]; then
|
2015-02-26 08:14:05 +00:00
|
|
|
echo_cmd "git submodule foreach git pull origin master"
|
2015-02-17 04:56:00 +00:00
|
|
|
fi
|
2015-02-09 00:16:00 +00:00
|
|
|
else
|
2015-02-18 02:34:31 +00:00
|
|
|
clone_type=
|
2015-02-26 08:14:05 +00:00
|
|
|
[ -n "$SHALLOW_CLONE" ] && depth="--depth 1 "
|
|
|
|
echo_cmd "git clone $depth\"$1\" \"$WORKDIR/$2\""
|
2015-03-01 10:25:06 +00:00
|
|
|
if [[ "$3" = "yes" || "$3" = "clone" ]]; then
|
2015-02-26 08:14:05 +00:00
|
|
|
echo_cmd "cd \"$fetch_dir\""
|
2019-06-19 02:40:33 +00:00
|
|
|
echo_cmd "git submodule update --init --recursive"
|
2015-02-15 18:23:46 +00:00
|
|
|
fi
|
2015-02-09 00:16:00 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-02-19 06:31:02 +00:00
|
|
|
# fetch_revision_git: Output the hash of the last commit in a git repository
|
2015-02-17 04:56:00 +00:00
|
|
|
#
|
|
|
|
# $1 Local directory to run git in
|
2015-02-19 06:31:02 +00:00
|
|
|
fetch_revision_git() {
|
|
|
|
[ -n "$1" ] && cd "$1"
|
2015-02-17 04:56:00 +00:00
|
|
|
git log -n 1 --pretty=format:%H
|
2015-02-14 12:53:05 +00:00
|
|
|
}
|
2015-02-19 06:31:02 +00:00
|
|
|
|
2015-04-06 05:53:51 +00:00
|
|
|
local_files_git() {
|
|
|
|
git diff-files --quiet --ignore-submodules
|
|
|
|
return $?
|
|
|
|
}
|
2015-02-19 06:31:02 +00:00
|
|
|
|
|
|
|
# fetch_revision: Output SCM-dependent revision string of a module
|
|
|
|
# (currently just calls fetch_revision_git)
|
|
|
|
#
|
|
|
|
# $1 The directory of the module
|
|
|
|
fetch_revision() {
|
|
|
|
fetch_revision_git $1
|
|
|
|
}
|
2015-04-06 05:53:51 +00:00
|
|
|
|
|
|
|
module_get_revision() {
|
|
|
|
if [ -d "$WORKDIR/$module_dir" ]; then
|
|
|
|
cd "$WORKDIR/$module_dir"
|
|
|
|
case "$module_fetch_rule" in
|
|
|
|
git)
|
|
|
|
if [ -n "$1" ]; then
|
|
|
|
git diff-files --quiet --ignore-submodules || echo -n "changed from "
|
|
|
|
fi
|
|
|
|
git log -n 1 --pretty=format:%H
|
|
|
|
;;
|
|
|
|
*) ;;
|
|
|
|
esac
|
|
|
|
fi
|
|
|
|
}
|