Skip to content

Instantly share code, notes, and snippets.

@bhankas
Last active September 19, 2022 10:24
Show Gist options
  • Save bhankas/422c34db2e987d4dc3f243e26ba156a3 to your computer and use it in GitHub Desktop.
Save bhankas/422c34db2e987d4dc3f243e26ba156a3 to your computer and use it in GitHub Desktop.
eglot2emacs

This code merges eglot.el from joaotavora/eglot to upstream emacs.git master branch. It does below:

  • Move eglot.el to lisp/progmodes/eglot.el
  • Preserve complete history from original repo for the file
  • Edit commit messages to append URLs for all mentioned issues and PRs to individual commit message

Dependencies required

While made by order, it is perfect example and suitable to rearrange code while preserving as well as modifying git history programmatically.

Hope it helps!

for match in re.finditer(b"([ ,\(]|Fix|github)#[0-9]+", message):
message = b''.join([message, b'\n', match.group(0).strip(), b': https://github.com/joaotavora/eglot/issues/', re.sub(b"[^0123456789]", b"", match.group(0))])
return message
# move to a directory where both repos can be cloned
cd ~/git
# TODO: Save eglot2emacs.py here
# clone repos
git clone https://github.com/joaotavora/eglot.git
git clone -b master git://git.sv.gnu.org/emacs.git
# filter eglot with only eglot.el
# move eglot.el to lisp/progmodes/eglot.el -> This makes history file specific and everything makes
# find+replace # in commit messages
cd eglot
git filter-repo --to-subdirectory-filter lisp/progmodes/ --path eglot.el --message-callback ../eglot2emacs.py
# back to emacs repo
cd ../emacs
# add filtered eglot as upstream
git remote add eglot ../eglot/
git fetch eglot master
# prepare emacs repo for merge
git merge remotes/eglot/master --allow-unrelated-histories --no-commit
# make a commit
git commit -m "; Merge from joaotavora/eglot"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment