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

build: lookup the right git binary on WSL #1477

Merged
merged 3 commits into from
Dec 16, 2022
Merged

Conversation

crazy-max
Copy link
Member

@crazy-max crazy-max commented Dec 15, 2022

closes #1470

Windows drives in WSL version 2 uses the 9P protocol which the WSL instance connects to. When running git operations on a 9p fs using git from /usr/bin/git, it can be quite slow:

$ cd /mnt/c/github.com/moby/moby
$ time git -c log.showSignature=false status --porcelain --ignored >/dev/null
real    1m5.620s
user    0m0.387s
sys     0m59.010s

But using git.exe is quite fast:

$ cd /mnt/c/github.com/moby/moby
$ time git.exe -c log.showSignature=false status --porcelain --ignored >/dev/null
real    0m0.147s
user    0m0.003s
sys     0m0.009s

This change will detect if git operations occur on WSL and on a 9p fs and in this case lookup for git.exe, otherwise fallback to git.

Signed-off-by: CrazyMax crazy-max@users.noreply.github.com

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
build/git.go Outdated Show resolved Hide resolved
build/git.go Show resolved Hide resolved
build/git.go Outdated
@@ -50,30 +51,45 @@ func getGitAttributes(ctx context.Context, contextPath string, dockerfilePath st

gitc, err := gitutil.New(gitutil.WithContext(ctx), gitutil.WithWorkingDir(wd))
if err != nil {
logrus.Warnf("Failed to initialize git: %v", err)
if st, err := os.Stat(path.Join(wd, ".git")); err == nil && st.IsDir() {
return nil, errors.New("git not found in PATH, but .git directory exists")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still a warning, not a failing error.

WARN: No git was found in the system. Current commit information was not captured by the build.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't notice that warning is on caller side. But update the message.

build/git.go Outdated
return
}

if !gitc.IsInsideWorkTree() {
logrus.Warnf("Unable to determine git information")
return
return nil, errors.New("not inside a git repository")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not an error. If no git repo then just continue.

Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants