-
Notifications
You must be signed in to change notification settings - Fork 0
/
weblate-stage-to-svn.sh
155 lines (124 loc) · 4.5 KB
/
weblate-stage-to-svn.sh
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/env bash
set -e
. "./svnupdate_common.sh"
language=zh_TW
kde_i18n_package=krita
git_fetch_remote_url="https://github.com/l10n-tw/krita-translation.git"
git_push_remote=origin
command_exists() {
command -v "$1" &> /dev/null
}
if ! command_exists git; then
echo "\`git\` not available, aborting."
exit 1
fi
if ! command_exists svn; then
echo "\`svn\` not available, aborting."
exit 1
fi
if [[ $(git rev-parse --abbrev-ref HEAD) != "master" ]]; then
echo "Not currently on master, aborting."
exit 1
fi
if [[ -n $(git status -s --untracked-files=no) ]]; then
echo "Working tree contains uncommitted changes, aborting."
exit 1
fi
# TODO: Use `wlc` to trigger push from Weblate.
# Fetch and checkout the latest weblate commits to a temporary worktree.
git_stage_dir="$tmpdir/__git_weblate_stage"
git fetch "$git_fetch_remote_url" weblate-stage
git worktree add --detach "$git_stage_dir" FETCH_HEAD
# Run `msgmerge` on the PO files.
for po_file in "$git_stage_dir/$language/"*.po; do
component="$(basename "$po_file" ".po")"
echo "Reformatting ${component}.po with \`msgmerge\`."
msgmerge --previous -o "$po_file" "$po_file" "$po_file"
done
if [[ -n $(git -C "$git_stage_dir" status -s) ]]; then
git -C "$git_stage_dir" add -A
git -C "$git_stage_dir" commit -m "Reformat with msgmerge"
else
echo "No changes after reformat."
fi
# Manual checking and editing.
echo "Staging git worktree at '$git_stage_dir'."
echo "You may now check the changes in the staging tree and add commits."
while : ; do
read -r -p "Command (bash/continue/quit) " input_command
case "$input_command" in
bash)
pushd "$git_stage_dir" > /dev/null
bash || true
popd > /dev/null
;;
continue)
if [[ -n $(git -C "$git_stage_dir" status -s) ]]; then
echo "Worktree contains uncommitted changes! Please commit or clean up before continuing."
else
break
fi
;;
quit)
echo "Quitting..."
exit
;;
*)
echo "Unknown option."
;;
esac
done
# Replace trap as we don't want the git tree to be removed.
trap 'echo "WARNING: tmpdir '"'$tmpdir'"' not deleted!"' EXIT
# SVN checkout and prepare for commit.
svn_stage_dir="$tmpdir/__svn_stage"
svn checkout "svn+ssh://[email protected]/home/kde/trunk/l10n-kf5/$language/messages/$kde_i18n_package" "$svn_stage_dir"
rm -v "$svn_stage_dir/"*.po
cp -v "$git_stage_dir/$language/"*.po "$svn_stage_dir/"
# Manual checking and editing.
echo "Staging svn checkout at '$svn_stage_dir'."
svn status "$svn_stage_dir"
echo "You may now check the changes in the checkout dir, and add any unversioned files with \`svn add <file>\`."
echo "NOTE: If you modify files inside the checkout dir, they will _not_ be synced back to git."
while : ; do
read -r -p "Command (bash/commit/quit) " input_command
case "$input_command" in
bash)
pushd "$svn_stage_dir" > /dev/null
bash || true
popd > /dev/null
;;
commit)
svn status "$svn_stage_dir"
read -r -p "Are you sure? (type 'yes' to confirm) " input_confirm
if [[ $input_confirm = "yes" ]]; then
break;
fi
;;
quit)
echo "Quitting..."
exit
;;
*)
echo "Unknown option."
;;
esac
done
# SVN commit.
svn commit -m "l10n(trunk/$kde_i18n_package/$language): update from Weblate" "$svn_stage_dir"
svn update "$svn_stage_dir"
svn_new_rev=$(svn info --show-item last-changed-revision "$svn_stage_dir")
echo "Committed updated PO catalogs to KDE SVN as r$svn_new_rev."
# Update and merge staging git branch.
echo -n "$svn_new_rev" > "$git_stage_dir/LAST_COMMIT_SVN_REVISION"
git -C "$git_stage_dir" add "$git_stage_dir/LAST_COMMIT_SVN_REVISION"
git -C "$git_stage_dir" commit -m "Mark committed to SVN r$svn_new_rev"
git_commit_to_merge=$(git -C "$git_stage_dir" rev-parse HEAD)
git merge --no-ff -m "Merge translation updates (r$svn_new_rev)" "$git_commit_to_merge"
# echo "Please push the master branch by running \`git push\` and delete the staging branch by \`git push <remote> :weblate-stage\`."
echo "Pushing to remote '$git_push_remote'"
git push "$git_push_remote" master:master :weblate-stage
# Re-register trap.
trap "remove_tmp_dir" EXIT
git worktree remove "$git_stage_dir"
# TODO: Use `wlc` to trigger update from Weblate.