Open
Description
When checking out with SparseCheckoutDirectories
pointing to a set of directories, if the directories start with a ./
path example: ./sparse-checkout
, the directory is ignored and checkout command silently continues without any errors. If sparse-checkout
is used instead of ./sparse-checkout
, this works as expected.
Is this by design ? It is possible to support the syntax with ./ since its intuitive for some users? Thank you!
Code to reproduce the behavior :
package main
import (
"fmt"
"io/fs"
"os"
"path/filepath"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
)
func main() {
dir, err := os.MkdirTemp("", "dir")
if err != nil {
panic("can't create temp dir")
}
r, err := git.PlainClone(dir, false, &git.CloneOptions{
URL: "https://github.com/dipti-pai/flux-test-repo.git",
NoCheckout: true,
SingleBranch: true,
Depth: 1,
Tags: git.NoTags,
ShallowSubmodules: true,
ReferenceName: plumbing.ReferenceName("refs/heads/main"),
})
if err != nil {
panic("can't clone repository")
}
w, err := r.Worktree()
if err != nil {
panic("can't get a worktree")
}
options := &git.CheckoutOptions{
Branch: plumbing.ReferenceName("refs/remotes/origin/main"),
SparseCheckoutDirectories: []string{"./sparse-checkout"},
}
err = w.Checkout(options)
if err != nil {
panic("can't checkout repository")
}
filepath.Walk(dir, func(f string, info fs.FileInfo, err error) error {
fmt.Println("File ", f)
if err != nil {
return err
}
return nil
})
}