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

clean up deprecated function #25

Merged
merged 1 commit into from
Oct 15, 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
2 changes: 1 addition & 1 deletion pkg/mirror/example_noworktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/mirror/example_worktree_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 0 additions & 9 deletions pkg/mirror/repo_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
18 changes: 0 additions & 18 deletions pkg/mirror/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <ref> [-- <path>]
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()
Expand Down
42 changes: 0 additions & 42 deletions pkg/mirror/z_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down
Loading