File: guilt-commit

package info (click to toggle)
guilt 0.36-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 1,312 kB
  • sloc: sh: 3,063; makefile: 95; perl: 42
file content (57 lines) | stat: -rwxr-xr-x 1,427 bytes parent folder | download | duplicates (3)
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/sh
#
# Copyright (c) Josef "Jeff" Sipek, 2008-2013
#

USAGE="-n <num> | -a | --all"
if [ -z "$GUILT_VERSION" ]; then
	echo "Invoking `basename "$0"` directly is no longer supported." >&2
	exit 1
fi

_main() {

case "$1" in
	-a|--all)
		[ $# -gt 1 ] && usage
		pat_commit="1,\$p"
		pat_keep=""
		;;
	-n)
		[ $# -gt 2 ] && usage
		[ "$2" -lt 0 ] && die "Must specify a number of patches to commit"
		[ "$2" -eq 0 ] && exit 0

		pat_commit="1,$2p"
		pat_keep="`expr "$2" + 1`,\$p"
		;;
	*)
		usage
		;;
esac

# if nothing's applied, exit
[ `wc -l < "$applied"` -eq 0 ] && exit 0

# remove patch refs for what's being committed, and update series
sed -n -e "${pat_commit}" "$applied" | while read pname; do
	# update the base branch to the last committed patch
	$old_style_prefix || git update-ref refs/heads/$branch \
				refs/patches/$branch/$pname

	series_remove_patch "$pname"
	echo "$pname" | remove_patch_refs
done

# update $applied to include only the patches we're keeping
sed -n -e "${pat_keep}" "$applied" > "$applied.tmp"
mv "$applied.tmp" "$applied"

# if we removed the last patch, switch back to the base branch
if [ `wc -l < "$applied"` -eq 0 ] && [ "`git symbolic-ref HEAD`" = "refs/heads/$GUILT_PREFIX$branch" ] && ! $old_style_prefix
then
	git update-ref refs/heads/$branch refs/heads/$GUILT_PREFIX$branch
	git symbolic-ref HEAD refs/heads/$branch
	git update-ref -d refs/heads/$GUILT_PREFIX$branch
fi
}