]> git.0d.be Git - git-acab.git/blob - git-acab
0a651468a0a8d5a04c73a1c59f23300b5fbc82d5
[git-acab.git] / git-acab
1 #! /usr/bin/python3
2 # amend HEAD commit to contain acab in its hash, it does so by repeatedly
3 # amending the commit with a new date.
4
5 import argparse
6 import subprocess
7 import sys
8 import time
9
10 parser = argparse.ArgumentParser()
11 parser.add_argument('--start', type=str, default='commit', help='now or commit')
12 parser.add_argument('--prefix', action='store_true')
13 parser.add_argument('--suffix', action='store_true')
14 parser.add_argument('-q', '--quiet', action='store_true')
15 args = parser.parse_args()
16
17 if args.start == 'commit':
18     p = subprocess.run(['git', 'show', '--format=format:%at'], capture_output=True)
19     timestamp = int(p.stdout[: p.stdout.index(b'\n')])
20 elif args.start == 'now':
21     timestamp = int(time.time())
22 else:
23     sys.stderr('unknown value for --start')
24     sys.exit(1)
25
26 t0 = time.time()
27 counter = 0
28 direction = -1
29 while True:
30     counter += 1
31     timestamp += direction
32     if counter % 3600 == 0:
33         # don't move more than one hour in the past, going back to initial time
34         # will give new commit hashes as the commit date (not author date) will
35         # be different.
36         direction = - direction
37     if not args.quiet:
38         print(
39             '%5d - %s - [%s:%02d]'
40             % (
41                 counter,
42                 time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)),
43                 int((time.time() - t0) // 60),
44                 int((time.time() - t0) % 60),
45             ),
46             end='\r',
47         )
48     p = subprocess.run(
49         [
50             'git',
51             'commit',
52             '--no-verify',
53             '--amend',
54             '--no-edit',
55             '--date=%s' % time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(timestamp)),
56         ],
57         capture_output=True,
58     )
59     p = subprocess.run(['git', 'rev-parse', 'HEAD'], capture_output=True)
60     if args.prefix and not p.stdout.startswith(b'acab'):
61         continue
62     if args.suffix and not p.stdout.strip().endswith(b'acab'):
63         continue
64     if b'acab' in p.stdout:
65         break
66
67 if not args.quiet:
68     print('\ngot %s ðŸ”¥ðŸš“' % p.stdout.decode().strip())