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

Fix workspace integration failed due to the git safe.directory error #10091

Closed
wants to merge 3 commits into from
Closed
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
1 change: 1 addition & 0 deletions test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ require (
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.5.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb // indirect
github.com/imdario/mergo v0.3.12 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions test/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ github.com/hashicorp/logutils v1.0.0/go.mod h1:QIAnNjmIWmVIIkWDTG1z5v++HQmx9WQRO
github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0mNTz8vQ=
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb h1:tsEKRC3PU9rMw18w/uAptoijhgG4EvlA5kfJPtwrMDk=
github.com/heptiolabs/healthcheck v0.0.0-20211123025425-613501dd5deb/go.mod h1:NtmN9h8vrTveVQRLHcX2HQ5wIPBDCsZ351TGbZWgg38=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
Expand Down
33 changes: 24 additions & 9 deletions test/pkg/integration/common/git-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
package common

import (
"fmt"
"net/rpc"
"strings"

"golang.org/x/xerrors"

agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api"
)

Expand All @@ -29,10 +28,10 @@ func (g GitClient) GetBranch(workspaceRoot string) (string, error) {
Args: []string{"rev-parse", "--abbrev-ref", "HEAD"},
}, &resp)
if err != nil {
return "", xerrors.Errorf("getBranch error: %w", err)
return "", fmt.Errorf("getBranch error: %w", err)
}
if resp.ExitCode != 0 {
return "", xerrors.Errorf("getBranch rc!=0: %d", resp.ExitCode)
return "", fmt.Errorf("getBranch returned rc: %d err: %v", resp.ExitCode, resp.Stderr)
}
return strings.Trim(resp.Stdout, " \t\n"), nil
}
Expand All @@ -54,7 +53,23 @@ func (g GitClient) Add(dir string, files ...string) error {
return err
}
if resp.ExitCode != 0 {
return xerrors.Errorf("commit returned rc: %d", resp.ExitCode)
return fmt.Errorf("add returned rc: %d err: %v", resp.ExitCode, resp.Stderr)
}
return nil
}

func (g GitClient) ConfigSafeDirectory(dir string) error {
var resp agent.ExecResponse
err := g.Call("WorkspaceAgent.Exec", &agent.ExecRequest{
Dir: dir,
Command: "git",
Args: []string{"config", "--global", "--add", "safe.directory", dir},
}, &resp)
if err != nil {
return err
}
if resp.ExitCode != 0 {
return fmt.Errorf("config returned rc: %d err: %v", resp.ExitCode, resp.Stderr)
}
return nil
}
Expand All @@ -71,7 +86,7 @@ func (g GitClient) ConfigUserName(dir string) error {
return err
}
if resp.ExitCode != 0 {
return xerrors.Errorf("config user name returned rc: %d", resp.ExitCode)
return fmt.Errorf("config user name returned rc: %d err: %v", resp.ExitCode, resp.Stderr)
}
return nil
}
Expand All @@ -88,7 +103,7 @@ func (g GitClient) ConfigUserEmail(dir string, files ...string) error {
return err
}
if resp.ExitCode != 0 {
return xerrors.Errorf("config user email returned rc: %d", resp.ExitCode)
return fmt.Errorf("config user email returned rc: %d err: %v", resp.ExitCode, resp.Stderr)
}
return nil
}
Expand All @@ -108,7 +123,7 @@ func (g GitClient) Commit(dir string, message string, all bool) error {
return err
}
if resp.ExitCode != 0 {
return xerrors.Errorf("commit returned rc: %d", resp.ExitCode)
return fmt.Errorf("commit returned rc: %d err: %v", resp.ExitCode, resp.Stderr)
}
return nil
}
Expand All @@ -131,7 +146,7 @@ func (g GitClient) Push(dir string, force bool, moreArgs ...string) error {
return err
}
if resp.ExitCode != 0 {
return xerrors.Errorf("commit returned rc: %d", resp.ExitCode)
return fmt.Errorf("push returned rc: %d err: %v", resp.ExitCode, resp.Stderr)
}
return nil
}
4 changes: 4 additions & 0 deletions test/tests/workspace/contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ func runContextTests(t *testing.T, tests []ContextTest) {

// get actual from workspace
git := common.Git(rsa)
err = git.ConfigSafeDirectory(test.WorkspaceRoot)
if err != nil {
t.Fatal(err)
}
actBranch, err := git.GetBranch(test.WorkspaceRoot)
if err != nil {
t.Fatal(err)
Expand Down
10 changes: 8 additions & 2 deletions test/tests/workspace/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ func TestGitActions(t *testing.T) {
ContextURL: "github.com/gitpod-io/gitpod-test-repo/tree/integration-test/commit-and-push",
WorkspaceRoot: "/workspace/gitpod-test-repo",
Action: func(rsa *rpc.Client, git common.GitClient, workspaceRoot string) (err error) {

var resp agent.ExecResponse
err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{
Dir: workspaceRoot,
Expand All @@ -54,6 +53,10 @@ func TestGitActions(t *testing.T) {
if err != nil {
return err
}
err = git.ConfigSafeDirectory(workspaceRoot)
if err != nil {
return err
}
err = git.ConfigUserName(workspaceRoot)
if err != nil {
return err
Expand All @@ -79,7 +82,6 @@ func TestGitActions(t *testing.T) {
ContextURL: "github.com/gitpod-io/gitpod-test-repo/tree/integration-test/commit-and-push",
WorkspaceRoot: "/workspace/gitpod-test-repo",
Action: func(rsa *rpc.Client, git common.GitClient, workspaceRoot string) (err error) {

var resp agent.ExecResponse
err = rsa.Call("WorkspaceAgent.Exec", &agent.ExecRequest{
Dir: workspaceRoot,
Expand All @@ -92,6 +94,10 @@ func TestGitActions(t *testing.T) {
if err != nil {
return err
}
err = git.ConfigSafeDirectory(workspaceRoot)
if err != nil {
return err
}
err = git.ConfigUserName(workspaceRoot)
if err != nil {
return err
Expand Down