Skip to content

Commit

Permalink
Merge pull request #198 from jakub-nt/ENT-11437
Browse files Browse the repository at this point in the history
ENT-11437: `cfbs init` no longer displays a traceback when `git` is not found
  • Loading branch information
olehermanse authored Jul 29, 2024
2 parents 968d4b0 + d49ed80 commit d2e1f1c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
)
from cfbs.index import _VERSION_INDEX, Index
from cfbs.git import (
git_exists,
is_git_repo,
git_commit,
git_get_config,
Expand Down Expand Up @@ -178,6 +179,10 @@ 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:
if not git_exists():
print("Command 'git' was not found")
return 1

user_name = get_args().git_user_name
if not user_name:
user_name = git_get_config("user.name")
Expand Down
8 changes: 8 additions & 0 deletions cfbs/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ class CFBSGitError(Exception):
pass


def git_exists():
try:
check_call(["git", "--version"], stdout=DEVNULL)
return True
except FileNotFoundError:
return False


def ls_remote(remote, branch):
"""Returns the hash of the commit that the current HEAD of a given branch
on a given remote is pointing to.
Expand Down

0 comments on commit d2e1f1c

Please sign in to comment.