Skip to content

Instantly share code, notes, and snippets.

@peterbe
Created February 1, 2020 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peterbe/5dbe77d63ddcb310125bb1b5abf803cf to your computer and use it in GitHub Desktop.
Save peterbe/5dbe77d63ddcb310125bb1b5abf803cf to your computer and use it in GitHub Desktop.
import os
import json
from git import Git
def run(cwd):
g = Git(cwd)
loginfo = g.log("--pretty=format:metadata:%aD,%an,%ae", "--name-only")
last_modified = {}
files = []
def add(these_files, this_metadata):
for file in these_files:
if file not in last_modified:
last_modified[file] = this_metadata["date"]
files.clear()
for line in loginfo.splitlines():
if line.startswith("metadata:"):
if files:
add(files, metadata)
metadata = {"date": line.split(",")[1].strip()}
elif line:
files.append(line)
with open("lastmodified-python.json", "w") as f:
json.dump(last_modified, f, indent=2)
def main(*args):
cwd = args[0]
assert os.path.isdir(cwd)
run(cwd)
if __name__ == "__main__":
import sys
sys.exit(main(*sys.argv[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment