Skip to content

Commit ad15590

Browse files
geroplona-agent
andauthored
[content-service] Fix git init default branch in tests (#21222)
* [content-service] Fix git init default branch in tests The tests were failing in CI because they depend on git's default branch configuration. The git client sets HOME=/home/gitpod where no .gitconfig exists, causing git to fall back to 'master' as the default branch. This fix explicitly sets --initial-branch=main for all git init calls in tests, making them deterministic regardless of the environment's git configuration. Co-authored-by: Ona <no-reply@ona.com> * [supervisor] Update test expectations for HISTFILE command The getCommand function now prepends a HISTFILE command for non-headless tasks to enable bash history. Updated test expectations to match the new output format. Co-authored-by: Ona <no-reply@ona.com> --------- Co-authored-by: Ona <no-reply@ona.com>
1 parent 46ae2f5 commit ad15590

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ func TestGitStatus(t *testing.T) {
3030
{
3131
"no commits",
3232
func(ctx context.Context, c *Client) error {
33-
if err := c.Git(ctx, "init"); err != nil {
33+
if err := c.Git(ctx, "init", "--initial-branch=main"); err != nil {
3434
return err
3535
}
3636
return nil
@@ -239,7 +239,7 @@ func TestGitStatusFromFiles(t *testing.T) {
239239
{
240240
"no commits",
241241
func(ctx context.Context, c *Client) error {
242-
if err := c.Git(ctx, "init"); err != nil {
242+
if err := c.Git(ctx, "init", "--initial-branch=main"); err != nil {
243243
return err
244244
}
245245
return nil
@@ -488,8 +488,9 @@ func newGitClient(ctx context.Context) (*Client, error) {
488488
return &Client{
489489
Location: loc,
490490
Config: map[string]string{
491-
"user.email": "foo@bar.com",
492-
"user.name": "tester",
491+
"user.email": "foo@bar.com",
492+
"user.name": "tester",
493+
"init.defaultBranch": "main",
493494
},
494495
}, nil
495496
}
@@ -499,7 +500,7 @@ func initFromRemote(ctx context.Context, c *Client) error {
499500
if err != nil {
500501
return xerrors.Errorf("cannot add remote: %w", err)
501502
}
502-
if err := remote.Git(ctx, "init"); err != nil {
503+
if err := remote.Git(ctx, "init", "--initial-branch=main"); err != nil {
503504
return err
504505
}
505506
if err := remote.Git(ctx, "config", "--local", "user.email", "foo@bar.com"); err != nil {

components/supervisor/pkg/supervisor/tasks_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,19 +280,19 @@ func TestGetTask(t *testing.T) {
280280
Name: "from prebuild",
281281
Task: allTasks,
282282
ContentSource: csapi.WorkspaceInitFromPrebuild,
283-
Expectation: "{\nbefore\n} && {\n[ -r /workspace/.prebuild-log-0 ] && cat /workspace/.prebuild-log-0; [ -r //prebuild-log-0 ] && cat //prebuild-log-0; true\n} && {\ncommand\n}",
283+
Expectation: " HISTFILE=//cmd-0 history -r; {\nbefore\n} && {\n[ -r /workspace/.prebuild-log-0 ] && cat /workspace/.prebuild-log-0; [ -r //prebuild-log-0 ] && cat //prebuild-log-0; true\n} && {\ncommand\n}",
284284
},
285285
{
286286
Name: "from other",
287287
Task: allTasks,
288288
ContentSource: csapi.WorkspaceInitFromOther,
289-
Expectation: "{\nbefore\n} && {\ninit\n} && {\ncommand\n}",
289+
Expectation: " HISTFILE=//cmd-0 history -r; {\nbefore\n} && {\ninit\n} && {\ncommand\n}",
290290
},
291291
{
292292
Name: "from backup",
293293
Task: allTasks,
294294
ContentSource: csapi.WorkspaceInitFromOther,
295-
Expectation: "{\nbefore\n} && {\ninit\n} && {\ncommand\n}",
295+
Expectation: " HISTFILE=//cmd-0 history -r; {\nbefore\n} && {\ninit\n} && {\ncommand\n}",
296296
},
297297
}
298298

0 commit comments

Comments
 (0)