blob: 373cc00beccb5a36a7ed8b92c50eed28f156a020 [file] [log] [blame]
Brian Silvermanccfeb222020-10-28 21:13:45 -07001#!/bin/bash
2
3# This script will run `git diff` from the latest upstream to HEAD on the
4# git-subtreed directory given as its first argument, passing all of the
5# other arguments on.
6#
7# This will not work on non-squashed git-subtree directories.
8
9# Copied from
10# https://github.com/git/git/blob/master/contrib/subtree/git-subtree.sh.
11find_latest_squash()
12{
13 dir="$1"
14 sq=
15 main=
16 sub=
17 git log --grep="^git-subtree-dir: $dir/*\$" \
18 --pretty=format:'START %H%n%s%n%n%b%nEND%n' HEAD |
19 while read a b junk; do
20 case "$a" in
21 START) sq="$b" ;;
22 git-subtree-mainline:) main="$b" ;;
23 git-subtree-split:) sub="$b" ;;
24 END)
25 if [ -n "$sub" ]; then
26 if [ -n "$main" ]; then
27 # a rejoin commit?
28 # Pretend its sub was a squash.
29 sq="$sub"
30 fi
31 echo "$sq" "$sub"
32 break
33 fi
34 sq=
35 main=
36 sub=
37 ;;
38 esac
39 done
40}
41
42DIR="${1%/}"
43shift
44DIFF_ARGS="$@"
45
46SPLIT="$(find_latest_squash "${DIR}")"
47if [ -z "${SPLIT}" ]; then
48 echo "${DIR} does not appear to be git-subtreed in."
49 exit 1
50fi
51
52set ${SPLIT}
53SQUASHED_UPSTREAM=$1
54
55git diff ${DIFF_ARGS} ${SQUASHED_UPSTREAM}..HEAD:${DIR}