smart-commit-tool 1.0.0__tar.gz → 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: smart-commit-tool
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Summary: Automated pre-push workflow manager with built-in code quality enforcement and smart branch protection.
5
5
  License-File: LICENSE
6
6
  Requires-Python: >=3.11
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "smart-commit-tool"
7
- version = "1.0.0"
7
+ version = "1.0.1"
8
8
  description = "Automated pre-push workflow manager with built-in code quality enforcement and smart branch protection."
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.11"
@@ -17,7 +17,7 @@ dependencies = [
17
17
  smart-commit = "smart_commit.cli:main"
18
18
 
19
19
  [tool.smart_commit]
20
- repository_url = "https://github.com/mokinprokin/smart_commit.git"
20
+ repository_url = "https://github.com/mokinprokin/SmartCommit.git"
21
21
  commands = ["ruff check ."]
22
22
  protected_branches = ["main", "master", "prod", "release"]
23
23
 
@@ -27,7 +27,7 @@ def main():
27
27
 
28
28
  current_branch = GitService.get_current_branch()
29
29
  branch = args.branch or current_branch
30
-
30
+ GitService.switch_branch(branch)
31
31
  if branch in protected_branches:
32
32
  Console.warning(
33
33
  f"You are pushing directly to a protected branch: '{branch}'."
@@ -28,6 +28,23 @@ class GitService:
28
28
  def get_current_branch(cls) -> str:
29
29
  return cls._run(["git", "branch", "--show-current"]).stdout.strip()
30
30
 
31
+ @classmethod
32
+ def switch_branch(cls, branch: str):
33
+ """Safely switches to the target branch or creates it."""
34
+ current = cls.get_current_branch()
35
+ if current != branch:
36
+ Console.info(f"🌿 Switching branch: {current} ➔ {branch}")
37
+ has_commits = cls._run(["git", "rev-parse", "HEAD"]).returncode == 0
38
+
39
+ if not has_commits:
40
+ res = cls._run(["git", "branch", "-M", branch])
41
+ else:
42
+ res = cls._run(["git", "checkout", "-B", branch])
43
+
44
+ if res.returncode != 0:
45
+ error_msg = res.stderr.strip() or res.stdout.strip()
46
+ raise GitOperationError(f"Failed to switch branch: {error_msg}")
47
+
31
48
  @classmethod
32
49
  def has_staged_changes(cls) -> bool:
33
50
  """Checks if there are files already in the staging area."""
@@ -53,12 +70,15 @@ class GitService:
53
70
 
54
71
  @classmethod
55
72
  def commit(cls, message: str):
73
+ """Commits changes and extracts Git output if it fails."""
56
74
  res = cls._run(["git", "commit", "-m", message])
57
75
  if res.returncode != 0:
58
- raise GitOperationError("Commit failed. Ensure you have changes to commit.")
76
+ error_msg = res.stderr.strip() or res.stdout.strip()
77
+ raise GitOperationError(f"Commit failed. Git says:\n{error_msg}")
59
78
 
60
79
  @classmethod
61
80
  def push_with_retry(cls, branch: str):
81
+ """Pushes to remote, attempting a pull --rebase if rejected."""
62
82
  Console.info(f"Pushing to branch: {branch}...")
63
83
  res = cls._run(["git", "push", "-u", "origin", branch])
64
84
 
@@ -71,11 +91,14 @@ class GitService:
71
91
  pull_res = cls._run(["git", "pull", "origin", branch, "--rebase"])
72
92
 
73
93
  if pull_res.returncode != 0:
94
+ error_msg = pull_res.stderr.strip() or pull_res.stdout.strip()
74
95
  raise GitOperationError(
75
- "🛑 Rebase conflict detected! Please resolve manually and run again."
96
+ f"🛑 Rebase conflict detected!\nGit says: {error_msg}"
76
97
  )
77
98
 
78
99
  Console.success("Sync successful. Retrying push...")
79
100
  push_retry = cls._run(["git", "push", "-u", "origin", branch])
101
+
80
102
  if push_retry.returncode != 0:
81
- raise GitOperationError("Final push failed after rebase.")
103
+ error_msg = push_retry.stderr.strip() or push_retry.stdout.strip()
104
+ raise GitOperationError(f"Final push failed after rebase:\n{error_msg}")