chiark / gitweb /
8d09a020846e7105210c34c96e868a56e962b183
[topgit.git] / tg-push.sh
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # GPLv2
4
5 ## Parse options
6
7 recurse_deps=true
8 tgish_deps_only=false
9 dry_run=
10
11 while [ -n "$1" ]; do
12         arg="$1"; shift
13         case "$arg" in
14         --no-deps)
15                 recurse_deps=false;;
16         --dry-run)
17                 dry_run=--dry-run;;
18         --tgish-only)
19                 tgish_deps_only=true;;
20         -h|--help)
21                 echo "Usage: tg push [--dry-run] [--no-deps] [--tgish-only] [-r remote] branch*"
22                 exit 0;;
23         -r)
24                 remote="$1"
25                 shift
26                 ;;
27         *)
28                 branches="$branches $arg";;
29         esac
30 done
31
32 if [ -z "$remote" ]; then
33         remote="$base_remote"
34 fi
35
36 if [ -z "$remote" ]; then
37         die "no remote location given. Either use -r remote argument or set topgit.remote"
38 fi
39
40 if [ -z "$branches" ]; then
41         branches="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
42 fi
43
44 for name in $branches; do
45         ref_exists "$name" || die "detached HEAD? Can't push $name"
46 done
47
48 push_branch()
49 {
50         # if so desired omit non tgish deps
51         $tgish_deps_only && [ -z "$_dep_is_tgish" ] && return 0
52
53         echo "$_dep"
54         local base="top-bases/$_dep"
55         if ref_exists "$base"; then
56                 echo "top-bases/$_dep"
57         else
58                 echo "warning, no base found $base" 1>&2
59         fi
60 }
61
62 for name in $branches; do
63         list="$(
64                 # deps
65                 if $recurse_deps; then
66                         no_remotes=1 recurse_deps push_branch "$name"
67                 fi
68                 # current branch
69                 _dep="$name"
70                 _dep_is_tgish=1
71                 push_branch "$name"
72         )"
73         echo "pushing:"; echo $list
74         git push $dry_run "$remote" $list
75 done