Skip to content

Commit 865950c

Browse files
committed
fix(core): Update version to 0.1.4 & fix subpro...
Updates the project version to 0.1.4. This release includes a fix for subprocess encoding issues. The change ensures correct handling of subprocess output. It improves reliability and potentially resolves encoding-related problems. Affected files: - M setup.py - M smart_git_commit.py
1 parent 11dea4c commit 865950c

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
setup(
1515
name="smart-git-commit",
16-
version="0.1.3",
16+
version="0.1.4",
1717
description="AI-powered Git commit workflow tool",
1818
long_description=long_description,
1919
long_description_content_type="text/markdown",

smart_git_commit.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,9 @@ def _run_git_command(self, args: List[str]) -> Tuple[str, int]:
381381
stdout=subprocess.PIPE,
382382
stderr=subprocess.PIPE,
383383
cwd=self.repo_path,
384-
text=True
384+
text=True,
385+
encoding='utf-8', # Specify UTF-8 encoding
386+
errors='ignore' # Ignore decoding errors
385387
)
386388
stdout, stderr = process.communicate()
387389
if process.returncode != 0 and stderr:
@@ -518,7 +520,7 @@ def _create_importance_prompt(self, change: GitChange) -> str:
518520
else:
519521
# For untracked files, read a sample of the content
520522
try:
521-
with open(os.path.join(self.repo_path, change.filename), 'r') as f:
523+
with open(os.path.join(self.repo_path, change.filename), 'r', encoding='utf-8', errors='ignore') as f:
522524
file_content = "".join(f.readlines()[:50])
523525
except Exception:
524526
pass
@@ -881,10 +883,21 @@ def execute_commits(self, interactive: bool = True) -> None:
881883
return
882884

883885
# Execute the commit
884-
with open(os.path.join(self.repo_path, ".git", "COMMIT_EDITMSG"), "w") as f:
885-
f.write(commit_message)
886-
887-
stdout, code = self._run_git_command(["commit", "-F", os.path.join(".git", "COMMIT_EDITMSG")])
886+
# Write commit message with UTF-8 encoding explicitly
887+
commit_msg_path = os.path.join(self.repo_path, ".git", "COMMIT_EDITMSG")
888+
try:
889+
with open(commit_msg_path, "w", encoding='utf-8') as f:
890+
f.write(commit_message)
891+
892+
stdout, code = self._run_git_command(["commit", "-F", os.path.join(".git", "COMMIT_EDITMSG")])
893+
finally:
894+
# Clean up the temporary commit message file
895+
if os.path.exists(commit_msg_path):
896+
try:
897+
os.remove(commit_msg_path)
898+
except OSError as e:
899+
logger.warning(f"Could not remove temporary commit message file: {e}")
900+
888901
if code != 0:
889902
logger.error("Failed to commit changes")
890903
if interactive:

0 commit comments

Comments
 (0)