Skip to content

Commit

Permalink
Improve the cleanliness of the git existence check
Browse files Browse the repository at this point in the history
Signed-off-by: jakub-nt <[email protected]>
  • Loading branch information
jakub-nt committed Jul 25, 2024
1 parent 9e932d0 commit d49ed80
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 2 additions & 4 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
)
from cfbs.index import _VERSION_INDEX, Index
from cfbs.git import (
check_git_exists,
git_exists,
is_git_repo,
git_commit,
git_get_config,
Expand Down Expand Up @@ -179,9 +179,7 @@ def init_command(index=None, masterfiles=None, non_interactive=False) -> int:
do_git = True if do_git == "yes" else False

if do_git is True:
try:
check_git_exists()
except FileNotFoundError as e:
if not git_exists():
print("Command 'git' was not found")
return 1

Expand Down
7 changes: 4 additions & 3 deletions cfbs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ class CFBSGitError(Exception):
pass


def check_git_exists():
def git_exists():
try:
check_call(["git", "--version"], stdout=DEVNULL)
except CalledProcessError as cpe:
raise CFBSGitError("'git' was not found") from cpe
return True
except FileNotFoundError:
return False


def ls_remote(remote, branch):
Expand Down

0 comments on commit d49ed80

Please sign in to comment.