-
Notifications
You must be signed in to change notification settings - Fork 34
Expand file tree
/
Copy pathpullcheck.sh
More file actions
59 lines (49 loc) · 2.13 KB
/
pullcheck.sh
File metadata and controls
59 lines (49 loc) · 2.13 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
# exit when any command fails
set -e
echo ""
echo "=========================================================================="
echo "=== check which files changes and the status code in remote master before pulling ============"
echo ""
echo "======== Status Codes =============="
echo "==== modify="M" # Modified ===="
echo "==== add="A" # Added ===="
echo "==== delete="D" # Deleted ===="
echo "==== rename="R" # Renamed ===="
echo "==== copy="C" # Copied ===="
echo "==== unmerged="U" # Unmerged (conflict) ===="
echo "==== typechange="T" # Type changed (file ↔ symlink) ===="
echo ""
echo " === Alert when an input/resources/*.json file was edited directly ======="
echo " =========== and the corresponding YAML source file not updated ========= "
echo "=========================================================================="
echo ""
git fetch
changed_files=$(git diff --name-status ...origin)
# changed_files=$(git diff-tree -r --name-only --no-commit-id ORIG_HEAD HEAD)
# Git status codes
statuses="M A D R C U T"
for file in $changed_files; do #The unquoted $changed_files triggers word splitting,
if [[ " $statuses " =~ " $file " ]]; then
status_code=$file
elif [[ $file == input/resources/*.json ]]; then
if ! echo "$changed_files" | grep -q "^${file%.json}.yaml"; then
echo ""
echo "⚠️ $file was edited directly! (status code = $status_code)"
echo " ℹ️ to reconcile with the YAML file pull and overwrite the YAML in resources-yaml"
echo ""
fi
else echo "ℹ️ changed file = $file (status code = $status_code)"
fi
done
echo "================================================================="
echo "=== hit 'y' to pull ===="
echo "=== else any other key to abort ==="
echo "================================================================="
read var1
echo "================================================================="
echo "==================== you typed '$var1' ============================"
echo "================================================================="
if [ $var1 == "y" ]; then
git pull
fi