X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=set-commit-date.py;h=74972e4653225207864e67fe3c603a7448e2471e;hb=e78829f5e4f3f167c40114a40c8d2d002fb5be4e;hp=a88c5dea43849ddba38a0272f6ce74a24ac9a995;hpb=a0f5c1217294a1a72b71bc94fd80760b0393e775;p=git-scripts.git diff --git a/set-commit-date.py b/set-commit-date.py index a88c5de..74972e4 100755 --- a/set-commit-date.py +++ b/set-commit-date.py @@ -5,18 +5,36 @@ # Adapted from https://git.wiki.kernel.org/index.php/ExampleScripts#Setting_the_timestamps_of_the_files_to_the_commit_timestamp_of_the_commit_which_last_touched_them # noqa +import argparse import os +import sys import subprocess git_root = subprocess.check_output(['git', 'rev-parse', '--show-toplevel'], universal_newlines=True).rstrip('\n') os.chdir(git_root) +parser = argparse.ArgumentParser(description='Set commit date') +parser.add_argument('-a', '--author', '--author-date', + action='store_true') +parser.add_argument('-c', '--committer', '--committer-date', + action='store_true') +args = parser.parse_args() + +if args.author and args.committer: + parser.print_help() + sys.exit("Use only one of `-a' or `-c' but not both") + +if args.author: + date_format = 'a' +else: + date_format = 'c' # This is the default + separator = '----- GIT LOG SEPARATOR -----' git_log = subprocess.Popen(['git', 'log', '-m', '--first-parent', '--name-status', '--no-color', - '--format=%s%%n%%ct' % separator], + '--format=%s%%n%%%st' % (separator, date_format)], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True) changed_files = set()