xref: /linux/scripts/package/gen-diff-patch (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
105e96e96SMasahiro Yamada#!/bin/sh
205e96e96SMasahiro Yamada# SPDX-License-Identifier: GPL-2.0-only
305e96e96SMasahiro Yamada
4*c0414419SMasahiro Yamadaset -eu
5*c0414419SMasahiro Yamada
6aa7d233fSMasahiro Yamadadiff_patch=$1
705e96e96SMasahiro Yamada
8aa7d233fSMasahiro Yamadamkdir -p "$(dirname "${diff_patch}")"
905e96e96SMasahiro Yamada
10aa7d233fSMasahiro Yamadagit -C "${srctree:-.}" diff HEAD > "${diff_patch}"
11aa7d233fSMasahiro Yamada
12aa7d233fSMasahiro Yamadaif [ ! -s "${diff_patch}" ] ||
13aa7d233fSMasahiro Yamada   [ -z "$(git -C "${srctree:-.}" ls-files --other --exclude-standard | head -n1)" ]; then
1405e96e96SMasahiro Yamada	exit
1505e96e96SMasahiro Yamadafi
1605e96e96SMasahiro Yamada
17aa7d233fSMasahiro Yamada# The source tarball, which is generated by 'git archive', contains everything
18aa7d233fSMasahiro Yamada# you committed in the repository. If you have local diff ('git diff HEAD'),
19aa7d233fSMasahiro Yamada# it will go into ${diff_patch}. If untracked files are remaining, the resulting
20aa7d233fSMasahiro Yamada# source package may not be correct.
21aa7d233fSMasahiro Yamada#
22aa7d233fSMasahiro Yamada# Examples:
23aa7d233fSMasahiro Yamada#  - You modified a source file to add #include "new-header.h"
24aa7d233fSMasahiro Yamada#    but forgot to add new-header.h
25aa7d233fSMasahiro Yamada#  - You modified a Makefile to add 'obj-$(CONFIG_FOO) += new-dirver.o'
26aa7d233fSMasahiro Yamada#    but you forgot to add new-driver.c
27aa7d233fSMasahiro Yamada#
28aa7d233fSMasahiro Yamada# You need to commit them, or at least stage them by 'git add'.
29aa7d233fSMasahiro Yamada#
30aa7d233fSMasahiro Yamada# This script does not take care of untracked files because doing so would
31aa7d233fSMasahiro Yamada# introduce additional complexity. Instead, print a warning message here if
32aa7d233fSMasahiro Yamada# untracked files are found.
33aa7d233fSMasahiro Yamada# If all untracked files are just garbage, you can ignore this warning.
34aa7d233fSMasahiro Yamadaecho >&2 "============================ WARNING ============================"
35aa7d233fSMasahiro Yamadaecho >&2 "Your working tree has diff from HEAD, and also untracked file(s)."
36aa7d233fSMasahiro Yamadaecho >&2 "Please make sure you did 'git add' for all new files you need in"
37aa7d233fSMasahiro Yamadaecho >&2 "the source package."
38aa7d233fSMasahiro Yamadaecho >&2 "================================================================="
39