File: mass-change

package info (click to toggle)
pkg-haskell-tools 0.12.5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 160 kB
  • sloc: haskell: 691; sh: 591; perl: 308; makefile: 10
file content (107 lines) | stat: -rwxr-xr-x 1,964 bytes parent folder | download | duplicates (4)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#!/bin/bash

if [ "$1" = "--help" -o -z "$1" ]
then
	cat <<__END__
mass-change - Apply a change to many packages

__END__
	$0 --manpage
	exit 0
fi

if [ "$1" = "--manpage" ]
then
cat <<__END__
Usage: dht mass-change [-n] [MESSAGE] [ACTION] DIRECTORY ...

This script runs ACTION in each of the given directories. If the ACTION
effected a change, it will add MESSAGE to the changelog.

It assumes that all directories are in the same git repository as this script.
It ensures that the repository is clean to begin with, and will commit all
changes at once at the end, if there was a change.
__END__
	exit 0;
fi


if [ "$1" = "-n" ]
then
  dry_run=1
  shift
fi

message=$1
shift
action=$1
shift

if ! git diff-files --quiet -- "$@"
then
	echo "The git repository is not clean. Please fix that first!"
	exit 1
fi

if ! git diff-index --cached --quiet HEAD -- "$@"
then
	echo "WARNING: The git index is not clean, and will be amended!"
fi

if test -n "$(git ls-files --exclude-standard --others -- "$@")"
then
	echo "The git repository has untracked files. Please fix that first!"
	exit 1
fi

changes=0
while [ -n "$1" ]
do
	dir=$1
	shift

	if ! pushd "$dir" >/dev/null
	then
		echo "Failed to switch to \"$dir\""
		continue
	fi

	if [ ! -e debian/changelog ]
	then
		echo "No changelog file found, skipping $dir"
		popd >/dev/null
		continue
	fi

	echo "Processing $dir"

	eval "$action"

	# some hack to make git update its cache of the working directory?
	#git update-index --refresh -q
	git diff . > /dev/null
	if git diff-files --quiet .
	then
		echo "Action did not change $dir, not modifying changelog"
		popd >/dev/null
		continue
	fi
	if [ -z "$dry_run" ]
	then
		echo "Staging these changes:"
		git diff|colordiff
		dht dch "$message"
		git add .
		changes=$((changes+1))
	else
		echo "Would stage these changes:"
		git diff|colordiff
		git checkout -- .
	fi
	popd >/dev/null
done

if [ $changes -gt 0 ]
then
	git commit -m "$message ($changes packages)"
fi