aboutsummaryrefslogtreecommitdiffstats
path: root/stable-commit-in-tree
blob: 30d0713b0f966db662b39b223d1dfffc72bbb280 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
#
# Check if a given commit is in the current branch, based on the subject
# rather than commit sha1.
#

if [ "$#" -ne 1 ]; then
	echo "Usage: stable commit-in-tree <commit sha1>"
	exit 1
fi

fullhash=$(git rev-parse $1)
# This might happen if someone pointed to a commit that doesn't exist in our
# tree.
if [ "$?" -gt "0" ]; then
	exit 0
fi

# Hope for the best, same commit is/isn't in the current branch
if [ "$(git merge-base $fullhash HEAD)" = "$fullhash" ]; then
	exit 1
fi

# Grab the subject, since commit sha1 is different between branches we
# have to look it up based on subject.
subj=$(git log -1 --pretty="%s" $1)
if [ $? -gt 0 ]; then
	exit 0
fi

STABLE_MAJ_VER=$(grep VERSION Makefile | head -n1 | awk {'print $3'})
STABLE_MIN_VER=$(grep PATCHLEVEL Makefile | head -n1 | awk {'print $3'})

# Try and find if there's a commit with given subject the hard way
for i in $(git log --pretty="%H" -F --grep "$subj" v$STABLE_MAJ_VER.$STABLE_MIN_VER..HEAD); do
	cursubj=$(git log -1 --format="%s" $i)
	if [ "$cursubj" = "$subj" ]; then
		exit 1
	fi
done
exit 0