Debian Codegraph @

extensions/VisualEditor/bin/updateSubmodule.sh

raw symbols SCIP
1 #!/bin/bash -eu
2
3 # This script generates a commit that updates the lib/ve submodule
4 # ./bin/updateSubmodule.sh updates to master
5 # ./bin/updateSubmodule.sh hash updates to specified hash
6
7 # cd to the VisualEditor directory
8 cd $(cd $(dirname $0)/..; pwd)
9
10 # Check that both working directories are clean
11 if git status -uno --ignore-submodules | grep -i changes > /dev/null
12 then
13 echo >&2 "Working directory must be clean"
14 exit 1
15 fi
16 cd lib/ve
17 if git status -uno --ignore-submodules | grep -i changes > /dev/null
18 then
19 echo >&2 "lib/ve working directory must be clean"
20 exit 1
21 fi
22 cd ../..
23
24 # Use 'gerrit' if it exists, otherwise 'origin'
25 MW_REMOTE=$(git remote | grep -w gerrit || echo origin)
26
27 git fetch $MW_REMOTE
28 # Create sync-repos branch if needed and reset it to master
29 git checkout -B sync-repos $MW_REMOTE/master
30 git submodule update
31 cd lib/ve
32
33 CORE_REMOTE=$(git remote | grep -w gerrit || echo origin)
34
35 git fetch $CORE_REMOTE
36
37 # Figure out what to set the submodule to
38 if [ -n "${1:-}" ]
39 then
40 TARGET="$1"
41 TARGETDESC="$1"
42 else
43 TARGET=$CORE_REMOTE/master
44 TARGETDESC="master ($(git rev-parse --short $CORE_REMOTE/master))"
45 fi
46
47 # Generate commit summary
48 NEWCHANGES=$(git log ..$TARGET --oneline --no-merges --topo-order --reverse --color=never)
49 TASKS=$(git log ..$TARGET --no-merges --format=format:%B | grep "Bug: T" | sort | uniq)
50
51 # Ensure script continues if grep "fails" (returns nothing) with || : (due to -e flag in bash)
52
53 # Addede/removed i18n keys
54 ADDED_I18N_KEYS=$(git diff HEAD..$TARGET -- i18n/en.json | grep -E '^\+' | grep --color=never -vE '^\+\+\+' | sed -E 's/^\+\s*"([^"]+)":.*/\1/' | sed 's/^/- /' || :)
55 DELETED_I18N_KEYS=$(git diff HEAD..$TARGET -- i18n/en.json | grep -E '^\-' | grep --color=never -vE '^\-\-\-' | sed -E 's/^\-\s*"([^"]+)":.*/\1/' | sed 's/^/- /' || :)
56 # Find common keys (modified keys)
57 MODIFIED_KEYS=$(echo -e "$ADDED_I18N_KEYS\n$DELETED_I18N_KEYS" | sort | uniq -d)
58 # Remove modified keys from the added and removed lists
59 ADDED_I18N_KEYS=$(echo "$ADDED_I18N_KEYS" | grep -vxF -f <(echo "$MODIFIED_KEYS") | sed 's/^/- /')
60 DELETED_I18N_KEYS=$(echo "$DELETED_I18N_KEYS" | grep -vxF -f <(echo "$MODIFIED_KEYS") | sed 's/^/- /')
61
62 # Added/removed files
63 ADDED_FILES=$(git diff HEAD..$TARGET --name-only --diff-filter=A | grep --color=never -E "\.(js|css|less)$" | sed 's/^/- /' || :)
64 DELETED_FILES=$(git diff HEAD..$TARGET --name-only --diff-filter=D | grep --color=never -E "\.(js|css|less)$" | sed 's/^/- /' || :)
65
66 COMMITMSG="Update VE core submodule to $TARGETDESC
67
68 New changes:
69 $NEWCHANGES"
70
71 if [ -n "$ADDED_I18N_KEYS" ]; then
72 COMMITMSG+="
73
74 Added i18n keys:
75 $ADDED_I18N_KEYS"
76 fi
77
78 if [ -n "$DELETED_I18N_KEYS" ]; then
79 COMMITMSG+="
80
81 Deleted i18n keys:
82 $DELETED_I18N_KEYS"
83 fi
84
85 if [ -n "$ADDED_FILES" ]; then
86 COMMITMSG+="
87
88 Added files:
89 $ADDED_FILES"
90 fi
91
92 if [ -n "$DELETED_FILES" ]; then
93 COMMITMSG+="
94
95 Deleted files:
96 $DELETED_FILES"
97 fi
98
99 COMMITMSG+="
100
101 $TASKS"
102
103 # Check out master of VE core
104 git checkout $TARGET
105
106 # Commit
107 cd ../..
108 git commit lib/ve -m "$COMMITMSG" > /dev/null
109 if [ "$?" == "1" ]
110 then
111 echo >&2 "No changes"
112 else
113 cat >&2 <<END
114
115
116 Created commit:
117
118 $COMMITMSG
119 END
120 fi