1#! /bin/sh -e
2
3# Create a new upstream user branch.
4
5# Usage:
6#  contrib/git-add-user-branch.sh [<personal-prefix>/]<branch-name> <base>
7
8usage ()
9{
10    echo "Usage:"
11    echo "  $0 [<personal-prefix>/]<branch-name> <start-point>"
12    echo
13    echo "personal space must already have been set up using"
14    echo "contrib/gcc-git-customization.sh"
15    exit 1
16}
17
18if [ $# != 2 ]
19then
20    usage
21fi
22
23userpfx=$(git config --get "gcc-config.userpfx")
24user=$(git config --get "gcc-config.user")
25
26if [ -z "$userpfx" -o -z "$user" ]
27then
28    usage
29fi
30
31branch=$(echo "$1" | sed -r "s:(${userpfx}/)?(.*)$:\2:")
32start=$2
33
34# Sanity check the new branch argument.  If there is no '/', then the
35# vendor will be the same as the entire first argument.
36if [ -z "$branch" ]
37then
38    usage
39fi
40
41git push users/${userpfx} ${start}:refs/users/${user}/heads/${branch}
42git fetch -q users/${userpfx}
43git branch ${userpfx}/${branch} remotes/users/${userpfx}/${branch}
44echo "You are now ready to check out ${userpfx}/${branch}"
45echo "To push the branch upstream use:"
46echo "  git push users/${userpfx} ${userpfx}/${branch}"
47