2548b35339ab5374936eca6292677b365d4550e0
[xonotic/xonotic.git] / all
1 #!/bin/sh
2
3 set -e
4
5 repos="
6         data/xonotic-data.pk3dir
7         data/xonotic-maps.pk3dir
8         data/xonotic-music.pk3dir
9         darkplaces
10 "
11
12 if [ "$#" = 0 ]; then
13         set -- help
14 fi
15 cmd=$1
16 shift
17
18 d0=`pwd`
19 case "$cmd" in
20         update|pull)
21                 base=`git config remote.origin.url`
22                 base=${base%/xonotic.git}
23                 for d in $repos; do
24                         if [ -d "$d0/$d" ]; then
25                                 cd "$d0/$d"
26                                 git config remote.origin.url "$base/${d##*/}.git"
27                                 git pull
28                                 cd "$d0"
29                         else
30                                 git clone "$base/${d##*/}.git" "$d0/$d"
31                         fi
32                 done
33                 ;;
34         checkout)
35                 remote=$1
36                 branch=$2
37                 if [ -z "$branch" ]; then
38                         branch=$remote
39                         remote=origin
40                 fi
41                 exists=false
42                 for d in $repos; do
43                         cd "$d0/$d"
44                         if git rev-parse "refs/heads/$branch" >/dev/null 2>&1; then
45                                 exists=true
46                                 git checkout "$branch"
47                         elif git rev-parse "refs/remotes/$remote/$branch" >/dev/null 2>&1; then
48                                 exists=true
49                                 git checkout --track -b "$branch" "$remote/$branch"
50                         else
51                                 git checkout master
52                         fi
53                         cd "$d0"
54                 done
55                 "$0" branch
56                 ;;
57         branch)
58                 if [ $# = 0 ]; then
59                         for d in $repos; do
60                                 cd "$d0/$d"
61                                 r=`git symbolic-ref HEAD`
62                                 r=${r#refs/heads/}
63                                 echo "$d is at $r"
64                                 cd "$d0"
65                         done
66                 else
67                         for d in $repos; do
68                                 cd "$d0/$d"
69                                 a=
70                                 while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
71                                         echo "Branch in $d?"
72                                         read -r a
73                                 done
74                                 if [ x"$a" = "y" ]; then
75                                         git branch "$1"
76                                 fi
77                                 cd "$d0"
78                         done
79                         "$0" branch
80                 fi
81                 ;;
82         branches)
83                 for d in $repos; do
84                         cd "$d0/$d"
85                         echo "In $d:"
86                         git branch -a | sed 's/^/  /'
87                         cd "$d0"
88                 done
89                 ;;
90         push)
91                 for d in $repos; do
92                         cd "$d0/$d"
93                         r=`git symbolic-ref HEAD`
94                         r=${r#refs/heads/}
95                         a=
96                         while [ x"$a" != x"y" -a x"$a" != x"n" ]; do
97                                 git log "origin/$r".."$r"
98                                 echo "Push $r in $d?"
99                                 read -r a
100                         done
101                         if [ x"$a" = "y" ]; then
102                                 git push -u origin HEAD
103                         fi
104                         cd "$d0"
105                 done
106                 ;;
107         *)
108                 echo "Usage:"
109                 echo "  $0 pull"
110                 echo "  $0 push"
111                 echo "  $0 branches"
112                 echo "  $0 branch"
113                 echo "  $0 checkout"
114                 ;;
115 esac