README: add a "NO UNDO" section
[topgit/pro.git] / tg-push.sh
blob305ef7d81de8be16e8bf65ac3df85ee66e177de1
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
13 while [ -n "$1" ]; do
14 arg="$1"; shift
15 case "$arg" in
16 --no-deps)
17 recurse_deps=false;;
18 --dry-run)
19 dry_run=--dry-run;;
20 -f|--force)
21 force=--force;;
22 --tgish-only)
23 tgish_deps_only=true;;
24 -a|--all)
25 push_all=true;;
26 -h|--help)
27 echo "Usage: ${tgname:-tg} [...] push [--dry-run] [--force] [--no-deps] [--tgish-only] [-r <remote>] [-a | --all | <branch>...]"
28 exit 0;;
29 -r)
30 remote="$1"
31 shift
34 branches="$branches $arg";;
35 esac
36 done
38 if [ -z "$remote" ]; then
39 remote="$base_remote"
42 if [ -z "$remote" ]; then
43 die "no remote location given. Either use -r remote argument or set topgit.remote"
46 if [ -z "$branches" ]; then
47 if $push_all; then
48 branches="$(non_annihilated_branches)"
49 else
50 branches="$(verify_topgit_branch HEAD)"
52 else
53 oldbranches="$branches"
54 branches=
55 for name in $oldbranches; do
56 if [ "$name" = "HEAD" ]; then
57 sr="$(git symbolic-ref --quiet HEAD || :)"
58 [ -n "$sr" ] || die "cannot push a detached HEAD"
59 case "$sr" in refs/heads/*) :;; *)
60 die "HEAD is a symref to other than refs/heads/..."
61 esac
62 branches="${branches:+$branches }${sr#refs/heads/}"
63 else
64 ref_exists "refs/heads/$name" || die "no such ref: refs/heads/$name"
65 branches="${branches:+$branches }$name"
67 done
68 unset oldbranches
71 _listfile="$(get_temp tg-push-listfile)"
73 push_branch()
75 # FIXME should we abort on missing dependency?
76 [ -z "$_dep_missing" ] || return 0
78 # if so desired omit non tgish deps
79 $tgish_deps_only && [ -z "$_dep_is_tgish" ] && return 0
81 # filter out plain SHA1s. These don't need to be pushed explicitly as
82 # the patches that depend on the sha1 have it already in their ancestry.
83 is_sha1 "$_dep" && return 0
85 echo "$_dep" >> "$_listfile"
86 [ -z "$_dep_is_tgish" ] ||
87 echo "top-bases/$_dep" >> "$_listfile"
90 no_remotes=1
91 for name in $branches; do
92 # current branch
93 # re-use push_branch, which expects some pre-defined variables
94 _dep="$name"
95 _dep_is_tgish=1
96 _dep_missing=
97 ref_exists "refs/top-bases/$_dep" ||
98 _dep_is_tgish=
99 push_branch "$name"
101 # deps but only if branch is tgish
102 $recurse_deps && [ -n "$_dep_is_tgish" ] &&
103 recurse_deps push_branch "$name"
104 done
106 # remove multiple occurrences of the same branch
107 sort -u "$_listfile" | xargs git push $dry_run $force "$remote"