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