summaryrefslogtreecommitdiff
path: root/contrib/git-fetch-vendor.sh
blob: bbd52fb2055b54020300afe3df8d1839138f24ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh

usage ()
{
    echo "Usage: $0 [--enable-push] <vendor>"
    echo "The following vendors are already known:"
    git ls-remote ${upstream} "*/vendors/*" | sed -r "s:.*/vendors/([^/]+)/.*:\1:"|sort|uniq
    exit 1
}

# Should we insert a "push" refspec to enable pushing to the vendor branch?
enable_push=no

upstream=`git config --get "gcc-config.upstream"`
if [ x"$upstream" = x ]
then
    echo "Config gcc-config.upstream not set, run contrib/gcc-git-customization.sh"
    exit 1
fi

case $# in
    1)
	# vendor names never start with -, so catch this in case user wrote something like --help.
	case "$1" in
	    -*)
		usage
		;;
	    *)
		vendor=$1
		;;
	esac
	;;
    2)
	vendor=$2
	if [ "$1" = "--enable-push" ]
	then
	    enable_push=yes
	else
	    usage
	fi
	;;
    *)
	usage
	;;
esac


echo "setting up git to fetch vendor ${vendor} to remotes/vendors/${vendor}"
url=$(git config --get "remote.${upstream}.url")
pushurl=$(git config --get "remote.${upstream}.pushurl")
git config "remote.vendors/${vendor}.url" "${url}"
if [ "x$pushurl" != "x" ]
then
    git config "remote.vendors/${vendor}.pushurl" "${pushurl}"
fi
git config --replace-all "remote.vendors/${vendor}.fetch" "+refs/vendors/${vendor}/heads/*:refs/remotes/vendors/${vendor}/*" "refs/vendors/${vendor}/heads"
git config --replace-all "remote.vendors/${vendor}.fetch" "+refs/vendors/${vendor}/tags/*:refs/tags/vendors/${vendor}/*" "refs/vendors/${vendor}/tags"
if [ "$enable_push" = "yes" ]
then
    echo "Warning: take care when pushing that you only push the changes you intend."
    echo "E.g. use \"git push vendors/${vendor} HEAD\" to push the current branch"
    git config --replace-all "remote.vendors/${vendor}.push" "refs/heads/${vendor}/*:refs/vendors/${vendor}/heads/*"
else
    git config --unset-all "remote.vendors/${vendor}.push"
fi
git fetch vendors/${vendor}