diff --git a/pre_commit/git.py b/pre_commit/git.py index 576bef8c..ce637b16 100644 --- a/pre_commit/git.py +++ b/pre_commit/git.py @@ -42,6 +42,10 @@ def no_git_env(_env: Optional[EnvironT] = None) -> Dict[str, str]: } +def get_basename() -> str: + return cmd_output('basename', get_root())[1].strip() + + def get_root() -> str: return cmd_output('git', 'rev-parse', '--show-toplevel')[1].strip() diff --git a/pre_commit/staged_files_only.py b/pre_commit/staged_files_only.py index 61793010..16e21b6f 100644 --- a/pre_commit/staged_files_only.py +++ b/pre_commit/staged_files_only.py @@ -47,7 +47,8 @@ def _unstaged_changes_cleared(patch_dir: str) -> Generator[None, None, None]: retcode=None, ) if retcode and diff_stdout_binary.strip(): - patch_filename = f'patch{int(time.time())}' + strftime = time.strftime('%Y-%m-%d-%H-%M-%S', time.gmtime()) + patch_filename = f'patch-{git.get_basename()}-{strftime}' patch_filename = os.path.join(patch_dir, patch_filename) logger.warning('Unstaged files detected.') logger.info(f'Stashing unstaged files to {patch_filename}.')