Last active
August 22, 2024 19:09
-
-
Save ngquerol/8a4df4382654ccafba6e162c4c98701d to your computer and use it in GitHub Desktop.
Script to automate maintainance of the ns_system_appearance emacs patch set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
set -eux | |
origin_remote="origin" | |
upstream_remote="upstream" | |
patch_branch_prefix="ns-system-appearance-change" | |
emacs_branches="master emacs-30 emacs-29 emacs-28 emacs-27" | |
gist_ids="9618d4aba60a6e691c3a4bdbefbdb9e9 ba7d50d281e71ba9a585be7c89590b1a 6dbb6f21bbb5756b59c1500f1f97094c 33e099eceae527b368bdf196c95d1ba3 8f430884386d1fcc4e216e484cc44c59" | |
for command in git gh; do | |
if ! command -v "${command}" 1>/dev/null; then | |
echo "'${command}' is not in PATH; exiting." >&2 | |
exit 1 | |
fi | |
done | |
old_pwd="${PWD}" | |
trap 'cd '"${old_pwd}"'; trap - EXIT; exit' EXIT TERM HUP INT | |
cd ./emacs | |
for remote in ${origin_remote} ${upstream_remote}; do | |
if ! git ls-remote "${remote}" --exit-code; then | |
echo "'${remote}' remote does not exist or is unreachable" >&2 | |
exit 1 | |
fi | |
done | |
if [ -n "$(git status --porcelain)" ]; then | |
echo "working directory is not clean" >&2 | |
exit 1 | |
fi | |
i="1" | |
for branch in ${emacs_branches}; do | |
git fetch --quiet "${upstream_remote}" "${branch}" | |
behind=$(git rev-list --count "${branch}..${upstream_remote}/${branch}") | |
if [ "${behind}" -eq 0 ]; then | |
continue | |
fi | |
git checkout --quiet "${branch}" | |
git merge --quiet --ff-only "${upstream_remote}/${branch}" | |
if [ "${branch}" = "master" ]; then | |
patch_branch="${patch_branch_prefix}" | |
gist_name="ns_system_appearance_change.patch" | |
else | |
patch_branch="${patch_branch_prefix}-${branch}" | |
gist_name="ns_system_appearance_change_${branch}.patch" | |
fi | |
git rebase --quiet "${branch}" "${patch_branch}" | |
git push --quiet --no-verify --all --force-with-lease "${origin_remote}" | |
gist_id=$(echo "${gist_ids}" | cut -d ' ' -f ${i}) | |
gist_description="Patch to make emacs (${branch} branch) aware of the macOS 10.14+ system appearance changes." | |
gh gist edit "${gist_id}" -f "${gist_name}" -d "${gist_description}" \ | |
/dev/fd/3 3<<-EOF | |
$(git format-patch --stdout HEAD~1) | |
EOF | |
i=$((i + 1)) | |
done | |
git checkout --quiet master |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Several assumptions are made here;
emacs
subdirectory at the script's own pathupstream
andorigin
remotesorigin
is the repo where I maintain the branches, one per patch & major emacs version with a particular naming (see the beginning of the script)emacs-xxx
&ns-system-appearance-change(-xxx)
branches are already created and pushed to theupstream
remotegist_ids
variable) are already createdThe
emacs_branches
&gist_ids
variables should be the only needed updates for a new major emacs release, unless the feature branches cannot be simply rebased.