Commit 84dbfe97 authored by Dom Sekotill's avatar Dom Sekotill
Browse files

Fix copyright.py when a repo has no commits

parent fa960739
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -22,7 +22,9 @@ import os
import re
import sys
import time
from functools import lru_cache
from pathlib import Path
from subprocess import DEVNULL
from subprocess import PIPE
from subprocess import run
from typing import Dict
@@ -93,6 +95,16 @@ def split_paths(paths: bytes) -> Iterator[Path]:
	return (Path(p.decode()) for p in paths.split(b'\x00') if p != b'')


@lru_cache(1)
def has_commits() -> bool:
	"""
	Return whether the repository has any commits yet
	"""
	cmd = ['git', 'rev-parse', '--verify', '-q', 'HEAD']
	proc = run(cmd, stdout=DEVNULL)
	return proc.returncode == 0


def cli_parser() -> argparse.ArgumentParser:
	"""
	Return an argparse parser
@@ -120,6 +132,7 @@ def main() -> None:

	year = time.strftime('%Y')
	years = {path: year for path in paths if path.is_file()}
	if has_commits():
		years.update(get_file_years(paths))
		years.update((path, year) for path in get_changed(paths))