2 # amend HEAD commit to contain acab in its hash, it does so by repeatedly
3 # amending the commit with a new date.
12 parser = argparse.ArgumentParser()
13 parser.add_argument('--start', type=str, default='commit', help='now or commit')
14 parser.add_argument('--prefix', action='store_true')
15 parser.add_argument('--suffix', action='store_true')
16 parser.add_argument('-q', '--quiet', action='store_true')
17 args = parser.parse_args()
19 while not os.path.exists('.git'):
21 if os.getcwd() == '/':
22 sys.stderr('failed to find a git repository')
26 def amend_commit(repo, initial_commit, start_timestamp):
29 authored_timestamp = start_timestamp
31 authored_timestamp -= 1
32 for committed_timestamp in range(start_timestamp, authored_timestamp, -1):
34 if counter % 10000 == 0:
38 '%5d - %s - %s - [%s:%02d]'
41 time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(authored_timestamp)),
42 time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(committed_timestamp)),
43 int((time.time() - t0) // 60),
44 int((time.time() - t0) % 60),
49 commit = initial_commit.replace(
50 authored_date=authored_timestamp, committed_date=committed_timestamp
52 if args.prefix and not commit.hexsha.startswith('acab'):
54 if args.suffix and not commit.hexsha.endswith('acab'):
56 if 'acab' not in commit.hexsha:
58 repo.active_branch.set_commit(commit)
64 commit = repo.commit('HEAD')
66 if args.start == 'commit':
67 start_timestamp = commit.authored_date
68 elif args.start == 'now':
69 start_timestamp = int(time.time())
71 sys.stderr('unknown value for --start')
74 new_head = amend_commit(repo, commit, start_timestamp)
77 print('\ngot %s 🔥🚓' % new_head.hexsha)