tg-tag.sh: show correct name in HEAD ref log displays
[topgit/pro.git] / tg-push.sh
blob7646fbd05740095644214e845baacc0e6095e9d3
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # GPLv2
5 ## Parse options
7 recurse_deps=1
8 tgish_deps_only=
9 dry_run=
10 force=
11 push_all=
12 branches=
14 while [ -n "$1" ]; do
15 arg="$1"; shift
16 case "$arg" in
17 --no-deps)
18 recurse_deps=;;
19 --dry-run)
20 dry_run=--dry-run;;
21 -f|--force)
22 force=--force;;
23 --tgish-only)
24 tgish_deps_only=1;;
25 -a|--all)
26 push_all=1;;
27 -h|--help)
28 echo "Usage: ${tgname:-tg} [...] push [--dry-run] [--force] [--no-deps] [--tgish-only] [-r <remote>] [-a | --all | <branch>...]"
29 exit 0;;
30 -r)
31 remote="$1"
32 shift
35 v_strip_ref arg "$arg"
36 branches="${branches:+$branches }$arg";;
37 esac
38 done
40 if [ -z "$remote" ]; then
41 remote="$base_remote"
44 if [ -z "$remote" ]; then
45 die "no remote location given. Either use -r remote argument or set topgit.remote"
48 if [ -z "$branches" ]; then
49 if [ -n "$push_all" ]; then
50 branches="$(non_annihilated_branches | paste -s -d " " -)"
51 else
52 v_verify_topgit_branch branches HEAD
54 else
55 oldbranches="$branches"
56 branches=
57 while read name && [ -n "$name" ]; do
58 if [ "$name" = "HEAD" ]; then
59 sr="$(git symbolic-ref --quiet HEAD)" || :
60 [ -n "$sr" ] || die "cannot push a detached HEAD"
61 case "$sr" in refs/heads/*);;*)
62 die "HEAD is a symref to other than refs/heads/..."
63 esac
64 branches="${branches:+$branches }${sr#refs/heads/}"
65 else
66 ref_exists "refs/heads/$name" || die "no such ref: refs/heads/$name"
67 branches="${branches:+$branches }$name"
69 done <<-EOT
70 $(sed 'y/ /\n/' <<-LIST
71 $oldbranches
72 LIST
74 EOT
75 unset oldbranches
78 _listfile="$(get_temp tg-push-listfile)"
80 push_branch()
82 # FIXME should we abort on missing dependency?
83 [ -z "$_dep_missing" ] || return 0
85 # if so desired omit non tgish deps
86 [ -z "$tgish_deps_only" ] || [ -n "$_dep_is_tgish" ] || return 0
88 # filter out plain SHA1s. These don't need to be pushed explicitly as
89 # the patches that depend on the sha1 have it already in their ancestry.
90 ! is_sha1 "$_dep" || return 0
92 echol "$_dep" >> "$_listfile"
93 [ -z "$_dep_is_tgish" ] ||
94 echo "$topbases/$_dep" >> "$_listfile"
97 no_remotes=1
98 while read name && [ -n "$name" ]; do
99 # current branch
100 # re-use push_branch, which expects some pre-defined variables
101 _dep="$name"
102 _dep_is_tgish=1
103 _dep_missing=
104 ref_exists "refs/$topbases/$_dep" ||
105 _dep_is_tgish=
106 push_branch "$name"
108 # deps but only if branch is tgish
109 [ -z "$recurse_deps" ] || [ -z "$_dep_is_tgish" ] ||
110 recurse_deps push_branch "$name"
111 done <<EOT
112 $(sed 'y/ /\n/' <<LIST
113 $branches
114 LIST
118 # remove multiple occurrences of the same branch
119 sort -u "$_listfile" | sed 's,[^A-Za-z0-9/_.+-],\\&,g' | xargs git push $dry_run $force "$remote"