diff --git a/pkg/mirror/example_noworktree_test.go b/pkg/mirror/example_noworktree_test.go index 36d529c..5957d90 100644 --- a/pkg/mirror/example_noworktree_test.go +++ b/pkg/mirror/example_noworktree_test.go @@ -61,7 +61,7 @@ repositories: } fmt.Println("last commit hash at main", "hash", hash) - msg, err := repos.LogMsg(ctx, "https://github.com/utilitywarehouse/git-mirror.git", "main", "") + msg, err := repos.Subject(ctx, "https://github.com/utilitywarehouse/git-mirror.git", "main") if err != nil { panic(err) } diff --git a/pkg/mirror/example_worktree_test.go b/pkg/mirror/example_worktree_test.go index 628d38b..2b1c3c5 100644 --- a/pkg/mirror/example_worktree_test.go +++ b/pkg/mirror/example_worktree_test.go @@ -64,7 +64,7 @@ repositories: } fmt.Println("last commit hash at main", "hash", hash) - msg, err := repos.LogMsg(ctx, "https://github.com/utilitywarehouse/git-mirror.git", "main", "") + msg, err := repos.Subject(ctx, "https://github.com/utilitywarehouse/git-mirror.git", "main") if err != nil { panic(err) } diff --git a/pkg/mirror/repo_pool.go b/pkg/mirror/repo_pool.go index cf38a17..20914aa 100644 --- a/pkg/mirror/repo_pool.go +++ b/pkg/mirror/repo_pool.go @@ -158,15 +158,6 @@ func (rp *RepoPool) Hash(ctx context.Context, remote, ref, path string) (string, return repo.Hash(ctx, ref, path) } -// LogMsg is wrapper around repositories LogMsg method -func (rp *RepoPool) LogMsg(ctx context.Context, remote, ref, path string) (string, error) { - repo, err := rp.Repository(remote) - if err != nil { - return "", err - } - return repo.LogMsg(ctx, ref, path) -} - // Subject is wrapper around repositories Subject method func (rp *RepoPool) Subject(ctx context.Context, remote, hash string) (string, error) { repo, err := rp.Repository(remote) diff --git a/pkg/mirror/repository.go b/pkg/mirror/repository.go index 04bc761..a7e93ce 100644 --- a/pkg/mirror/repository.go +++ b/pkg/mirror/repository.go @@ -168,24 +168,6 @@ func (r *Repository) Hash(ctx context.Context, ref, path string) (string, error) return r.hash(ctx, ref, path) } -// LogMsg returns the formatted log subject with author info of the given -// revision and for the path if specified. -func (r *Repository) LogMsg(ctx context.Context, ref, path string) (string, error) { - r.lock.RLock() - defer r.lock.RUnlock() - - args := []string{"log", `--pretty=format:'%s (%an)'`, "-n", "1", ref} - if path != "" { - args = append(args, "--", path) - } - // git log --pretty=format:'%s (%an)' -n 1 [-- ] - msg, err := runGitCommand(ctx, r.log, r.envs, r.dir, args...) - if err != nil { - return "", err - } - return strings.Trim(msg, "'"), nil -} - // Subject returns commit subject of given commit hash func (r *Repository) Subject(ctx context.Context, hash string) (string, error) { r.lock.RLock() diff --git a/pkg/mirror/z_e2e_test.go b/pkg/mirror/z_e2e_test.go index 859064e..5cffebb 100644 --- a/pkg/mirror/z_e2e_test.go +++ b/pkg/mirror/z_e2e_test.go @@ -769,12 +769,6 @@ func Test_commit_hash_msg(t *testing.T) { if _, err := repo.Hash(txtCtx, otherBranch, "dir1"); err == nil { t.Errorf("unexpected success for non-existent branch:%s", otherBranch) } - if _, err := repo.LogMsg(txtCtx, otherBranch, ""); err == nil { - t.Errorf("unexpected success for non-existent branch:%s", otherBranch) - } - if _, err := repo.LogMsg(txtCtx, otherBranch, "dir1"); err == nil { - t.Errorf("unexpected success for non-existent branch:%s", otherBranch) - } } func Test_commit_hash_files_merge(t *testing.T) { @@ -1398,17 +1392,6 @@ func Test_RepoPool_Success(t *testing.T) { t.Errorf("remote2 hash mismatch got:%s want:%s", got, fileU2SHA2) } - if got, err := rp.LogMsg(txtCtx, remote1, "HEAD", ""); err != nil { - t.Fatalf("unexpected err:%s", err) - } else if !strings.Contains(got, t.Name()+"-u1-main-2") { - t.Errorf("remote1 commit msg mismatch got:%s want:%s", got, t.Name()+"-u1-main-2") - } - if got, err := rp.LogMsg(txtCtx, remote2, "HEAD", ""); err != nil { - t.Fatalf("unexpected err:%s", err) - } else if !strings.Contains(got, t.Name()+"-u2-main-2") { - t.Errorf("remote2 commit msg mismatch got:%s want:%s", got, t.Name()+"-u2-main-2") - } - // after mirror we should expect a symlink at root and a file with test function name assertLinkedFile(t, root, "link1", "file", t.Name()+"-u1-main-2") assertLinkedFile(t, root, "link3", "file", t.Name()+"-u1-main-2") @@ -1452,17 +1435,6 @@ func Test_RepoPool_Success(t *testing.T) { t.Errorf("remote2 hash mismatch got:%s want:%s", got, fileU2SHA1) } - if got, err := rp.LogMsg(txtCtx, remote1, "HEAD", ""); err != nil { - t.Fatalf("unexpected err:%s", err) - } else if !strings.Contains(got, t.Name()+"-u1-main-1") { - t.Errorf("remote1 commit msg mismatch got:%s want:%s", got, t.Name()+"-u1-main-1") - } - if got, err := rp.LogMsg(txtCtx, remote2, "HEAD", ""); err != nil { - t.Fatalf("unexpected err:%s", err) - } else if !strings.Contains(got, t.Name()+"-u2-main-1") { - t.Errorf("remote2 commit msg mismatch got:%s want:%s", got, t.Name()+"-u2-main-1") - } - // after mirror we should expect a symlink at root and a file with test function name assertLinkedFile(t, root, "link1", "file", t.Name()+"-u1-main-1") assertLinkedFile(t, root, "link3", "file", t.Name()+"-u1-main-1") @@ -1575,11 +1547,6 @@ func Test_RepoPool_Error(t *testing.T) { } else if err != ErrNotExist { t.Errorf("error mismatch got:%s want:%s", err, ErrNotExist) } - if _, err := rp.LogMsg(context.Background(), nonExistingRemote, "HEAD", ""); err == nil { - t.Errorf("unexpected success for non existing repo") - } else if err != ErrNotExist { - t.Errorf("error mismatch got:%s want:%s", err, ErrNotExist) - } if _, err := rp.Clone(context.Background(), nonExistingRemote, testTmpDir, "HEAD", "", false); err == nil { t.Errorf("unexpected success for non existing repo") } else if err != ErrNotExist { @@ -1719,22 +1686,13 @@ func assertCommitLog(t *testing.T, repo *Repository, ref, path, wantSHA, wantSub string, wantChangedFiles []string) { t.Helper() - var wantMsg string // add user info - if wantSub != "" { - wantMsg = fmt.Sprintf("%s (%s)", wantSub, testGitUser) - } gotHash, err := repo.Hash(txtCtx, ref, path) if err != nil { t.Fatalf("unexpected error: %v", err) } else if gotHash != wantSHA { t.Errorf("ref '%s' on path '%s' SHA mismatch got:%s want:%s", ref, path, gotHash, wantSHA) } - if got, err := repo.LogMsg(txtCtx, ref, path); err != nil { - t.Fatalf("unexpected error: %v", err) - } else if got != wantMsg { - t.Errorf("ref '%s' on path '%s' Msg mismatch got:%s want:%s", ref, path, got, wantMsg) - } if wantSHA == "" { return