From ec08eb42773333890cebc0baedf1680f7ced4a0c Mon Sep 17 00:00:00 2001 From: nelsonic Date: Thu, 5 May 2022 17:22:18 +0100 Subject: [PATCH] restore Mock.checkout function --- lib/gogs.ex | 5 ++--- test/gogs_test.exs | 6 +++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/gogs.ex b/lib/gogs.ex index 3e452f0..4340934 100644 --- a/lib/gogs.ex +++ b/lib/gogs.ex @@ -116,14 +116,13 @@ defmodule Gogs do """ @spec local_branch_create(String.t(), String.t()) :: {:ok, map} | {:error, any} def local_branch_create(repo_name, _branch_name \\ "draft") do - # inject_git().checkout(local_git_repo(repo_name), ~w(-b draft)) - Git.checkout(local_git_repo(repo_name), ~w(-b draft)) + inject_git().checkout(local_git_repo(repo_name), ~w(-b draft)) end @spec local_file_write_text(String.t(), String.t(), String.t()) :: :ok | {:error, any} def local_file_write_text(repo_name, file_name, text) do file_path = Path.join([local_repo_path(repo_name), file_name]) - # IO.inspect("attempting to write to #{file_path}") + # Logger.info("attempting to write to #{file_path}") File.touch!(file_path) File.write(file_path, text) end diff --git a/test/gogs_test.exs b/test/gogs_test.exs index c5fd275..d26ee4f 100644 --- a/test/gogs_test.exs +++ b/test/gogs_test.exs @@ -62,7 +62,7 @@ defmodule GogsTest do delete_local_directory(repo) end - test "Gogs.clone error branch" do + test "Gogs.clone error (simulate unhappy path)" do repo = "error" org = "nelsonic" git_repo_url = GogsHelpers.remote_url_ssh(org, repo) @@ -73,12 +73,16 @@ defmodule GogsTest do test "local_branch_create/1 creates a new branch on the localhost" do repo_name = create_test_git_repo("myorg") + # delete before if exists: + Git.branch(GogsHelpers.local_git_repo(repo_name), ~w(-D draft)) + {:ok, res} = Gogs.local_branch_create(repo_name, "draft") assert res == "Switched to a new branch 'draft'\n" # Cleanup! Gogs.remote_repo_delete("myorg", repo_name) delete_local_directory(repo_name) + Git.branch(GogsHelpers.local_git_repo(repo_name), ~w(-D draft)) end