Skip to content

Commit 32e8d1b

Browse files
utam0kroboquat
authored andcommitted
content-service: Ignore git hooks when checkout
Signed-off-by: utam0k <[email protected]>
1 parent cee3c72 commit 32e8d1b

File tree

2 files changed

+32
-8
lines changed

2 files changed

+32
-8
lines changed

components/content-service/pkg/initializer/git.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,13 @@ func (ws *GitInitializer) realizeCloneTarget(ctx context.Context) (err error) {
198198
return err
199199
}
200200

201-
if err := ws.Git(ctx, "checkout", "-B", branchName, "origin/"+ws.CloneTarget); err != nil {
201+
if err := ws.Git(ctx, "-c", "core.hooksPath=/dev/null", "checkout", "-B", branchName, "origin/"+ws.CloneTarget); err != nil {
202202
log.WithError(err).WithField("remoteURI", ws.RemoteURI).WithField("branch", branchName).Error("Cannot fetch remote branch")
203203
return err
204204
}
205205
case LocalBranch:
206206
// checkout local branch based on remote HEAD
207-
if err := ws.Git(ctx, "checkout", "-B", ws.CloneTarget, "origin/HEAD", "--no-track"); err != nil {
207+
if err := ws.Git(ctx, "-c", "core.hooksPath=/dev/null", "checkout", "-B", ws.CloneTarget, "origin/HEAD", "--no-track"); err != nil {
208208
return err
209209
}
210210
case RemoteCommit:
@@ -216,7 +216,7 @@ func (ws *GitInitializer) realizeCloneTarget(ctx context.Context) (err error) {
216216
}
217217

218218
// checkout specific commit
219-
if err := ws.Git(ctx, "checkout", ws.CloneTarget); err != nil {
219+
if err := ws.Git(ctx, "-c", "core.hooksPath=/dev/null", "checkout", ws.CloneTarget); err != nil {
220220
return err
221221
}
222222
default:

test/tests/workspace/git_hooks_test.go

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,32 @@ import (
1313
"sigs.k8s.io/e2e-framework/pkg/envconf"
1414
"sigs.k8s.io/e2e-framework/pkg/features"
1515

16+
agent "github.com/gitpod-io/gitpod/test/pkg/agent/workspace/api"
1617
"github.com/gitpod-io/gitpod/test/pkg/integration"
1718
)
1819

19-
type GitHooksTest struct {
20+
const (
21+
FILE_CREATED_HOOKS = "output.txt"
22+
)
23+
24+
type GitHooksTestCase struct {
2025
Name string
2126
ContextURL string
2227
WorkspaceRoot string
2328
}
2429

25-
func GithuHooksTest(t *testing.T) {
30+
func TestGitHooks(t *testing.T) {
2631
userToken, _ := os.LookupEnv("USER_TOKEN")
2732
integration.SkipWithoutUsername(t, username)
2833
integration.SkipWithoutUserToken(t, userToken)
2934

3035
parallelLimiter := make(chan struct{}, 2)
3136

32-
tests := []GitHooksTest{
37+
tests := []GitHooksTestCase{
3338
{
3439
Name: "husky",
3540
ContextURL: "https://github.com/gitpod-io/gitpod-test-repo/tree/husky",
36-
WorkspaceRoot: "/workspace/template-golang-cli",
41+
WorkspaceRoot: "/workspace/gitpod-test-repo",
3742
},
3843
}
3944

@@ -90,7 +95,7 @@ func GithuHooksTest(t *testing.T) {
9095
api := integration.NewComponentAPI(ctx, cfg.Namespace(), kubeconfig, cfg.Client())
9196
defer api.Done(t)
9297

93-
_, stopWs, err := integration.LaunchWorkspaceFromContextURL(t, ctx, test.ContextURL, username, api)
98+
wsInfo, stopWs, err := integration.LaunchWorkspaceFromContextURL(t, ctx, test.ContextURL, username, api)
9499
if err != nil {
95100
t.Fatal(err)
96101
}
@@ -106,6 +111,25 @@ func GithuHooksTest(t *testing.T) {
106111
t.Fatal(err)
107112
}
108113
}()
114+
rsa, closer, err := integration.Instrument(integration.ComponentWorkspace, "workspace", cfg.Namespace(), kubeconfig, cfg.Client(), integration.WithInstanceID(wsInfo.LatestInstance.ID))
115+
if err != nil {
116+
t.Fatal(err)
117+
}
118+
defer rsa.Close()
119+
integration.DeferCloser(t, closer)
120+
121+
var ls agent.ListDirResponse
122+
err = rsa.Call("WorkspaceAgent.ListDir", &agent.ListDirRequest{
123+
Dir: test.WorkspaceRoot,
124+
}, &ls)
125+
if err != nil {
126+
t.Fatal(err)
127+
}
128+
for _, f := range ls.Files {
129+
if f == FILE_CREATED_HOOKS {
130+
t.Fatal("Checkout hooks are executed")
131+
}
132+
}
109133
})
110134
}
111135
}

0 commit comments

Comments
 (0)