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

feat: include the option to unshallow a repository during a fetch #170

Merged
merged 1 commit into from
Dec 1, 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
26 changes: 19 additions & 7 deletions fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@ import (
type FetchOption func(*fetchOptions)

type fetchOptions struct {
All bool
Config []string
Depth int
Force bool
NoTags bool
RefSpecs []string
Tags bool
All bool
Config []string
Depth int
Force bool
NoTags bool
RefSpecs []string
Tags bool
Unshallow bool
}

func (o fetchOptions) String() string {
Expand All @@ -44,6 +45,10 @@ func (o fetchOptions) String() string {
buf.WriteString(" --no-tags")
}

if o.Unshallow {
buf.WriteString(" --unshallow")
}

if len(o.RefSpecs) > 0 {
buf.WriteString(" origin ")
buf.WriteString(strings.Join(o.RefSpecs, " "))
Expand Down Expand Up @@ -119,6 +124,13 @@ func WithFetchRefSpecs(refs ...string) FetchOption {
}
}

// WithUnshallow will fetch the complete history from the remote
func WithUnshallow() FetchOption {
return func(opts *fetchOptions) {
opts.Unshallow = true
}
}

// Fetch all remote changes from a remote repository without integrating (merging)
// them into the current repository (working directory). Ensures the current repository
// only tracks the latest remote changes
Expand Down
17 changes: 17 additions & 0 deletions fetch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,20 @@ func TestFetchWithFetchRefSpecs(t *testing.T) {
require.Len(t, dlog, 1)
assert.Equal(t, "test: add test for validating refspecs", dlog[0].Message)
}

func TestFetchWithUnshallow(t *testing.T) {
log := `(main, origin/main) fifth feature
feat: fourth feature
feat: third feature
feat: second feature
feat: first feature`
gittest.InitRepository(t, gittest.WithRemoteLog(log))
shallowClone(t, gittest.Remote(t))

client, _ := git.NewClient()
_, err := client.Fetch(git.WithUnshallow())
require.NoError(t, err)

glog := gittest.Log(t)
assert.Len(t, glog, 6)
}
Loading