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

fix: fix git failures for versions prior to 2.28 #184

Merged
merged 2 commits into from
Feb 24, 2023
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
9 changes: 5 additions & 4 deletions src/algokit/cli/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,10 +380,11 @@ def git(*args: str, bad_exit_warn_message: str) -> bool:
logger.warning(bad_exit_warn_message)
return success

if git("init", "--initial-branch=main", bad_exit_warn_message="Failed to initialise git repository"):
if git("add", "--all", bad_exit_warn_message="Failed to add generated project files"):
if git("commit", "-m", commit_message, bad_exit_warn_message="Initial commit failed"):
logger.info("🎉 Performed initial git commit successfully! 🎉")
if git("init", bad_exit_warn_message="Failed to initialise git repository"):
if git("checkout", "-b", "main", bad_exit_warn_message="Failed to name initial branch"):
if git("add", "--all", bad_exit_warn_message="Failed to add generated project files"):
if git("commit", "-m", commit_message, bad_exit_warn_message="Initial commit failed"):
logger.info("🎉 Performed initial git commit successfully! 🎉")


def _get_run_bootstrap() -> bool:
Expand Down
13 changes: 10 additions & 3 deletions tests/init/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,11 @@
GIT_BUNDLE_PATH = PARENT_DIRECTORY / "copier-helloworld.bundle"


def make_output_scrubber(**extra_tokens: str) -> Scrubber:
def make_output_scrubber(*extra_scrubbers: Callable[[str], str], **extra_tokens: str) -> Scrubber:
default_tokens = {"test_parent_directory": str(PARENT_DIRECTORY)}
tokens = default_tokens | extra_tokens
return combine_scrubbers(
*extra_scrubbers,
click.unstyle,
TokenScrubber(tokens=tokens),
TokenScrubber(tokens={"test_parent_directory": str(PARENT_DIRECTORY).replace("\\", "/")}),
Expand Down Expand Up @@ -167,7 +168,7 @@ def test_init_minimal_interaction_required_yes_git_no_network(
git_initial_commit_hash = git_rev_list.stdout[:7]
verify(
result.output,
scrubber=make_output_scrubber(git_initial_commit_hash=git_initial_commit_hash),
scrubber=make_output_scrubber(_remove_git_hints, git_initial_commit_hash=git_initial_commit_hash),
)


Expand Down Expand Up @@ -371,7 +372,7 @@ def test_init_ask_about_git(tmp_path_factory: TempPathFactory, mock_questionary_
git_initial_commit_hash = git_rev_list.stdout[:7]
verify(
result.output,
scrubber=make_output_scrubber(git_initial_commit_hash=git_initial_commit_hash),
scrubber=make_output_scrubber(_remove_git_hints, git_initial_commit_hash=git_initial_commit_hash),
)


Expand Down Expand Up @@ -516,3 +517,9 @@ def test_init_with_custom_env(tmp_path_factory: TempPathFactory):
),
scrubber=make_output_scrubber(),
)


def _remove_git_hints(output: str) -> str:
git_init_hint_prefix = "DEBUG: git: hint:"
lines = [line for line in output.splitlines() if not line.startswith(git_init_hint_prefix)]
return "\n".join(lines)
4 changes: 3 additions & 1 deletion tests/init/test_init.test_init_ask_about_git.approved.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ DEBUG: Template initialisation complete, final clone URL = {test_parent_director
Executed `algokit bootstrap all` in {current_working_directory}/myapp
DEBUG: Running 'git rev-parse --show-toplevel' in '{current_working_directory}/myapp'
DEBUG: git: fatal: not a git repository (or any of the parent directories): .git
DEBUG: Running 'git init --initial-branch=main' in '{current_working_directory}/myapp'
DEBUG: Running 'git init' in '{current_working_directory}/myapp'
DEBUG: git: Initialized empty Git repository in {current_working_directory}/myapp/.git/
DEBUG: Running 'git checkout -b main' in '{current_working_directory}/myapp'
DEBUG: git: Switched to a new branch 'main'
DEBUG: Running 'git add --all' in '{current_working_directory}/myapp'
DEBUG: Running 'git commit -m Project initialised with AlgoKit CLI using template: {test_parent_directory}/copier-helloworld.bundle' in '{current_working_directory}/myapp'
DEBUG: git: [main (root-commit) {git_initial_commit_hash}] Project initialised with AlgoKit CLI using template: {test_parent_directory}/copier-helloworld.bundle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ DEBUG: Template initialisation complete, final clone URL = {test_parent_director
Executed `algokit bootstrap all` in {current_working_directory}/myapp
DEBUG: Running 'git rev-parse --show-toplevel' in '{current_working_directory}/myapp'
DEBUG: git: fatal: not a git repository (or any of the parent directories): .git
DEBUG: Running 'git init --initial-branch=main' in '{current_working_directory}/myapp'
DEBUG: Running 'git init' in '{current_working_directory}/myapp'
DEBUG: git: Initialized empty Git repository in {current_working_directory}/myapp/.git/
DEBUG: Running 'git checkout -b main' in '{current_working_directory}/myapp'
DEBUG: git: Switched to a new branch 'main'
DEBUG: Running 'git add --all' in '{current_working_directory}/myapp'
DEBUG: Running 'git commit -m Project initialised with AlgoKit CLI using template: {test_parent_directory}/copier-helloworld.bundle' in '{current_working_directory}/myapp'
DEBUG: git: [main (root-commit) {git_initial_commit_hash}] Project initialised with AlgoKit CLI using template: {test_parent_directory}/copier-helloworld.bundle
Expand Down