Add script for copying remote branch to local
[ag.git] / ag-remote-cp
1 #!/bin/bash
2
3 if [ ! -d .git ]; then
4         echo Does not appear to be a git tree
5         exit 1
6 fi
7
8 if [ "$1"x == x ]; then
9         echo Need remote branch
10         exit 1
11 fi
12
13 SRC=$1
14
15 if [ ! -f .git/refs/remotes/origin/$SRC ]; then
16         echo Remote branch $SRC does not exist
17         exit 2
18 fi
19
20 if [ "$2"x != x ]; then
21         DST=$2
22 else
23         DST=$SRC
24 fi
25
26 cp .git/refs/remotes/origin/$SRC .git/refs/heads/$DST