From c29f95dac5145969baa0ca17873a34bdf8ea3a87 Mon Sep 17 00:00:00 2001 From: godcong Date: Tue, 8 Oct 2024 17:49:56 +0800 Subject: [PATCH] fix(repo): update git pull command and remove unused test - Modify the UpdateRepoWithCmd function to remove the branch name 'main' from the git pull command, allowing for flexibility in target branches. - Remove the unused test function TestCreatesCacheDirectory from Repository_BeforeCopy_test.go to streamline the test suite. --- internal/repo/Repository_BeforeCopy_test.go | 18 ------------------ internal/repo/repo_git.go | 2 +- 2 files changed, 1 insertion(+), 19 deletions(-) diff --git a/internal/repo/Repository_BeforeCopy_test.go b/internal/repo/Repository_BeforeCopy_test.go index 7c1692a..0fbfcac 100644 --- a/internal/repo/Repository_BeforeCopy_test.go +++ b/internal/repo/Repository_BeforeCopy_test.go @@ -1,29 +1,11 @@ package repo import ( - "os" "testing" "github.com/origadmin/toolkits/context" ) -// Successfully creates a cache directory if it does not exist -func TestCreatesCacheDirectory(t *testing.T) { - // Arrr, let's set sail and test the creation of the cache directory! - repo := Repository{ - cacheDir: "test_cache_dir", - useCmd: false, - } - err := repo.BeforeCopy(context.Background()) - if err != nil { - t.Fatalf("Expected no error, but got %v", err) - } - if _, err := os.Stat("test_cache_dir"); os.IsNotExist(err) { - t.Fatalf("Expected cache directory to be created, but it does not exist") - } - os.RemoveAll("test_cache_dir") -} - // Clones the repository using the go-git library when useCmd is false func TestCloneRepoWithGoGit(t *testing.T) { // Avast ye! Testing the go-git library for cloning! diff --git a/internal/repo/repo_git.go b/internal/repo/repo_git.go index 32819e0..9c12353 100644 --- a/internal/repo/repo_git.go +++ b/internal/repo/repo_git.go @@ -120,7 +120,7 @@ func CloneRepoWithCmd(ctx context.Context, repoURL, cacheDir, tag string) error // // If a tag is specified, it checks out that tag; otherwise, it fetches the latest version. func UpdateRepoWithCmd(ctx context.Context, cacheDir, tag string) error { // Pull the latest changes - cmd := exec.CommandContext(ctx, "git", "pull", "origin", "main") + cmd := exec.CommandContext(ctx, "git", "pull", "origin") cmd.Dir = cacheDir if err := cmd.Run(); err != nil { return errors.Wrap(err, "failed to pull repository")