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