Commit | Line | Data |
---|---|---|
cdd071ff YD |
1 | #!/bin/sh |
2 | set -e | |
3 | ||
4 | # stg-gitk - helper script to graphically display an StGIT stack | |
5 | ||
6 | # Displays given branches and stacks, without getting disturbed by | |
7 | # patch logs. | |
8 | ||
9 | # LIMITATIONS: | |
10 | # - asking gitk to "update" won't detect any new ref | |
11 | # - no support for spaces in branch names | |
12 | ||
13 | # Copyright (c) 2007 Yann Dirson <ydirson@altern.org> | |
14 | # Subject to the GNU GPL, version 2. | |
15 | ||
16 | usage() | |
17 | { | |
18 | echo "Usage: $(basename $0) [<branches>|--all]" | |
19 | exit 1 | |
20 | } | |
21 | ||
22 | allbranches=0 | |
23 | case "$1" in | |
24 | --all) allbranches=1; shift ;; | |
25 | --*) usage ;; | |
26 | *) break ;; | |
27 | esac | |
28 | ||
29 | if [ $allbranches = 1 ] && [ "$#" -gt 0 ]; then | |
30 | usage | |
31 | fi | |
32 | ||
33 | GIT_DIR=$(git-rev-parse --git-dir) | |
34 | GIT_DIR_SPKIPLEN=$(printf "$GIT_DIR/X" | wc -c) | |
35 | ||
36 | refdirs='' | |
37 | if [ $allbranches = 1 ]; then | |
38 | refdirs="$GIT_DIR/refs" | |
39 | else | |
40 | if [ "$#" = 0 ]; then | |
41 | set -- "$(stg branch)" | |
42 | fi | |
43 | ||
44 | for b in "$@"; do | |
45 | if [ -e "$GIT_DIR/refs/patches/$b" ]; then | |
46 | # StGIT branch: show all patches | |
47 | refdirs="$refdirs $GIT_DIR/refs/heads/$b $GIT_DIR/refs/patches/$b" | |
48 | elif [ -e "$GIT_DIR/refs/heads/$b" ]; then | |
49 | # other GIT branch | |
50 | refdirs="$refdirs $GIT_DIR/refs/heads/$b" | |
51 | elif [ $(git-for-each-ref "refs/$b" | wc -l) != 0 ]; then | |
52 | # other ref | |
53 | refdirs="$refdirs $(git-for-each-ref --format="$GIT_DIR/%(refname)" "refs/$b")" | |
54 | else | |
55 | echo >&2 "ERROR: no such ref '$b'" | |
56 | usage | |
57 | fi | |
58 | done | |
59 | fi | |
60 | ||
61 | gitk $(find $refdirs -type f -not -name '*.log' | cut -c${GIT_DIR_SPKIPLEN}- ) |