Skip to content

Instantly share code, notes, and snippets.

@ngquerol
Last active August 22, 2024 19:09
Show Gist options
  • Save ngquerol/8a4df4382654ccafba6e162c4c98701d to your computer and use it in GitHub Desktop.
Save ngquerol/8a4df4382654ccafba6e162c4c98701d to your computer and use it in GitHub Desktop.
Script to automate maintainance of the ns_system_appearance emacs patch set
#!/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
@ngquerol
Copy link
Author

ngquerol commented Oct 9, 2023

Several assumptions are made here;

  1. there exists a emacs subdirectory at the script's own path
  2. that subdirectory contains the emacs git repository, with two self-explanatory upstream and origin remotes
  3. origin is the repo where I maintain the branches, one per patch & major emacs version with a particular naming (see the beginning of the script)
  4. emacs-xxx & ns-system-appearance-change(-xxx) branches are already created and pushed to the upstream remote
  5. Gists (see gist_ids variable) are already created

The 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment