MCPcopy Index your code
hub / github.com/rilldata/rill / setupTestRepository

Function setupTestRepository

cli/pkg/gitutil/gitcmdwrapper_test.go:488–545  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

486 require.Equal(t, p1, p2)
487}
488func setupTestRepository(t *testing.T) (string, string) {
489 tempDir := t.TempDir()
490
491 // Initialize a new git repository in the temp directory
492 cmd := exec.Command("git", "init", tempDir)
493 err := cmd.Run()
494 require.NoError(t, err, "failed to initialize git repository")
495 setupGitConfig(t, tempDir)
496
497 // Create a remote repository in another temp directory
498 remoteDir := t.TempDir()
499 cmd = exec.Command("git", "init", "--bare", remoteDir)
500 err = cmd.Run()
501 require.NoError(t, err, "failed to initialize remote git repository")
502
503 // Add the remote to the local repository
504 cmd = exec.Command("git", "-C", tempDir, "remote", "add", "origin", remoteDir)
505 err = cmd.Run()
506 require.NoError(t, err, "failed to add remote repository")
507
508 // Create and commit multiple files
509 for i := 1; i <= 3; i++ {
510 filePath := filepath.Join(tempDir, fmt.Sprintf("test%d.txt", i))
511 err = os.WriteFile(filePath, []byte(fmt.Sprintf("content of file %d", i)), 0644)
512 require.NoError(t, err, "failed to create test file")
513
514 cmd = exec.Command("git", "-C", tempDir, "add", fmt.Sprintf("test%d.txt", i))
515 err = cmd.Run()
516 require.NoError(t, err, "failed to stage file")
517 }
518
519 cmd = exec.Command("git", "-C", tempDir, "commit", "-m", "initial commit")
520 _, err = cmd.Output()
521 if err != nil {
522 var execErr *exec.ExitError
523 if errors.As(err, &execErr) {
524 require.NoError(t, err, "failed to commit files: "+fmt.Sprintf(": %s", execErr.Stderr))
525 }
526 require.NoError(t, err, "failed to commit files")
527 }
528
529 // Push the initial commit to the remote repository
530 cmd = exec.Command("git", "-C", tempDir, "push", "-u", "origin", "HEAD")
531 err = cmd.Run()
532 require.NoError(t, err, "failed to push initial commit")
533
534 // Run the RunGitStatus function
535 status, err := RunGitStatus(tempDir, "", "origin", "")
536 require.NoError(t, err, "RunGitStatus failed")
537
538 // Validate the status
539 require.Equal(t, int32(0), status.LocalCommits, "unexpected local commits")
540 require.Equal(t, remoteDir, status.RemoteURL, "unexpected remote URL")
541 require.False(t, status.LocalChanges, "unexpected local changes")
542 require.Equal(t, int32(0), status.RemoteCommits, "unexpected remote commits")
543
544 return tempDir, remoteDir
545}

Calls 4

RunGitStatusFunction · 0.85
setupGitConfigFunction · 0.70
TempDirMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected