Advertisement
Guest User

Untitled

a guest
Mar 24th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. cat <<EOF
  4. Rewriting current branch to master, by applying black.
  5.  
  6. This is only tested for simple, linear branches and results should
  7. be checked thoroughly before abandoning the old history.
  8. EOF
  9.  
  10. # Find out the combined base commit
  11. BASE=$(git merge-base HEAD master)
  12. # How many commits are we ahead?
  13. commit_count=$(git rev-list --count ${BASE}..HEAD)
  14. # Get a list of every .py file that changed - so we don't reformat everything
  15. export changed_files="$(git log --name-only --pretty="format:" -${commit_count} | sort | uniq | sed -e '/^$/d' | grep '.py$')"
  16. echo "Changed files:"
  17. echo "${changed_files}"
  18.  
  19. # Do the rewriting. Do one commit more than required so that the first commit
  20. # doesn't include the diff from reformatting everything to black
  21. git filter-branch -f --tree-filter 'black $(echo "$changed_files" | xargs ls -d 2>/dev/null)' ${BASE}^..HEAD
  22. # Now, rebase the original number of commits onto the master
  23. git rebase HEAD~${commit_count} --onto master
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement