tg.sh: quote problem alternate directory paths
[topgit/pro.git] / tg-push.sh
blob72518ad3b141ea228f7a92060a685e67203a5230
1 #!/bin/sh
2 # TopGit - A different patch queue manager
3 # GPLv2
5 ## Parse options
7 recurse_deps=true
8 tgish_deps_only=false
9 dry_run=
10 force=
11 push_all=false
12 branches=
14 while [ -n "$1" ]; do
15 arg="$1"; shift
16 case "$arg" in
17 --no-deps)
18 recurse_deps=false;;
19 --dry-run)
20 dry_run=--dry-run;;
21 -f|--force)
22 force=--force;;
23 --tgish-only)
24 tgish_deps_only=true;;
25 -a|--all)
26 push_all=true;;
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 branches="${branches:+$branches }$(strip_ref "$arg")";;
36 esac
37 done
39 if [ -z "$remote" ]; then
40 remote="$base_remote"
43 if [ -z "$remote" ]; then
44 die "no remote location given. Either use -r remote argument or set topgit.remote"
47 if [ -z "$branches" ]; then
48 if $push_all; then
49 branches="$(non_annihilated_branches | paste -s -d " " -)"
50 else
51 branches="$(verify_topgit_branch HEAD)"
53 else
54 oldbranches="$branches"
55 branches=
56 while read name && [ -n "$name" ]; do
57 if [ "$name" = "HEAD" ]; then
58 sr="$(git symbolic-ref --quiet HEAD)" || :
59 [ -n "$sr" ] || die "cannot push a detached HEAD"
60 case "$sr" in refs/heads/*);;*)
61 die "HEAD is a symref to other than refs/heads/..."
62 esac
63 branches="${branches:+$branches }${sr#refs/heads/}"
64 else
65 ref_exists "refs/heads/$name" || die "no such ref: refs/heads/$name"
66 branches="${branches:+$branches }$name"
68 done <<-EOT
69 $(sed 'y/ /\n/' <<-LIST
70 $oldbranches
71 LIST
73 EOT
74 unset oldbranches
77 _listfile="$(get_temp tg-push-listfile)"
79 push_branch()
81 # FIXME should we abort on missing dependency?
82 [ -z "$_dep_missing" ] || return 0
84 # if so desired omit non tgish deps
85 $tgish_deps_only && [ -z "$_dep_is_tgish" ] && return 0
87 # filter out plain SHA1s. These don't need to be pushed explicitly as
88 # the patches that depend on the sha1 have it already in their ancestry.
89 is_sha1 "$_dep" && return 0
91 echol "$_dep" >> "$_listfile"
92 [ -z "$_dep_is_tgish" ] ||
93 echo "$topbases/$_dep" >> "$_listfile"
96 no_remotes=1
97 while read name && [ -n "$name" ]; do
98 # current branch
99 # re-use push_branch, which expects some pre-defined variables
100 _dep="$name"
101 _dep_is_tgish=1
102 _dep_missing=
103 ref_exists "refs/$topbases/$_dep" ||
104 _dep_is_tgish=
105 push_branch "$name"
107 # deps but only if branch is tgish
108 $recurse_deps && [ -n "$_dep_is_tgish" ] &&
109 recurse_deps push_branch "$name"
110 done <<EOT
111 $(sed 'y/ /\n/' <<LIST
112 $branches
113 LIST
117 # remove multiple occurrences of the same branch
118 sort -u "$_listfile" | xargs git push $dry_run $force "$remote"