Skip to content

Commit 73db459

Browse files
committed
verify-subtree.sh: ensure that there are no local commits
The goal is to enforce that changes get merged upstream first and only get into the local repo via a normal "git subtree merge".
1 parent b32dd01 commit 73db459

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

verify-subtree.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#! /bin/sh -e
2+
#
3+
# Copyright 2019 The Kubernetes Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# This script verifies that the content of a directory managed
18+
# by "git subtree" has not been modified locally. It does that
19+
# by looking for commits that modify the files with the
20+
# subtree prefix (aka directory) while ignoring merge
21+
# commits. Merge commits are where "git subtree" pulls the
22+
# upstream files into the directory.
23+
#
24+
# Theoretically a developer can subvert this check by modifying files
25+
# in a merge commit, but in practice that shouldn't happen.
26+
27+
DIR="$1"
28+
if [ ! "$DIR" ]; then
29+
echo "usage: $0 <directory>" >&2
30+
exit 1
31+
fi
32+
33+
REV=$(git log -n1 --format=format:%H --no-merges -- "$DIR")
34+
if [ "$REV" ]; then
35+
echo "Directory '$DIR' contains non-upstream changes:"
36+
echo
37+
git log --no-merges -- "$DIR"
38+
exit 1
39+
else
40+
echo "$DIR is a clean copy of upstream."
41+
fi

0 commit comments

Comments
 (0)