Created
July 18, 2022 02:24
-
-
Save scarf005/e31b13adfdc0d64bef2b46ccefd7b279 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
"""Fake git commits. | |
Usage: | |
fakecommit.py [-h] [--git=<git>] --date=<date> [-d] [--] <args>... | |
Options: | |
-h, --help Show this help message and exit. | |
-d, --dry Dry run. | |
--git=<git> alternative git-like program to use. [default: git] | |
--date=<date> date to use for the commit. iso8601 format mandatory. | |
""" | |
# from subprocess import run | |
from os import system | |
from textwrap import dedent, wrap | |
from docopt import docopt | |
def flatten(s: str) -> str: | |
return " ".join(wrap(dedent(s))) | |
def merge(args: list[str]) -> str: | |
"""if args contains space, wrap them with quote(")""" | |
def wrap(s: str) -> str: | |
return f'"{s}"' if " " in s else s | |
return " ".join(wrap(a) for a in args) | |
... | |
def main() -> None: | |
args = docopt(__doc__) # type: ignore | |
# print(args) | |
# fmt: off | |
payload = flatten( | |
"""GIT_AUTHOR_DATE="{date}" GIT_COMMITTER_DATE="{date}" {git} commit {args}""" | |
.format(date=args["--date"], git=args["--git"], args=merge(args["<args>"])) | |
) | |
# fmt: on | |
f = print if args["--dry"] else system | |
f(payload) | |
if __name__ == "__main__": | |
main() | |
# GIT_AUTHOR_DATE="2022-03-10 17:30:00" GIT_COMMITTER_DATE="2022-03-10 17:30:00" git commit -m "update readme" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment