Allow the rebase command to be defined
[stgit/ydirson.git] / contrib / stg-gitk
blob6ddcfb1c321342eb6657eb2979dcd66f150abeab
1 #!/bin/sh
2 set -e
4 # stg-gitk - helper script to graphically display an StGIT stack
6 # Displays given branches and stacks, without getting disturbed by
7 # patch logs.
9 # LIMITATIONS:
10 # - no support for spaces in branch names
12 # Copyright (c) 2007 Yann Dirson <ydirson@altern.org>
13 # Subject to the GNU GPL, version 2.
15 usage()
17 echo "Usage: $(basename $0) [<branches>|--all]"
18 exit 1
21 allbranches=0
22 refsonly=0
23 while [ "$#" -gt 0 ]; do
24 case "$1" in
25 --refs) refsonly=1 ;;
26 --all) allbranches=1 ;;
27 --*) usage ;;
28 *) break ;;
29 esac
30 shift
31 done
33 if [ $allbranches = 1 ] && [ "$#" -gt 0 ]; then
34 usage
37 GIT_DIR=$(git-rev-parse --git-dir)
38 GIT_DIR_SPKIPLEN=$(printf "$GIT_DIR/X" | wc -c)
40 refdirs=''
41 if [ $allbranches = 1 ]; then
42 refdirs="$GIT_DIR/refs"
43 else
44 if [ "$#" = 0 ]; then
45 set -- "$(stg branch)"
48 for b in "$@"; do
49 if [ -e "$GIT_DIR/refs/patches/$b" ]; then
50 # StGIT branch: show all patches
51 refdirs="$refdirs $GIT_DIR/refs/heads/$b $GIT_DIR/refs/patches/$b"
52 elif [ -e "$GIT_DIR/refs/heads/$b" ]; then
53 # other GIT branch
54 refdirs="$refdirs $GIT_DIR/refs/heads/$b"
55 elif [ $(git-for-each-ref "refs/$b" | wc -l) != 0 ]; then
56 # other ref
57 refdirs="$refdirs $(git-for-each-ref --format="$GIT_DIR/%(refname)" "refs/$b")"
58 else
59 echo >&2 "ERROR: no such ref '$b'"
60 usage
62 done
65 printrefs()
67 find $refdirs -type f -not -name '*.log' | cut -c${GIT_DIR_SPKIPLEN}-
70 if [ $refsonly = 1 ]; then
71 printrefs
72 elif grep -q -- --argscmd $(which gitk); then
73 # This gitk supports --argscmd.
74 # Let's use a hack to pass --all, which was consumed during command-line parsing
75 if [ $allbranches = 1 ]; then
76 gitk --argscmd="$0 --refs --all"
77 else
78 gitk --argscmd="$0 --refs $*"
80 else
81 # This gitk does not support --argscmd, just compute refs onces
82 gitk $(printrefs)