Skip to content

Commit 774be53

Browse files
author
Alexander Rogalskiy
committed
Updates on files
1 parent e159e7b commit 774be53

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@
252252
"script:name": "test -f ./scripts/package_app_name.js && node --experimental-modules --no-warnings --no-deprecation ./scripts/package_app_name.js || echo '✔ Node package name script is missing'",
253253
"script:notes": "test -f ./scripts/git_release_notes.sh && . ./scripts/git_release_notes.sh > NOTES.md || echo '✔ Git release notes script is missing'",
254254
"script:size": "test -f ./scripts/git_size.sh && . ./scripts/git_size.sh || echo '✔ Git size script is missing'",
255+
"script:conflict": "test -f ./scripts/pre-commit.sh && /bin/bash ./scripts/pre-commit.sh || echo '✔ Git pre-commit script is missing'",
255256
"setheapsize": "export NODE_OPTIONS=--max_old_space_size=2048",
256257
"solidarity": "solidarity",
257258
"solidarity:update": "solidarity snapshot cli node",

scripts/check_merge_conflict.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env python
2+
# from https://github.com/pre-commit/pre-commit-hooks
3+
# and made more blunt
4+
from __future__ import print_function
5+
6+
import argparse
7+
import os.path
8+
import sys
9+
10+
CONFLICT_PATTERNS = [
11+
'<<<<<<< ',
12+
'======= ',
13+
'=======\n',
14+
'>>>>>>> '
15+
]
16+
WARNING_MSG = 'Merge conflict string "{0}" found in {1}:{2}'
17+
18+
19+
def detect_merge_conflict(argv=None):
20+
parser = argparse.ArgumentParser()
21+
parser.add_argument('filenames', nargs='*')
22+
args = parser.parse_args(argv)
23+
24+
retcode = 0
25+
for filename in args.filenames:
26+
with open(filename) as inputfile:
27+
for i, line in enumerate(inputfile):
28+
for pattern in CONFLICT_PATTERNS:
29+
if line.startswith(pattern):
30+
print(WARNING_MSG.format(pattern, filename, i + 1))
31+
retcode = 1
32+
33+
return retcode
34+
35+
if __name__ == '__main__':
36+
sys.exit(detect_merge_conflict())

scripts/hook.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515

1616
# Usage example: /bin/sh ./scripts/hook.sh
1717

18+
set -o errexit
19+
set -o nounset
20+
set -o pipefail
21+
1822
cat << EOF
1923
Build specification:
2024
DefaultRepo: $SKAFFOLD_DEFAULT_REPO

scripts/pre-commit.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
# Copyright (C) 2022 SensibleMetrics, Inc. (http://sensiblemetrics.io/)
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
# Usage example: /bin/bash ./scripts/pre-commit.sh
17+
18+
set -o errexit
19+
set -o nounset
20+
set -o pipefail
21+
22+
# probably a dumb way to detect changed files which are not deleted
23+
scripts/check_merge_conflict.py $(comm -12 <(git diff --name-only --cached) <(git ls-files))

0 commit comments

Comments
 (0)