Skip to content

Commit

Permalink
support unshallow with fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
purpleclay committed Dec 1, 2024
1 parent efae20b commit 867d3ee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
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)
}

0 comments on commit 867d3ee

Please sign in to comment.