Skip to content

Instantly share code, notes, and snippets.

View thedoubl3j's full-sized avatar
:shipit:
Ansible and Python

Jake Jackson thedoubl3j

:shipit:
Ansible and Python
View GitHub Profile
@jbradberry
jbradberry / rebase_migrations.py
Last active June 21, 2024 01:37
Re-number Django migrations during a rebase, use like `$ git rebase -i devel --exec "python3 rebase_migrations.py"`
from collections import defaultdict
from pathlib import Path
import re
import subprocess
changed_files = subprocess.check_output("git diff-tree --no-commit-id --name-status -r HEAD", shell=True)
changed_status = [line.split('\t') for line in changed_files.decode('utf-8').rstrip('\n').split('\n')]
changed_migrations = {fname for status, fname in changed_status
if '/migrations/' in fname and Path(fname).name[0].isdigit() and status != 'D'}