Skip to content

Instantly share code, notes, and snippets.

@mmastrac
Created June 24, 2016 22:28
Show Gist options
  • Save mmastrac/dc6362447b9cb6585beed7b4f9879f97 to your computer and use it in GitHub Desktop.
Save mmastrac/dc6362447b9cb6585beed7b4f9879f97 to your computer and use it in GitHub Desktop.
[merge "clang_format"]
name = clang-format merge driver
driver = /tmp/merge_driver.sh %O %A %B %L %P
recursive = binary
*.cpp merge=clang_format
*.h merge=clang_format
#!/bin/bash
BASE="$1"
OURS="$2"
OTHERS="$3"
PATH_FYI="$5"
clang-format -i -style=file "$BASE"
clang-format -i -style=file "$OURS"
clang-format -i -style=file "$OTHERS"
echo "clang-format merge driver. Merging $PATH_FYI"
echo git merge-file -p "1:$OURS" "2:$BASE" "3:$OTHERS" \> "$OURS.tmp"
git merge-file -p "$OURS" "$BASE" "$OTHERS" --theirs > "$OURS.tmp"
clang-format -i -style=file "$OURS.tmp" # one last format
RET=$?
mv "$OURS.tmp" "$OURS"
exit $RET
@mmastrac
Copy link
Author

mmastrac commented Jun 24, 2016

YOU SHOULD REMOVE THIS DRIVER AFTER REBASING YOUR PR!

First, rebase to the commit before everything goes to hell:

git rebase -i 2115e8a4a6814e32107b5205ff5c95bbd3c6e99c

Then, install the merge_driver and rebase to master, fixing any conflicts:

git rebase -i master

Finally, run a pass overtop of everything to reformat anything that didn't conflict:

git rebase -i master --exec "git reset --soft HEAD~ && git clang-format --style file && git commit -a -C ORIG_HEAD"

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