Skip to content

Commit

Permalink
fix: cfbs should not try to commit without diff
Browse files Browse the repository at this point in the history
Ticket: CFE-3967
Changelog: None
Signed-off-by: Mikita Pilinka <[email protected]>
  • Loading branch information
mineralsfree committed Jan 24, 2024
1 parent 1cad09d commit 5dd4a8d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 15 additions & 0 deletions cfbs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,18 @@ def git_discard_changes_in_file(file_name):
raise CFBSGitError(
"Failed to discard changes in file '%s'" % file_name
) from cpe
def git_check_tracked_changes(scope="all"):
should_commit = False
try:
result = run(["git", "status", "-s"], check=True, capture_output=True)
if scope == "all":
if len(result.stdout) > 0:
should_commit = True
else:
changes = list(map(lambda m: m.strip().split(' ')[1], list(filter(None, result.stdout.split('\n')))))
should_commit = any(i in changes for i in scope)
if not should_commit:
print("No changes to commit")
return should_commit
except CalledProcessError as cpe:
return False
4 changes: 2 additions & 2 deletions cfbs/git_magic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from cfbs.prompts import YES_NO_CHOICES, prompt_user
from cfbs.cfbs_config import CFBSConfig, CFBSReturnWithoutCommit
from cfbs.git import git_commit, git_discard_changes_in_file, CFBSGitError, is_git_repo
from cfbs.git import git_commit, git_discard_changes_in_file, CFBSGitError, is_git_repo, git_check_tracked_changes
from cfbs.args import get_args
from cfbs.result import Result
import logging as log
Expand Down Expand Up @@ -85,7 +85,7 @@ def decorated_fn(*args, **kwargs):
msg = commit_msg % tuple(positional_args)
else:
msg = commit_msg

should_commit &= git_check_tracked_changes(files_to_commit)
if not should_commit:
return ret

Expand Down

0 comments on commit 5dd4a8d

Please sign in to comment.