From 18c57de405824fc45b5e2d8f9499455de659c00c Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 29 Apr 2025 06:16:26 +0000 Subject: [PATCH 01/23] refactor: enhance testCloneRepository function with git executable handling and temporary directory management --- internal/stage_clone_repository.go | 52 +++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/internal/stage_clone_repository.go b/internal/stage_clone_repository.go index a0cb9fa..fd55fca 100644 --- a/internal/stage_clone_repository.go +++ b/internal/stage_clone_repository.go @@ -2,7 +2,9 @@ package internal import ( "fmt" + "io" "os" + "os/exec" "path" "github.com/codecrafters-io/tester-utils/random" @@ -31,7 +33,7 @@ func (r TestRepo) randomFile() TestFile { return r.exampleFiles[random.RandomInt(0, len(r.exampleFiles))] } -var testRepos []TestRepo = []TestRepo{ +var testRepos = []TestRepo{ { url: "https://github.com/codecrafters-io/git-sample-1", exampleCommits: []string{ @@ -90,6 +92,54 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { testRepo := randomRepo() logger.Infof("$ ./%s clone %s ", path.Base(executable.Path), testRepo.url) + + gitPath, err := exec.LookPath("git") + if err != nil { + return fmt.Errorf("git executable not found: %v", err) + } + logger.Debugf("Found git executable at: %s", gitPath) + + gitDir, err := os.MkdirTemp("/tmp", "git-*") + if err != nil { + return err + } + logger.Debugf("Created temporary directory for git clone: %s", gitDir) + defer os.RemoveAll(gitDir) + + // Copy the custom_executable to the output path + command := fmt.Sprintf("cp %s %s", gitPath, gitDir) + logger.Debugf("Cp-ed git to temp directory: %s", gitDir) + //fmt.Println(command) + copyCmd := exec.Command("sh", "-c", command) + copyCmd.Stdout = io.Discard + copyCmd.Stderr = io.Discard + if err := copyCmd.Run(); err != nil { + return fmt.Errorf("CodeCrafters Internal Error: cp failed: %w", err) + } + + defer func() error { + // Copy the custom_executable to the output path + command := fmt.Sprintf("cp %s %s", gitDir, gitPath) + logger.Debugf("Cp-ed git to temp directory: %s", gitPath) + //fmt.Println(command) + copyCmd := exec.Command("sh", "-c", command) + copyCmd.Stdout = io.Discard + copyCmd.Stderr = io.Discard + + if err := copyCmd.Run(); err != nil { + return fmt.Errorf("CodeCrafters Internal Error: cp failed: %w", err) + } + + return nil + }() + + defer func() error { + if err := os.RemoveAll(gitDir); err != nil { + return fmt.Errorf("CodeCrafters Internal Error: delete directory failed: %s", gitDir) + } + return nil + }() + result, err := executable.Run("clone", testRepo.url, "test_dir") if err != nil { return err From 209fe0ab1281bd20822f60708b3a845eaad3cd94 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 29 Apr 2025 06:16:38 +0000 Subject: [PATCH 02/23] chore: add .idea and .devcontainer to .gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index ec0aa9e..50c4b5b 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,5 @@ dist __pycache__ vendor .history/ +.idea/ +.devcontainer/ \ No newline at end of file From 6aa90cefb6436260382f31dcd55fd012a27a28bd Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 29 Apr 2025 11:56:28 +0530 Subject: [PATCH 03/23] fix: replace cp command with mv in testCloneRepository for better file handling --- .github/workflows/test.yml | 1 + debug | 1 + internal/stage_clone_repository.go | 12 ++++++------ 3 files changed, 8 insertions(+), 6 deletions(-) create mode 160000 debug diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6242fc6..7a75094 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -17,3 +17,4 @@ jobs: with: python-version: '3.12' - run: make test + - run: make test_with_git diff --git a/debug b/debug new file mode 160000 index 0000000..72f5883 --- /dev/null +++ b/debug @@ -0,0 +1 @@ +Subproject commit 72f5883090a469173336debf5160727ed6025e34 diff --git a/internal/stage_clone_repository.go b/internal/stage_clone_repository.go index fd55fca..eb20a76 100644 --- a/internal/stage_clone_repository.go +++ b/internal/stage_clone_repository.go @@ -107,27 +107,27 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { defer os.RemoveAll(gitDir) // Copy the custom_executable to the output path - command := fmt.Sprintf("cp %s %s", gitPath, gitDir) - logger.Debugf("Cp-ed git to temp directory: %s", gitDir) + command := fmt.Sprintf("mv %s %s", gitPath, gitDir) + logger.Debugf("mv-ed git to temp directory: %s", gitDir) //fmt.Println(command) copyCmd := exec.Command("sh", "-c", command) copyCmd.Stdout = io.Discard copyCmd.Stderr = io.Discard if err := copyCmd.Run(); err != nil { - return fmt.Errorf("CodeCrafters Internal Error: cp failed: %w", err) + return fmt.Errorf("CodeCrafters Internal Error: mv failed: %w", err) } defer func() error { // Copy the custom_executable to the output path - command := fmt.Sprintf("cp %s %s", gitDir, gitPath) - logger.Debugf("Cp-ed git to temp directory: %s", gitPath) + command := fmt.Sprintf("mv %s %s", gitDir, gitPath) + logger.Debugf("mv-ed git to og directory: %s", gitPath) //fmt.Println(command) copyCmd := exec.Command("sh", "-c", command) copyCmd.Stdout = io.Discard copyCmd.Stderr = io.Discard if err := copyCmd.Run(); err != nil { - return fmt.Errorf("CodeCrafters Internal Error: cp failed: %w", err) + return fmt.Errorf("CodeCrafters Internal Error: mv failed: %w", err) } return nil From 90fee20a1ac74ef45431f15a5b21d6af362e277b Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 29 Apr 2025 12:02:15 +0530 Subject: [PATCH 04/23] refactor: improve testCloneRepository by updating git executable handling and temporary directory usage --- internal/stage_clone_repository.go | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/internal/stage_clone_repository.go b/internal/stage_clone_repository.go index eb20a76..631cca1 100644 --- a/internal/stage_clone_repository.go +++ b/internal/stage_clone_repository.go @@ -93,22 +93,24 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { logger.Infof("$ ./%s clone %s ", path.Base(executable.Path), testRepo.url) - gitPath, err := exec.LookPath("git") + oldGitPath, err := exec.LookPath("git") if err != nil { return fmt.Errorf("git executable not found: %v", err) } - logger.Debugf("Found git executable at: %s", gitPath) + oldGitDir := path.Dir(oldGitPath) + logger.Debugf("Found git executable at: %s", oldGitPath) - gitDir, err := os.MkdirTemp("/tmp", "git-*") + tmpGitDir, err := os.MkdirTemp("/tmp", "git-*") if err != nil { return err } - logger.Debugf("Created temporary directory for git clone: %s", gitDir) - defer os.RemoveAll(gitDir) + logger.Debugf("Created temporary directory for git clone: %s", tmpGitDir) + tmpGitPath := path.Join(tmpGitDir, "git") + defer os.RemoveAll(tmpGitDir) // Copy the custom_executable to the output path - command := fmt.Sprintf("mv %s %s", gitPath, gitDir) - logger.Debugf("mv-ed git to temp directory: %s", gitDir) + command := fmt.Sprintf("mv %s %s", oldGitPath, tmpGitDir) + logger.Debugf("mv-ed git to temp directory: %s", tmpGitDir) //fmt.Println(command) copyCmd := exec.Command("sh", "-c", command) copyCmd.Stdout = io.Discard @@ -119,8 +121,8 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { defer func() error { // Copy the custom_executable to the output path - command := fmt.Sprintf("mv %s %s", gitDir, gitPath) - logger.Debugf("mv-ed git to og directory: %s", gitPath) + command := fmt.Sprintf("mv %s %s", tmpGitPath, oldGitDir) + logger.Debugf("mv-ed git to og directory: %s", oldGitDir) //fmt.Println(command) copyCmd := exec.Command("sh", "-c", command) copyCmd.Stdout = io.Discard @@ -134,8 +136,8 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { }() defer func() error { - if err := os.RemoveAll(gitDir); err != nil { - return fmt.Errorf("CodeCrafters Internal Error: delete directory failed: %s", gitDir) + if err := os.RemoveAll(tmpGitDir); err != nil { + return fmt.Errorf("CodeCrafters Internal Error: delete directory failed: %s", tmpGitDir) } return nil }() From 7eb2f2493b03277ed2269ee28057d97d9c0d2b14 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 29 Apr 2025 12:04:35 +0530 Subject: [PATCH 05/23] chore: set global git user configuration in your_git.sh --- internal/test_helpers/pass_all/your_git.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/internal/test_helpers/pass_all/your_git.sh b/internal/test_helpers/pass_all/your_git.sh index d7d4c22..f740d33 100755 --- a/internal/test_helpers/pass_all/your_git.sh +++ b/internal/test_helpers/pass_all/your_git.sh @@ -1,5 +1,8 @@ #!/bin/sh +git config --global user.email "you@example.com" +git config --global user.name "Your Name" + if [ "$1" = "write-tree" ] then git add . From b1c5d9e5b93e398f44bc007c0d91d2b7e0bde0f2 Mon Sep 17 00:00:00 2001 From: Ryan Gang Date: Tue, 29 Apr 2025 12:06:19 +0530 Subject: [PATCH 06/23] chore: set default branch name to 'main' in your_git.sh --- internal/test_helpers/pass_all/your_git.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/test_helpers/pass_all/your_git.sh b/internal/test_helpers/pass_all/your_git.sh index f740d33..59758cb 100755 --- a/internal/test_helpers/pass_all/your_git.sh +++ b/internal/test_helpers/pass_all/your_git.sh @@ -2,6 +2,7 @@ git config --global user.email "you@example.com" git config --global user.name "Your Name" +git config --global init.defaultBranch "main" if [ "$1" = "write-tree" ] then From 8a0a2a14e58fa6abe6ec444a2da6d90a09862d73 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 29 Apr 2025 06:38:07 +0000 Subject: [PATCH 07/23] fix: improve logging for git executable movement in testCloneRepository --- internal/stage_clone_repository.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/internal/stage_clone_repository.go b/internal/stage_clone_repository.go index 631cca1..bcde5da 100644 --- a/internal/stage_clone_repository.go +++ b/internal/stage_clone_repository.go @@ -110,27 +110,24 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { // Copy the custom_executable to the output path command := fmt.Sprintf("mv %s %s", oldGitPath, tmpGitDir) - logger.Debugf("mv-ed git to temp directory: %s", tmpGitDir) - //fmt.Println(command) copyCmd := exec.Command("sh", "-c", command) copyCmd.Stdout = io.Discard copyCmd.Stderr = io.Discard if err := copyCmd.Run(); err != nil { return fmt.Errorf("CodeCrafters Internal Error: mv failed: %w", err) } + logger.Debugf("mv-ed git to temp directory: %s", tmpGitDir) defer func() error { // Copy the custom_executable to the output path command := fmt.Sprintf("mv %s %s", tmpGitPath, oldGitDir) - logger.Debugf("mv-ed git to og directory: %s", oldGitDir) - //fmt.Println(command) copyCmd := exec.Command("sh", "-c", command) copyCmd.Stdout = io.Discard copyCmd.Stderr = io.Discard - if err := copyCmd.Run(); err != nil { return fmt.Errorf("CodeCrafters Internal Error: mv failed: %w", err) } + logger.Debugf("mv-ed git to og directory: %s", oldGitDir) return nil }() From ce98ee6508d80c294a4e74c2599446347c5251a6 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 08:22:10 +0000 Subject: [PATCH 08/23] fix: remove unused debug subproject reference --- debug | 1 - 1 file changed, 1 deletion(-) delete mode 160000 debug diff --git a/debug b/debug deleted file mode 160000 index 72f5883..0000000 --- a/debug +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 72f5883090a469173336debf5160727ed6025e34 From 448311b35bd84d29a351e4df957b01e75c4b8514 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 20 May 2025 09:14:41 +0000 Subject: [PATCH 09/23] fix: update git executable handling in testCloneRepository to use sudo and improve logging --- internal/stage_clone_repository.go | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/internal/stage_clone_repository.go b/internal/stage_clone_repository.go index bcde5da..91512ef 100644 --- a/internal/stage_clone_repository.go +++ b/internal/stage_clone_repository.go @@ -109,23 +109,25 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { defer os.RemoveAll(tmpGitDir) // Copy the custom_executable to the output path - command := fmt.Sprintf("mv %s %s", oldGitPath, tmpGitDir) + command := fmt.Sprintf("sudo mv %s %s", oldGitPath, tmpGitDir) + fmt.Println(command) copyCmd := exec.Command("sh", "-c", command) - copyCmd.Stdout = io.Discard - copyCmd.Stderr = io.Discard + copyCmd.Stdout = os.Stdout + copyCmd.Stderr = os.Stderr if err := copyCmd.Run(); err != nil { - return fmt.Errorf("CodeCrafters Internal Error: mv failed: %w", err) + return fmt.Errorf("CodeCrafters Internal Error: mv1 failed: %w", err) } logger.Debugf("mv-ed git to temp directory: %s", tmpGitDir) defer func() error { // Copy the custom_executable to the output path - command := fmt.Sprintf("mv %s %s", tmpGitPath, oldGitDir) + command := fmt.Sprintf("sudo mv %s %s", tmpGitPath, oldGitDir) + fmt.Println(command) copyCmd := exec.Command("sh", "-c", command) copyCmd.Stdout = io.Discard copyCmd.Stderr = io.Discard if err := copyCmd.Run(); err != nil { - return fmt.Errorf("CodeCrafters Internal Error: mv failed: %w", err) + return fmt.Errorf("CodeCrafters Internal Error: mv2 failed: %w", err) } logger.Debugf("mv-ed git to og directory: %s", oldGitDir) @@ -133,9 +135,10 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { }() defer func() error { - if err := os.RemoveAll(tmpGitDir); err != nil { - return fmt.Errorf("CodeCrafters Internal Error: delete directory failed: %s", tmpGitDir) - } + fmt.Println(tmpGitDir) + // if err := os.RemoveAll(tmpGitDir); err != nil { + // return fmt.Errorf("CodeCrafters Internal Error: delete directory failed: %s", tmpGitDir) + // } return nil }() From 366d42e02dc516337d6cb261c609f0912d6d9eb5 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 20 May 2025 09:20:50 +0000 Subject: [PATCH 10/23] fix: ensure temporary git directory is removed after cloning --- internal/stage_clone_repository.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/internal/stage_clone_repository.go b/internal/stage_clone_repository.go index 91512ef..6beaa9f 100644 --- a/internal/stage_clone_repository.go +++ b/internal/stage_clone_repository.go @@ -131,14 +131,9 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { } logger.Debugf("mv-ed git to og directory: %s", oldGitDir) - return nil - }() - - defer func() error { - fmt.Println(tmpGitDir) - // if err := os.RemoveAll(tmpGitDir); err != nil { - // return fmt.Errorf("CodeCrafters Internal Error: delete directory failed: %s", tmpGitDir) - // } + if err := os.RemoveAll(tmpGitDir); err != nil { + return fmt.Errorf("CodeCrafters Internal Error: delete directory failed: %s", tmpGitDir) + } return nil }() From 6754885c0aabfa275a8511276f8d9154edd775db Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 09:38:33 +0000 Subject: [PATCH 11/23] fix: improve logging in testCloneRepository and clean up deferred function --- internal/stage_clone_repository.go | 38 ++++++++++++++++-------------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/internal/stage_clone_repository.go b/internal/stage_clone_repository.go index 6beaa9f..d299fbd 100644 --- a/internal/stage_clone_repository.go +++ b/internal/stage_clone_repository.go @@ -110,7 +110,7 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { // Copy the custom_executable to the output path command := fmt.Sprintf("sudo mv %s %s", oldGitPath, tmpGitDir) - fmt.Println(command) + logger.Debugf(command) copyCmd := exec.Command("sh", "-c", command) copyCmd.Stdout = os.Stdout copyCmd.Stderr = os.Stderr @@ -119,23 +119,7 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { } logger.Debugf("mv-ed git to temp directory: %s", tmpGitDir) - defer func() error { - // Copy the custom_executable to the output path - command := fmt.Sprintf("sudo mv %s %s", tmpGitPath, oldGitDir) - fmt.Println(command) - copyCmd := exec.Command("sh", "-c", command) - copyCmd.Stdout = io.Discard - copyCmd.Stderr = io.Discard - if err := copyCmd.Run(); err != nil { - return fmt.Errorf("CodeCrafters Internal Error: mv2 failed: %w", err) - } - logger.Debugf("mv-ed git to og directory: %s", oldGitDir) - - if err := os.RemoveAll(tmpGitDir); err != nil { - return fmt.Errorf("CodeCrafters Internal Error: delete directory failed: %s", tmpGitDir) - } - return nil - }() + logger.Infof("$ git clone %s %s", testRepo.url, "test_dir") result, err := executable.Run("clone", testRepo.url, "test_dir") if err != nil { @@ -183,5 +167,23 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { } logger.Successf("File contents verified") + defer func() error { + // Copy the custom_executable to the output path + command := fmt.Sprintf("sudo mv %s %s", tmpGitPath, oldGitDir) + logger.Debugf(command) + copyCmd := exec.Command("sh", "-c", command) + copyCmd.Stdout = io.Discard + copyCmd.Stderr = io.Discard + if err := copyCmd.Run(); err != nil { + return fmt.Errorf("CodeCrafters Internal Error: mv2 failed: %w", err) + } + logger.Debugf("mv-ed git to og directory: %s", oldGitDir) + + if err := os.RemoveAll(tmpGitDir); err != nil { + return fmt.Errorf("CodeCrafters Internal Error: delete directory failed: %s", tmpGitDir) + } + return nil + }() + return nil } From 53180181f9498c50cf5eb6bd0580cc113cbdf1eb Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 09:38:39 +0000 Subject: [PATCH 12/23] fix: add logging for git command location in testCloneRepository --- internal/stage_clone_repository.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/internal/stage_clone_repository.go b/internal/stage_clone_repository.go index d299fbd..8a8ef96 100644 --- a/internal/stage_clone_repository.go +++ b/internal/stage_clone_repository.go @@ -121,6 +121,17 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { logger.Infof("$ git clone %s %s", testRepo.url, "test_dir") + //////// which git + command = fmt.Sprint("which git") + logger.Debugf(command) + cmd := exec.Command("sh", "-c", command) + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + if err := cmd.Run(); err != nil { + return fmt.Errorf("CodeCrafters Internal Error: mv1 failed: %w", err) + } + logger.Debugf("mv-ed git to temp directory: %s", tmpGitDir) + result, err := executable.Run("clone", testRepo.url, "test_dir") if err != nil { return err From f8ae2ff73894ccc6f32b79c740caee827417e950 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 09:40:42 +0000 Subject: [PATCH 13/23] fix: comment out unused git command execution in testCloneRepository --- internal/stage_clone_repository.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/internal/stage_clone_repository.go b/internal/stage_clone_repository.go index 8a8ef96..11a3725 100644 --- a/internal/stage_clone_repository.go +++ b/internal/stage_clone_repository.go @@ -122,15 +122,15 @@ func testCloneRepository(harness *test_case_harness.TestCaseHarness) error { logger.Infof("$ git clone %s %s", testRepo.url, "test_dir") //////// which git - command = fmt.Sprint("which git") - logger.Debugf(command) - cmd := exec.Command("sh", "-c", command) - cmd.Stdout = os.Stdout - cmd.Stderr = os.Stderr - if err := cmd.Run(); err != nil { - return fmt.Errorf("CodeCrafters Internal Error: mv1 failed: %w", err) - } - logger.Debugf("mv-ed git to temp directory: %s", tmpGitDir) + // command = fmt.Sprint("which git") + // logger.Debugf(command) + // cmd := exec.Command("sh", "-c", command) + // cmd.Stdout = os.Stdout + // cmd.Stderr = os.Stderr + // if err := cmd.Run(); err != nil { + // return fmt.Errorf("CodeCrafters Internal Error: mv1 failed: %w", err) + // } + // logger.Debugf("mv-ed git to temp directory: %s", tmpGitDir) result, err := executable.Run("clone", testRepo.url, "test_dir") if err != nil { From eccd92279d3f6ac8106265ac1538a1d6e9579b65 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 10:42:13 +0000 Subject: [PATCH 14/23] feat: add support for Rust and Python setup in GitHub Actions workflow; create configuration and script for cloning --- .github/workflows/test.yml | 4 ++++ Makefile | 7 ++++++- internal/test_helpers/clone/codecrafters.yml | 11 +++++++++++ internal/test_helpers/clone/your_git.sh | 8 ++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 internal/test_helpers/clone/codecrafters.yml create mode 100755 internal/test_helpers/clone/your_git.sh diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7a75094..885bc29 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -12,9 +12,13 @@ jobs: uses: actions/setup-go@v5 with: go-version: 1.24.x + - name: Set up Rust + uses: actions-rust-lang/setup-rust-toolchain@v1 - name: Set up Python uses: actions/setup-python@v5 with: python-version: '3.12' + - run: cargo install cargo-binstall + - run: cargo binstall gitoxide - run: make test - run: make test_with_git diff --git a/Makefile b/Makefile index 28950c9..f7303df 100644 --- a/Makefile +++ b/Makefile @@ -15,7 +15,12 @@ test: test_with_git: build CODECRAFTERS_REPOSITORY_DIR=$(shell pwd)/internal/test_helpers/pass_all \ - CODECRAFTERS_TEST_CASES_JSON='[{"slug":"gg4","tester_log_prefix":"stage-1","title":"Stage #1: Initialize the .git directory"},{"slug":"ic4","tester_log_prefix":"stage-2","title":"Stage #2: Read a blob object"},{"slug":"jt4","tester_log_prefix":"stage-3","title":"Stage #3: Create a blob object"},{"slug":"kp1","tester_log_prefix":"stage-4","title":"Stage #4: Read a tree object"},{"slug":"fe4","tester_log_prefix":"stage-5","title":"Stage #5: Write a tree object"},{"slug":"jm9","tester_log_prefix":"stage-6","title":"Stage #6: Create a commit"},{"slug":"mg6","tester_log_prefix":"stage-7","title":"Stage #7: Clone a repository"}]' \ + CODECRAFTERS_TEST_CASES_JSON='[{"slug":"gg4","tester_log_prefix":"stage-1","title":"Stage #1: Initialize the .git directory"},{"slug":"ic4","tester_log_prefix":"stage-2","title":"Stage #2: Read a blob object"},{"slug":"jt4","tester_log_prefix":"stage-3","title":"Stage #3: Create a blob object"},{"slug":"kp1","tester_log_prefix":"stage-4","title":"Stage #4: Read a tree object"},{"slug":"fe4","tester_log_prefix":"stage-5","title":"Stage #5: Write a tree object"},{"slug":"jm9","tester_log_prefix":"stage-6","title":"Stage #6: Create a commit"}]' \ + $(shell pwd)/dist/main.out + +test_with_gix: build + CODECRAFTERS_REPOSITORY_DIR=$(shell pwd)/internal/test_helpers/clone \ + CODECRAFTERS_TEST_CASES_JSON='[{"slug":"mg6","tester_log_prefix":"stage-7","title":"Stage #7: Clone a repository"}]' \ $(shell pwd)/dist/main.out copy_course_file: diff --git a/internal/test_helpers/clone/codecrafters.yml b/internal/test_helpers/clone/codecrafters.yml new file mode 100644 index 0000000..533cd7a --- /dev/null +++ b/internal/test_helpers/clone/codecrafters.yml @@ -0,0 +1,11 @@ +# This is the current stage that you're on. +# +# Whenever you want to advance to the next stage, +# bump this to the next number. +current_stage: 1 + +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: true diff --git a/internal/test_helpers/clone/your_git.sh b/internal/test_helpers/clone/your_git.sh new file mode 100755 index 0000000..2d834a3 --- /dev/null +++ b/internal/test_helpers/clone/your_git.sh @@ -0,0 +1,8 @@ +#!/bin/sh + +if [ "$1" = "cat-file" ] +then + gix cat "@$" +fi + +exec gix "$@" From 88b1597180dcd3f37998418b3045b82c5edc0bf2 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 10:42:18 +0000 Subject: [PATCH 15/23] fix: comment out git configuration commands in your_git.sh --- internal/test_helpers/pass_all/your_git.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/test_helpers/pass_all/your_git.sh b/internal/test_helpers/pass_all/your_git.sh index 59758cb..11f74bd 100755 --- a/internal/test_helpers/pass_all/your_git.sh +++ b/internal/test_helpers/pass_all/your_git.sh @@ -1,8 +1,7 @@ #!/bin/sh - -git config --global user.email "you@example.com" -git config --global user.name "Your Name" -git config --global init.defaultBranch "main" +# git config --global user.email "you@example.com" +# git config --global user.name "Your Name" +# git config --global init.defaultBranch "main" if [ "$1" = "write-tree" ] then From 07a50d64510cd9e6620dbd71ca13fe6d5dc06eee Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 10:46:56 +0000 Subject: [PATCH 16/23] fix: uncomment git configuration commands in your_git.sh --- internal/test_helpers/pass_all/your_git.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/test_helpers/pass_all/your_git.sh b/internal/test_helpers/pass_all/your_git.sh index 11f74bd..59758cb 100755 --- a/internal/test_helpers/pass_all/your_git.sh +++ b/internal/test_helpers/pass_all/your_git.sh @@ -1,7 +1,8 @@ #!/bin/sh -# git config --global user.email "you@example.com" -# git config --global user.name "Your Name" -# git config --global init.defaultBranch "main" + +git config --global user.email "you@example.com" +git config --global user.name "Your Name" +git config --global init.defaultBranch "main" if [ "$1" = "write-tree" ] then From 87a489c313269505e9eb5b11345a661753a2ed41 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 10:47:16 +0000 Subject: [PATCH 17/23] feat: add test_with_gix step to GitHub Actions workflow --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 885bc29..9ae9dca 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -21,4 +21,5 @@ jobs: - run: cargo install cargo-binstall - run: cargo binstall gitoxide - run: make test + - run: make test_with_gix - run: make test_with_git From 5f9d8fc9222e03fca53750dfdc1cd2434093aee9 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 10:56:41 +0000 Subject: [PATCH 18/23] fix: add export PATH command for cargo binaries in GitHub Actions workflow --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9ae9dca..2281d79 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,6 +20,7 @@ jobs: python-version: '3.12' - run: cargo install cargo-binstall - run: cargo binstall gitoxide + - run: export PATH="$HOME/.cargo/bin:$PATH" - run: make test - run: make test_with_gix - run: make test_with_git From 6d68173184a54eb0b350f82328c2d21cbaed8f21 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 10:59:56 +0000 Subject: [PATCH 19/23] fix: update PATH handling for cargo binaries in GitHub Actions workflow --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2281d79..4f3aced 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -20,7 +20,7 @@ jobs: python-version: '3.12' - run: cargo install cargo-binstall - run: cargo binstall gitoxide - - run: export PATH="$HOME/.cargo/bin:$PATH" + - run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH - run: make test - run: make test_with_gix - run: make test_with_git From 1a8c8b7c49e2398e2afa235d5c6a6cf0fbda09fb Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 11:01:19 +0000 Subject: [PATCH 20/23] fix: add --force flag to cargo binstall for gitoxide --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4f3aced..378ea53 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,7 +19,7 @@ jobs: with: python-version: '3.12' - run: cargo install cargo-binstall - - run: cargo binstall gitoxide + - run: cargo binstall gitoxide --force - run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH - run: make test - run: make test_with_gix From 06a97327ff931438a992aba41bc749073b57d5e5 Mon Sep 17 00:00:00 2001 From: Ryan Date: Tue, 20 May 2025 11:02:52 +0000 Subject: [PATCH 21/23] fix: uncomment cargo binstall command for gitoxide in GitHub Actions workflow --- .github/workflows/test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 378ea53..d203943 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -19,8 +19,8 @@ jobs: with: python-version: '3.12' - run: cargo install cargo-binstall - - run: cargo binstall gitoxide --force - - run: echo "$HOME/.cargo/bin" >> $GITHUB_PATH + # This sets up the binaries required for gix. + - run: cargo binstall gitoxide --force - run: make test - run: make test_with_gix - run: make test_with_git From 46be12b7142850ea3751b3197bc3e896839469f9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 20 May 2025 18:44:37 +0000 Subject: [PATCH 22/23] fix: add init command handling in your_git.sh script --- internal/test_helpers/clone/your_git.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/internal/test_helpers/clone/your_git.sh b/internal/test_helpers/clone/your_git.sh index 2d834a3..b187125 100755 --- a/internal/test_helpers/clone/your_git.sh +++ b/internal/test_helpers/clone/your_git.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [ "$1" = "init" ] +then + ein init "@$" +fi + if [ "$1" = "cat-file" ] then gix cat "@$" From 9d4381000ec967613fd55ac8c695d1c068336cfb Mon Sep 17 00:00:00 2001 From: Ryan Date: Mon, 23 Jun 2025 21:47:14 +0530 Subject: [PATCH 23/23] wip: add tmp config change --- internal/test_helpers/pass_all/your_git.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/internal/test_helpers/pass_all/your_git.sh b/internal/test_helpers/pass_all/your_git.sh index 59758cb..8ab55fb 100755 --- a/internal/test_helpers/pass_all/your_git.sh +++ b/internal/test_helpers/pass_all/your_git.sh @@ -1,12 +1,12 @@ #!/bin/sh -git config --global user.email "you@example.com" -git config --global user.name "Your Name" -git config --global init.defaultBranch "main" +/tmp/test_helpers/git config --global user.email "you@example.com" +/tmp/test_helpers/git config --global user.name "Your Name" +/tmp/test_helpers/git config --global init.defaultBranch "main" if [ "$1" = "write-tree" ] then - git add . + /tmp/test_helpers/git add . fi -exec git "$@" +exec /tmp/test_helpers/git "$@"