chiark / gitweb /
Add a "make tags" target
[stgit] / contrib / stg-gitk
CommitLineData
cdd071ff
YD
1#!/bin/sh
2set -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
16usage()
17{
18 echo "Usage: $(basename $0) [<branches>|--all]"
19 exit 1
20}
21
22allbranches=0
23case "$1" in
24--all) allbranches=1; shift ;;
25--*) usage ;;
26*) break ;;
27esac
28
29if [ $allbranches = 1 ] && [ "$#" -gt 0 ]; then
30 usage
31fi
32
33GIT_DIR=$(git-rev-parse --git-dir)
34GIT_DIR_SPKIPLEN=$(printf "$GIT_DIR/X" | wc -c)
35
36refdirs=''
37if [ $allbranches = 1 ]; then
38 refdirs="$GIT_DIR/refs"
39else
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
59fi
60
61gitk $(find $refdirs -type f -not -name '*.log' | cut -c${GIT_DIR_SPKIPLEN}- )