From 22f22406d18233bf8b10b7d5c452893a4bb77fc5 Mon Sep 17 00:00:00 2001 From: Chris Cummins Date: Sun, 12 Jan 2020 18:37:42 +0000 Subject: [PATCH] Write commit message to local cache. Signed-off-by: format 2020.01.12 [Exported from 6f77cd82ffc80c2814574d6ad9455e0c0a419daf] --- tools/format/format.py | 2 +- tools/format/git_util.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/format/format.py b/tools/format/format.py index 0fe453ff..7f0f50ac 100644 --- a/tools/format/format.py +++ b/tools/format/format.py @@ -126,7 +126,7 @@ def Main(argv): print("\n".join(sorted(formatters.keys()))) return elif FLAGS.install_pre_commit_hook: - git_util.InstallPreCommitHookOrDie() + git_util.InstallPreCommitHookOrDie(cache_dir) return # Acquire an inter-process lock. This does not need to be released - cleanup diff --git a/tools/format/git_util.py b/tools/format/git_util.py index 77e4d618..0c6f8c50 100644 --- a/tools/format/git_util.py +++ b/tools/format/git_util.py @@ -92,7 +92,7 @@ def GitAddOrDie(paths: Iterable[pathlib.Path]): sys.exit(1) -def InstallPreCommitHookOrDie(): +def InstallPreCommitHookOrDie(cache_path: pathlib.Path): git_root = GetGitRootOrDie() hooks_dir = git_root / ".git" / "hooks" @@ -121,10 +121,10 @@ def InstallPreCommitHookOrDie(): f.write( f"""\ #!/usr/bin/env bash -cp $1 /tmp/format_pre_commit_message.txt +cp $1 {cache_path / 'git_commit_message.txt'} echo -e "\\n\\nSigned-off-by: format {version} " > $1 -cat /tmp/format_pre_commit_message.txt >> $1 -rm -f /tmp/format_pre_commit_message.txt +cat {cache_path / 'git_commit_message.txt'} >> $1 +rm -f {cache_path / 'git_commit_message.txt'} """ ) os.chmod(prepare_commit_msg, 0o744)