tg-prev/tg-next: commands to explore dependencies
[topgit.git] / tg-push.sh
bloba928fba8e9e93a522f966004bea28c0c6fc1fe07
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=
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
28 branches="$branches $arg";;
29 esac
30 done
32 if [ -z "$remote" ]; then
33 remote="$base_remote"
36 if [ -z "$remote" ]; then
37 die "no remote location given. Either use -r remote argument or set topgit.remote"
40 if [ -z "$branches" ]; then
41 branches="$(git symbolic-ref HEAD | sed 's#^refs/heads/##')"
44 for name in $branches; do
45 ref_exists "$name" || die "detached HEAD? Can't push $name"
46 done
48 _listfile="$(get_temp tg-push-listfile)"
50 push_branch()
52 # if so desired omit non tgish deps
53 $tgish_deps_only && [ -z "$_dep_is_tgish" ] && return 0
55 # filter out plain SHA1s. These don't need to be pushed explicitly as
56 # the patches that depend on the sha1 have it already in their ancestry.
57 is_sha1 "$_dep" && return 0
59 echo "$_dep" >> "$_listfile"
60 [ -z "$_dep_is_tgish" ] ||
61 echo "top-bases/$_dep" >> "$_listfile"
64 for name in $branches; do
65 # current branch
66 # re-use push_branch, which expects some pre-defined variables
67 _dep="$name"
68 _dep_is_tgish=1
69 ref_exists "top-bases/$_dep" ||
70 _dep_is_tgish=
71 push_branch "$name"
73 # deps but only if branch is tgish
74 $recurse_deps && [ -n "$_dep_is_tgish" ] &&
75 no_remotes=1 recurse_deps push_branch "$name"
77 # remove multiple occurrences of the same branch
78 sort -u "$_listfile" | xargs git push $dry_run "$remote"
79 done