[pacman-dev] [PATCH 4/4] makepkg: allow using GIT source URLs

Allan McRae allan at archlinux.org
Sun Jun 3 11:40:49 EDT 2012


Allow specifing GIT sources using the following syntax

source=('<folder>::<repo>#<fragment>')

This will download the git repo <repo> into <folder> (into $SRCDIR
if set, otherwise $startdir). <repo> must start with "git", but
non-git protocols are handled using (e.g.) "git+http://...".

The <fragment> can be used to specify a branch, tag, or commit to
build from. e.g. branch=maint.

When --holdver is not used and the fragment does not specify a
commit or tag to build from, makepkg will update the pkgver to
$(git rev-list HEAD | wc -l)_$(git rev-parse --short HEAD)

Note: this currently must be used with --skipinteg...

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 scripts/makepkg.sh.in |   95 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 95 insertions(+)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 227af5e..59fa9e4 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -295,6 +295,98 @@ download_file() {
 	fi
 }
 
+download_git() {
+	local netfile=$1
+
+	local fragment=${netfile##*#}
+	if [[ $fragment = "$netfile" ]]; then
+		unset fragment
+	fi
+
+	local folder=${netfile%%::*}
+	local repo=${netfile##*/}
+	repo=${repo%%.git*}
+
+	if [[ $folder = "$netfile" ]]; then
+		folder="${repo}"
+	fi
+
+	if [[ ! -d "$startdir"/$folder && -d "$SRCDEST"/$folder ]]; then
+		folder="$SRCDEST"/$folder
+	else
+		folder="$startdir"/$folder
+	fi
+
+	local url=${netfile##*git+}
+	url=${url%%#*}
+
+	local ret=0
+	if [[ ! -d $folder ]]; then
+		msg2 "$(gettext "Cloning %s %s repo...")" "${repo}" "git"
+		git clone --mirror "$url" "$folder" || ret=$?
+	else
+		msg2 "$(gettext "Updating %s %s repo...")" "${repo}" "git"
+		cd_safe "$folder"
+		git fetch --all -p || ret=$?
+	fi
+
+	if (( ret )); then
+		error "$(gettext "Failure while downloading %s %s repo")" "${repo}" "git"
+		plain "$(gettext "Aborting...")"
+		exit 1
+	fi
+
+	msg2 "$(gettext "Creating working copy of %s %s repo...")" "${repo}" "git"
+	pushd "$srcdir" &>/dev/null
+	rm -rf ${folder##*/}
+	git clone $folder
+
+	cd_safe ${folder##*/}
+
+	if (( HOLDVER )); then
+		ref=${pkgver##*_}
+	elif [[ -n $fragment ]]; then
+		case $fragment in
+			commit=*|tag*)
+				ref=${fragment##*=}
+				# assume pkgver is set when building from given commit or tag
+				HOLDVER=1
+				;;
+			branch=*)
+				ref=origin/${fragment##*=}
+				;;
+			*)
+				error "$(gettext "Unrecognized reference: %s")" "${fragment}"
+				plain "$(gettext "Aborting...")"
+				exit 1
+		esac
+	fi
+
+	if [[ -n $ref ]]; then
+		git checkout -b makepkg $ref || ret=$?
+		if (( ret )); then
+			error "$(gettext "Failure while checking out reference %s")" "${fragment}"
+			plain "$(gettext "Aborting...")"
+			exit 1
+		fi
+	fi
+
+	if (( !HOLDVER )); then
+		newpkgver=$(git rev-list HEAD | wc -l)_$(git rev-parse --short HEAD)
+		if [[ $newpkgver != "$pkgver" ]]; then
+			if [[ -f $BUILDFILE && -w $BUILDFILE ]]; then
+				sed -i "s/^pkgver=[^ ]*/pkgver=$newpkgver/" "$BUILDFILE"
+				sed -i "s/^pkgrel=[^ ]*/pkgrel=1/" "$BUILDFILE"
+				source "$BUILDFILE"
+			else
+				warning "$(gettext "%s is not writeable -- pkgver will not be updated")" "$BUILDFILE"
+			fi
+		fi
+	fi
+
+	popd &>/dev/null
+}
+
 download_sources() {
 	msg "$(gettext "Retrieving Sources...")"
 
@@ -350,6 +442,9 @@ download_sources() {
 					ln -s "$SRCDEST/$filename" "$srcdir/"
 				fi
 				;;
+			git*)
+				download_git "$netfile"
+				;;
 		esac
 	done
 
-- 
1.7.10.3



More information about the pacman-dev mailing list