채록채록
[Developing] hook, pre-commit 본문
PS C:\chaen\M5ers> pre-commit -V
pre-commit 4.0.1
PS C:\chaen\M5ers> pre-commit sample-config > .pre-commit-config.yaml
PS C:\chaen\M5ers> ls
디렉터리: C:\chaen\M5ers
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 24-10-17(목) 오후 5:27 656 .pre-commit-config.yaml
PS C:\chaen\M5ers> pre-commit run
An error has occurred: FatalError: git failed. Is it installed, and are you in a Git repository directory?
Check the log at C:\Users\chaen\.cache\pre-commit\pre-commit.log
PS C:\chaen\M5ers> git --version
git version 2.41.0.windows.1
PS C:\chaen\M5ers> git status
fatal: not a git repository (or any of the parent directories): .git
PS C:\chaen\M5ers> git init
Initialized empty Git repository in C:/chaen/M5ers/.git/
PS C:\chaen\M5ers> pre-commit run
An error has occurred: InvalidConfigError:
==> File .pre-commit-config.yaml
=====> 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Check the log at C:\Users\chaen\.cache\pre-commit\pre-commit.log
PS C:\chaen\M5ers> pre-commit run
An error has occurred: InvalidConfigError:
==> File .pre-commit-config.yaml
=====> 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte
Check the log at C:\Users\chaen\.cache\pre-commit\pre-commit.log
PS C:\chaen\M5ers> pre-commit run
[INFO] Initializing environment for https://github.com/pre-commit/pre-commit-hooks.
[WARNING] repo `https://github.com/pre-commit/pre-commit-hooks` uses deprecated stage names (commit, push) which will be removed in a future version. Hint: often `pre-commit autoupdate --repo https://github.com/pre-commit/pre-commit-hooks` will fix this. if it does not -- consider reporting an issue to that repo.
[INFO] Installing environment for https://github.com/pre-commit/pre-commit-hooks.
[INFO] Once installed this environment will be reused.
[INFO] This may take a few minutes...
Trim Trailing Whitespace.............................(no files to check)Skipped
Fix End of Files.....................................(no files to check)Skipped
Check Yaml...........................................(no files to check)Skipped
Check for added large files..........................(no files to check)Skipped
PS C:\chaen\M5ers> git add .pre-commit-config.yaml
PS C:\chaen\M5ers> pre-commit run -a
Trim Trailing Whitespace.................................................Passed
Fix End of Files.........................................................Passed
Check Yaml...............................................................Passed
Check for added large files..............................................Passed
PS C:\chaen\M5ers> git commit -m "creates .pre-commit-config.yaml"
[main (root-commit) c476a10] creates .pre-commit-config.yaml
1 file changed, 10 insertions(+)
create mode 100644 .pre-commit-config.yaml
PS C:\chaen\M5ers> echo "test " > test.txt
PS C:\chaen\M5ers> git add test.txt
PS C:\chaen\M5ers> pre-commit run
Trim Trailing Whitespace.................................................Passed
Fix End of Files.........................................................Failed
- hook id: end-of-file-fixer
- exit code: 1
- files were modified by this hook
Fixing test.txt
Check Yaml...........................................(no files to check)Skipped
Check for added large files..............................................Passed
PS C:\chaen\M5ers> git status
On branch main
Changes to be committed:
(use "git restore --staged <file>..." to unstage)
new file: test.txt
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git restore <file>..." to discard changes in working directory)
modified: test.txt
PS C:\chaen\M5ers> git add test.txt
PS C:\chaen\M5ers> pre-commit run
Trim Trailing Whitespace.................................................Passed
Fix End of Files.........................................................Passed
Check Yaml...........................................(no files to check)Skipped
Check for added large files..............................................Passed
PS C:\chaen\M5ers>
- Git의 pre-commit hook은 작성한 코드를 commit할 때마다 자동으로 특정 작업을 실행해준다.
- 코드에 잠재하고 있는 문제들을 찾아낸다.
- 인간은 기계가 아니기 때문에 실수도 하기 때문이다.
- pre-commit은 Git의 pre-commit hook을 편리하게 사용할 수 있도록 도와주는 도구이다.
- 프로젝트의 모든 개발자들은 git 저장소를 clone받은 후에 제일 먼저 pre-commit install 커맨드를 실행해야한다.
이 명령어를 실행한 후에는 매번 pre-commit run 커맨드를 실행하지 않아도, 커밋을 할려고 할 때마다 자동으로 pre-commit이 실행되기 때문이다.
이런게 현재 현장실습하고 있는 회사에 도입되어있었다면,
"," 안찍어서 그렇게 하루종일 시간을 날리는 일도
그래서 결국 전시회에 기능 하나를 최적화하지 못한 채 가는 일도
없었을지도 모르겠다.
Reference: