Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENT-11437: cfbs init no longer displays a traceback when git is not found #198

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading