8000 Feat: Add post_commit · N-analyst/commitizen_auto@d315de2 · GitHub
[go: up one dir, main page]

Skip to content

Commit d315de2

Browse files
author
raw.data
committed
Feat: Add post_commit
1 parent 9ebb30a commit d315de2

File tree

5 files changed

+32
-2
lines changed

5 files changed

+32
-2
lines changed

.pre-commit-hooks.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
name: commitizen post-commit
4141
description: >
4242
cz-prepare-commit-msg created backup unlink.
43-
entry: /hooks/post-commit.py
43+
entry: cz post-commit
4444
stages: [post-commit]
4545
language: python
4646
language_version: python3

commitizen/cli.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,10 @@ def __call__(
484484
}
485485
]
486486
},
487+
{
488+
"name": ["post-commit"],
489+
"func": commands.PostCommit
490+
}
487491
],
488492
},
489493
}

commitizen/commands/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from .schema import Schema
1010
from .version import Version
1111
from .prepare_commit_msg import PrepareCommitMsg
12+
from .post_commit import PostCommit
1213

1314

1415
__all__ = (
@@ -22,5 +23,6 @@
2223
"Schema",
2324
"Version",
2425
"Init",
25-
"PrepareCommitMsg"
26+
"PrepareCommitMsg",
27+
"PostCommit"
2628
)

commitizen/commands/post_commit.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import os
2+
import tempfile
3+
from pathlib import Path
4+
5+
from commitizen.config import BaseConfig
6+
7+
8+
class PostCommit:
9+
def __init__(self, config: BaseConfig, arguments):
10+
pass
11+
12+
def __call__(self, *args, **kwargs):
13+
exit(self.post_commit())
14+
15+
def post_commit(self):
16+
backup_file = Path(
17+
tempfile.gettempdir(), f"cz.commit{os.environ.get('USER', '')}.backup"
18+
)
19+
20+
# remove backup file if it exists
21+
if backup_file.is_file():
22+
backup_file.unlink()

commitizen/commands/prepare_commit_msg.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ def prepare_commit_msg(self, commit_msg_file: Path) -> int:
3939
backup_file = Path(
4040
tempfile.gettempdir(), f"cz.commit{os.environ.get('USER', '')}.backup"
4141
)
42+
print(backup_file, '==== backup_file')
4243

4344
if backup_file.is_file():
45+
print('==== backup_file.is_file() 로직 진입')
4446
# confirm if commit message from backup file should be reused
4547
answer = input("retry with previous message? [y/N]: ")
4648
if answer.lower() == "y":

0 commit comments

Comments
 (0)
0