Browse Source

Initial commit

master
Dylan Baker 5 years ago
commit
97743ecce8
2 changed files with 54 additions and 0 deletions
  1. 25
    0
      README.md
  2. 29
    0
      git-commit-at.py

+ 25
- 0
README.md View File

@@ -0,0 +1,25 @@
1
+# git-commit-at
2
+
3
+This is a small script that allows you to perform a git commit at a time other
4
+than the current time.
5
+
6
+## Installation
7
+
8
+```
9
+$ git clone https://git.sr.ht/~simulacrumparty/git-commit-at
10
+$ cp git-commit-at/git-commit-at.py /usr/local/bin/git-commit-at
11
+$ chmod +x /usr/local/bin/git-commit-at
12
+```
13
+
14
+## Usage
15
+
16
+```
17
+$ git commit-at [args] <message>
18
+```
19
+
20
+## Examples
21
+
22
+```
23
+$ git commit-at --plus 10 'Committing 10 hours in the future'
24
+$ git commit-at --minus 10 'Committing 10 hours in the past'
25
+```

+ 29
- 0
git-commit-at.py View File

@@ -0,0 +1,29 @@
1
+#!/usr/bin/env python3
2
+
3
+import argparse
4
+import datetime
5
+import subprocess
6
+
7
+def main():
8
+    parser = argparse.ArgumentParser(description="Perform a git commit at a different time")
9
+    parser.add_argument("--minus", type=int, default=0, help="Hours to subtract")
10
+    parser.add_argument("--plus", type=int, default=0, help="Hours to add")
11
+    parser.add_argument("message", type=str, help="The commit message")
12
+
13
+    args = parser.parse_args()
14
+
15
+    minus = datetime.timedelta(hours=args.minus)
16
+    plus = datetime.timedelta(hours=args.plus)
17
+
18
+    date = datetime.datetime.now().astimezone() - minus + plus
19
+    formatted_date = date.strftime("%a %b %d %Y %H:%M:%S %z")
20
+
21
+    env = {
22
+        "GIT_AUTHOR_DATE": formatted_date,
23
+        "GIT_COMMITTER_DATE": formatted_date
24
+    }
25
+
26
+    subprocess.call(["git", "commit", "-m", args.message, "--date", formatted_date], env=env)
27
+
28
+if __name__ == "__main__":
29
+    main()

Loading…
Cancel
Save