summaryrefslogtreecommitdiffstats
path: root/scripts/package/gen-diff-patch
blob: f842ab50a780c657b7d2755c7c8a089393414474 (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
42
43
44
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only

diff_patch="${1}"
untracked_patch="${2}"
srctree=$(dirname $0)/../..

rm -f ${diff_patch} ${untracked_patch}

if ! ${srctree}/scripts/check-git; then
	exit
fi

mkdir -p "$(dirname ${diff_patch})" "$(dirname ${untracked_patch})"

git -C "${srctree}" diff HEAD > "${diff_patch}"

if [ ! -s "${diff_patch}" ]; then
	rm -f "${diff_patch}"
	exit
fi

git -C ${srctree} status --porcelain --untracked-files=all |
while read stat path
do
	if [ "${stat}" = '??' ]; then

		if ! diff -u /dev/null "${srctree}/${path}" > .tmp_diff &&
			! head -n1 .tmp_diff | grep -q "Binary files"; then
			{
				echo "--- /dev/null"
				echo "+++ linux/$path"
				cat .tmp_diff | tail -n +3
			} >> ${untracked_patch}
		fi
	fi
done

rm -f .tmp_diff

if [ ! -s "${diff_patch}" ]; then
	rm -f "${diff_patch}"
	exit
fi