├── .github
└── workflows
│ ├── post-diffs-in-pr.yml
│ ├── test-git-is-unavailable.yml
│ └── test.yml
├── .gitignore
├── LICENSE
├── Makefile
├── README.md
├── compiled_starters
├── c
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── README.md
│ ├── codecrafters.yml
│ ├── src
│ │ └── main.c
│ ├── vcpkg-configuration.json
│ ├── vcpkg.json
│ └── your_program.sh
├── cpp
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── README.md
│ ├── codecrafters.yml
│ ├── src
│ │ └── main.cpp
│ ├── vcpkg-configuration.json
│ ├── vcpkg.json
│ └── your_program.sh
├── csharp
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── README.md
│ ├── codecrafters-git.csproj
│ ├── codecrafters-git.sln
│ ├── codecrafters.yml
│ ├── src
│ │ └── Program.cs
│ └── your_program.sh
├── go
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── README.md
│ ├── app
│ │ └── main.go
│ ├── codecrafters.yml
│ ├── go.mod
│ ├── go.sum
│ └── your_program.sh
├── haskell
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── README.md
│ ├── app
│ │ └── Main.hs
│ ├── codecrafters.yml
│ ├── package.yaml
│ ├── stack.yaml
│ ├── stack.yaml.lock
│ ├── your_git.sh
│ └── your_program.sh
├── java
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── README.md
│ ├── codecrafters.yml
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ │ └── java
│ │ │ └── Main.java
│ └── your_program.sh
├── javascript
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── README.md
│ ├── app
│ │ └── main.js
│ ├── codecrafters.yml
│ ├── package-lock.json
│ ├── package.json
│ └── your_program.sh
├── kotlin
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── README.md
│ ├── codecrafters.yml
│ ├── pom.xml
│ ├── src
│ │ └── main
│ │ │ └── kotlin
│ │ │ └── Main.kt
│ └── your_program.sh
├── python
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── README.md
│ ├── app
│ │ └── main.py
│ ├── codecrafters.yml
│ └── your_program.sh
├── ruby
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── Gemfile
│ ├── Gemfile.lock
│ ├── README.md
│ ├── app
│ │ └── main.rb
│ ├── codecrafters.yml
│ └── your_program.sh
├── rust
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── Cargo.lock
│ ├── Cargo.toml
│ ├── README.md
│ ├── codecrafters.yml
│ ├── src
│ │ └── main.rs
│ └── your_program.sh
├── typescript
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── README.md
│ ├── app
│ │ └── main.ts
│ ├── bun.lockb
│ ├── codecrafters.yml
│ ├── package.json
│ ├── tsconfig.json
│ └── your_program.sh
└── zig
│ ├── .codecrafters
│ ├── compile.sh
│ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── README.md
│ ├── build.zig
│ ├── build.zig.zon
│ ├── codecrafters.yml
│ ├── src
│ └── main.zig
│ └── your_program.sh
├── course-definition.yml
├── dockerfiles
├── bun-1.1.Dockerfile
├── bun-1.2.Dockerfile
├── c-23.Dockerfile
├── cpp-20.Dockerfile
├── cpp-23.Dockerfile
├── dotnet-8.0.Dockerfile
├── dotnet-9.0.Dockerfile
├── go-1.13.Dockerfile
├── go-1.16.Dockerfile
├── go-1.19.Dockerfile
├── go-1.21.Dockerfile
├── go-1.22.Dockerfile
├── go-1.24.Dockerfile
├── haskell-9.4.Dockerfile
├── haskell-9.8.Dockerfile
├── java-21.Dockerfile
├── java-23.Dockerfile
├── kotlin-1.3.72.Dockerfile
├── kotlin-1.4.Dockerfile
├── kotlin-2.0.Dockerfile
├── nodejs-18.Dockerfile
├── nodejs-21.Dockerfile
├── python-3.11.Dockerfile
├── python-3.12.Dockerfile
├── python-3.13.Dockerfile
├── python-3.7.Dockerfile
├── python-3.8.Dockerfile
├── ruby-2.7.Dockerfile
├── ruby-3.2.Dockerfile
├── ruby-3.3.Dockerfile
├── rust-1.62.Dockerfile
├── rust-1.68.Dockerfile
├── rust-1.70.Dockerfile
├── rust-1.76.Dockerfile
├── rust-1.77.Dockerfile
├── rust-1.80.Dockerfile
├── rust-1.82.Dockerfile
├── rust-1.85.Dockerfile
├── rust-1.86.Dockerfile
├── zig-0.12.Dockerfile
└── zig-0.14.Dockerfile
├── scripts
└── check_git_is_unavailable.sh
├── solutions
├── c
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── .gitignore
│ │ ├── CMakeLists.txt
│ │ ├── README.md
│ │ ├── codecrafters.yml
│ │ ├── src
│ │ │ └── main.c
│ │ ├── vcpkg-configuration.json
│ │ ├── vcpkg.json
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── src
│ │ │ └── main.c.diff
│ │ └── explanation.md
├── cpp
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── .gitignore
│ │ ├── CMakeLists.txt
│ │ ├── README.md
│ │ ├── codecrafters.yml
│ │ ├── src
│ │ │ └── main.cpp
│ │ ├── vcpkg-configuration.json
│ │ ├── vcpkg.json
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── src
│ │ │ └── main.cpp.diff
│ │ └── explanation.md
├── csharp
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── codecrafters-git.csproj
│ │ ├── codecrafters-git.sln
│ │ ├── codecrafters.yml
│ │ ├── src
│ │ │ └── Program.cs
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── src
│ │ │ └── Program.cs.diff
│ │ └── explanation.md
├── go
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── README.md
│ │ ├── app
│ │ │ └── main.go
│ │ ├── codecrafters.yml
│ │ ├── go.mod
│ │ ├── go.sum
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── app
│ │ │ └── main.go.diff
│ │ └── explanation.md
├── haskell
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── app
│ │ │ └── Main.hs
│ │ ├── codecrafters.yml
│ │ ├── package.yaml
│ │ ├── stack.yaml
│ │ ├── stack.yaml.lock
│ │ ├── your_git.sh
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── app
│ │ │ └── Main.hs.diff
│ │ └── explanation.md
├── java
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── codecrafters.yml
│ │ ├── pom.xml
│ │ ├── src
│ │ │ └── main
│ │ │ │ └── java
│ │ │ │ └── Main.java
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── src
│ │ │ └── main
│ │ │ └── java
│ │ │ └── Main.java.diff
│ │ └── explanation.md
├── javascript
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── app
│ │ │ └── main.js
│ │ ├── codecrafters.yml
│ │ ├── package-lock.json
│ │ ├── package.json
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── app
│ │ │ └── main.js.diff
│ │ └── explanation.md
├── kotlin
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── codecrafters.yml
│ │ ├── pom.xml
│ │ ├── src
│ │ │ └── main
│ │ │ │ └── kotlin
│ │ │ │ └── Main.kt
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── src
│ │ │ └── main
│ │ │ └── kotlin
│ │ │ └── Main.kt.diff
│ │ └── explanation.md
├── python
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── app
│ │ │ └── main.py
│ │ ├── codecrafters.yml
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── app
│ │ │ └── main.py.diff
│ │ └── explanation.md
├── ruby
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── Gemfile
│ │ ├── Gemfile.lock
│ │ ├── README.md
│ │ ├── app
│ │ │ └── main.rb
│ │ ├── codecrafters.yml
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── app
│ │ │ └── main.rb.diff
│ │ └── explanation.md
├── rust
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── .gitignore
│ │ ├── Cargo.lock
│ │ ├── Cargo.toml
│ │ ├── README.md
│ │ ├── codecrafters.yml
│ │ ├── src
│ │ │ └── main.rs
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── src
│ │ │ └── main.rs.diff
│ │ └── explanation.md
├── typescript
│ └── 01-gg4
│ │ ├── code
│ │ ├── .codecrafters
│ │ │ ├── compile.sh
│ │ │ └── run.sh
│ │ ├── .gitattributes
│ │ ├── .gitignore
│ │ ├── README.md
│ │ ├── app
│ │ │ └── main.ts
│ │ ├── bun.lockb
│ │ ├── codecrafters.yml
│ │ ├── package.json
│ │ ├── tsconfig.json
│ │ └── your_program.sh
│ │ ├── diff
│ │ └── app
│ │ │ └── main.ts.diff
│ │ └── explanation.md
└── zig
│ └── 01-gg4
│ ├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitattributes
│ ├── .gitignore
│ ├── README.md
│ ├── build.zig
│ ├── build.zig.zon
│ ├── codecrafters.yml
│ ├── src
│ │ └── main.zig
│ └── your_program.sh
│ ├── diff
│ └── src
│ │ └── main.zig.diff
│ └── explanation.md
└── starter_templates
├── all
└── code
│ ├── .gitattributes
│ ├── README.md
│ └── codecrafters.yml
├── c
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── src
│ │ └── main.c
│ ├── vcpkg-configuration.json
│ └── vcpkg.json
└── config.yml
├── cpp
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitignore
│ ├── CMakeLists.txt
│ ├── src
│ │ └── main.cpp
│ ├── vcpkg-configuration.json
│ └── vcpkg.json
└── config.yml
├── csharp
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitignore
│ ├── codecrafters-git.csproj
│ ├── codecrafters-git.sln
│ └── src
│ │ └── Program.cs
└── config.yml
├── go
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── app
│ │ └── main.go
│ ├── go.mod
│ └── go.sum
└── config.yml
├── haskell
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitignore
│ ├── app
│ │ └── Main.hs
│ ├── package.yaml
│ ├── stack.yaml
│ ├── stack.yaml.lock
│ └── your_git.sh
└── config.yml
├── java
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── java
│ │ └── Main.java
└── config.yml
├── javascript
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitignore
│ ├── app
│ │ └── main.js
│ ├── package-lock.json
│ └── package.json
└── config.yml
├── kotlin
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitignore
│ ├── pom.xml
│ └── src
│ │ └── main
│ │ └── kotlin
│ │ └── Main.kt
└── config.yml
├── python
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitignore
│ └── app
│ │ └── main.py
└── config.yml
├── ruby
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── Gemfile
│ ├── Gemfile.lock
│ └── app
│ │ └── main.rb
└── config.yml
├── rust
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitignore
│ ├── Cargo.lock
│ ├── Cargo.toml
│ └── src
│ │ └── main.rs
└── config.yml
├── typescript
├── code
│ ├── .codecrafters
│ │ ├── compile.sh
│ │ └── run.sh
│ ├── .gitignore
│ ├── app
│ │ └── main.ts
│ ├── bun.lockb
│ ├── package.json
│ └── tsconfig.json
└── config.yml
└── zig
├── code
├── .codecrafters
│ ├── compile.sh
│ └── run.sh
├── .gitignore
├── build.zig
├── build.zig.zon
└── src
│ └── main.zig
└── config.yml
/.github/workflows/post-diffs-in-pr.yml:
--------------------------------------------------------------------------------
1 | name: Post diffs
2 |
3 | on:
4 | pull_request:
5 |
6 | concurrency:
7 | group: ${{ github.workflow }}-${{ github.ref }}
8 | cancel-in-progress: true
9 |
10 | jobs:
11 | post_diffs:
12 | uses: codecrafters-io/course-sdk/.github/workflows/post-diffs-in-pr.yml@main
13 | with:
14 | sdkRef: main
15 |
--------------------------------------------------------------------------------
/.github/workflows/test-git-is-unavailable.yml:
--------------------------------------------------------------------------------
1 | name: Validate Git is hidden
2 |
3 | # Disabled for now, until we figure out how to remove Git from other downstream components
4 | on:
5 | push:
6 | branches: [test-git-is-unavailable]
7 |
8 | jobs:
9 | test_git_is_unavailable:
10 | runs-on: ubuntu-latest
11 |
12 | steps:
13 | - uses: actions/checkout@v3
14 |
15 | - name: Validate Git is hidden
16 | run: ./scripts/check_git_is_unavailable.sh
17 |
--------------------------------------------------------------------------------
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: Test
2 |
3 | on:
4 | pull_request:
5 | push:
6 | branches: [main]
7 |
8 | concurrency:
9 | group: ${{ github.workflow }}-${{ github.ref }}
10 | cancel-in-progress: true
11 |
12 | jobs:
13 | test_course_definition:
14 | uses: codecrafters-io/course-sdk/.github/workflows/test-course-definition.yml@main
15 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | course_definition_tester
2 | .history/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2022 CodeCrafters
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | setup:
2 | git clone https://github.com/codecrafters-io/course-sdk course_sdk
3 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # build-your-own-git
2 |
3 | Content for the "Build your own Git" challenge
4 |
5 | ### Setup
6 |
7 | This challenge is developed using https://github.com/codecrafters-io/course-sdk. Read the README there for information
8 | on how to contribute language support & submit solutions.
--------------------------------------------------------------------------------
/compiled_starters/c/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
12 | cmake --build ./build
13 |
--------------------------------------------------------------------------------
/compiled_starters/c/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec $(dirname $0)/build/git "$@"
12 |
--------------------------------------------------------------------------------
/compiled_starters/c/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/c/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Linker output
11 | *.ilk
12 | *.map
13 | *.exp
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 |
19 | # Libraries
20 | *.lib
21 | *.a
22 | *.la
23 | *.lo
24 |
25 | # Shared objects (inc. Windows DLLs)
26 | *.dll
27 | *.so
28 | *.so.*
29 | *.dylib
30 |
31 | # Executables
32 | *.exe
33 | *.out
34 | *.app
35 | *.i*86
36 | *.x86_64
37 | *.hex
38 |
39 | # Debug files
40 | *.dSYM/
41 | *.su
42 | *.idb
43 | *.pdb
44 |
45 | # Kernel Module Compile Results
46 | *.mod*
47 | *.cmd
48 | .tmp_versions/
49 | modules.order
50 | Module.symvers
51 | Mkfile.old
52 | dkms.conf
53 |
54 | build
55 | vcpkg_installed
--------------------------------------------------------------------------------
/compiled_starters/c/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.13)
2 |
3 | project(codecrafters-git)
4 |
5 | file(GLOB_RECURSE SOURCE_FILES src/*.c src/*.h)
6 |
7 | set(CMAKE_C_STANDARD 23) # Enable the C23 standard
8 |
9 | find_package(OpenSSL REQUIRED)
10 | find_package(ZLIB REQUIRED)
11 |
12 | add_executable(git ${SOURCE_FILES})
13 |
14 | target_link_libraries(git PRIVATE OpenSSL::Crypto)
15 | target_link_libraries(git PRIVATE ZLIB::ZLIB)
16 |
--------------------------------------------------------------------------------
/compiled_starters/c/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the C version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: c-23
11 | language_pack: c-23
12 |
--------------------------------------------------------------------------------
/compiled_starters/c/vcpkg-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "default-registry": {
3 | "kind": "git",
4 | "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d",
5 | "repository": "https://github.com/microsoft/vcpkg"
6 | },
7 | "registries": [
8 | {
9 | "kind": "artifact",
10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11 | "name": "microsoft"
12 | }
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/compiled_starters/c/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": []
3 | }
4 |
--------------------------------------------------------------------------------
/compiled_starters/c/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
18 | cmake --build ./build
19 | )
20 |
21 | # Copied from .codecrafters/run.sh
22 | #
23 | # - Edit this to change how your program runs locally
24 | # - Edit .codecrafters/run.sh to change how your program runs remotely
25 | exec $(dirname $0)/build/git "$@"
26 |
--------------------------------------------------------------------------------
/compiled_starters/cpp/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
12 | cmake --build ./build
13 |
--------------------------------------------------------------------------------
/compiled_starters/cpp/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec $(dirname "$0")/build/git "$@"
--------------------------------------------------------------------------------
/compiled_starters/cpp/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/cpp/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Linker output
11 | *.ilk
12 | *.map
13 | *.exp
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 |
19 | # Libraries
20 | *.lib
21 | *.a
22 | *.la
23 | *.lo
24 |
25 | # Shared objects (inc. Windows DLLs)
26 | *.dll
27 | *.so
28 | *.so.*
29 | *.dylib
30 |
31 | # Executables
32 | *.exe
33 | *.out
34 | *.app
35 | *.i*86
36 | *.x86_64
37 | *.hex
38 |
39 | # Debug files
40 | *.dSYM/
41 | *.su
42 | *.idb
43 | *.pdb
44 |
45 | # Kernel Module Compile Results
46 | *.mod*
47 | *.cmd
48 | .tmp_versions/
49 | modules.order
50 | Module.symvers
51 | Mkfile.old
52 | dkms.conf
53 |
54 | build
55 | vcpkg_installed
--------------------------------------------------------------------------------
/compiled_starters/cpp/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.13)
2 |
3 | project(codecrafters-git)
4 |
5 | set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard
6 |
7 | file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp)
8 |
9 | find_package(OpenSSL REQUIRED)
10 | find_package(ZLIB REQUIRED)
11 |
12 | add_executable(git ${SOURCE_FILES})
13 |
14 | target_link_libraries(git PRIVATE OpenSSL::Crypto)
15 | target_link_libraries(git PRIVATE ZLIB::ZLIB)
--------------------------------------------------------------------------------
/compiled_starters/cpp/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the C++ version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: cpp-23
11 | language_pack: cpp-23
12 |
--------------------------------------------------------------------------------
/compiled_starters/cpp/vcpkg-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "default-registry": {
3 | "kind": "git",
4 | "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d",
5 | "repository": "https://github.com/microsoft/vcpkg"
6 | },
7 | "registries": [
8 | {
9 | "kind": "artifact",
10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11 | "name": "microsoft"
12 | }
13 | ]
14 | }
--------------------------------------------------------------------------------
/compiled_starters/cpp/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": []
3 | }
--------------------------------------------------------------------------------
/compiled_starters/cpp/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
18 | cmake --build ./build
19 | )
20 |
21 | # Copied from .codecrafters/run.sh
22 | #
23 | # - Edit this to change how your program runs locally
24 | # - Edit .codecrafters/run.sh to change how your program runs remotely
25 | exec $(dirname "$0")/build/git "$@"
26 |
--------------------------------------------------------------------------------
/compiled_starters/csharp/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | dotnet build --configuration Release --output /tmp/codecrafters-build-git-csharp codecrafters-git.csproj
12 |
--------------------------------------------------------------------------------
/compiled_starters/csharp/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec /tmp/codecrafters-build-git-csharp/codecrafters-git "$@"
12 |
--------------------------------------------------------------------------------
/compiled_starters/csharp/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/csharp/codecrafters-git.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 | codecrafters_git
7 | enable
8 | enable
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/compiled_starters/csharp/codecrafters-git.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31903.59
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "codecrafters-git", "codecrafters-git.csproj", "{5647EB94-C939-4AAF-BDC4-807AA270FCF0}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(SolutionProperties) = preSolution
14 | HideSolutionNode = FALSE
15 | EndGlobalSection
16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
17 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.Build.0 = Release|Any CPU
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/compiled_starters/csharp/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the C# version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: dotnet-9.0
11 | language_pack: dotnet-9.0
12 |
--------------------------------------------------------------------------------
/compiled_starters/csharp/src/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | if (args.Length < 1)
5 | {
6 | Console.WriteLine("Please provide a command.");
7 | return;
8 | }
9 |
10 | // You can use print statements as follows for debugging, they'll be visible when running tests.
11 | Console.Error.WriteLine("Logs from your program will appear here!");
12 |
13 | string command = args[0];
14 |
15 | if (command == "init")
16 | {
17 | // Uncomment this block to pass the first stage
18 | //
19 | // Directory.CreateDirectory(".git");
20 | // Directory.CreateDirectory(".git/objects");
21 | // Directory.CreateDirectory(".git/refs");
22 | // File.WriteAllText(".git/HEAD", "ref: refs/heads/main\n");
23 | // Console.WriteLine("Initialized git directory");
24 | }
25 | else
26 | {
27 | throw new ArgumentException($"Unknown command {command}");
28 | }
--------------------------------------------------------------------------------
/compiled_starters/csharp/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | dotnet build --configuration Release --output /tmp/codecrafters-build-git-csharp codecrafters-git.csproj
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec /tmp/codecrafters-build-git-csharp/codecrafters-git "$@"
25 |
--------------------------------------------------------------------------------
/compiled_starters/go/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | go build -o /tmp/codecrafters-build-git-go app/*.go
12 |
--------------------------------------------------------------------------------
/compiled_starters/go/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec /tmp/codecrafters-build-git-go "$@"
12 |
--------------------------------------------------------------------------------
/compiled_starters/go/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/go/app/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "os"
6 | )
7 |
8 | // Usage: your_program.sh ...
9 | func main() {
10 | // You can use print statements as follows for debugging, they'll be visible when running tests.
11 | fmt.Fprintf(os.Stderr, "Logs from your program will appear here!\n")
12 |
13 | if len(os.Args) < 2 {
14 | fmt.Fprintf(os.Stderr, "usage: mygit [...]\n")
15 | os.Exit(1)
16 | }
17 |
18 | switch command := os.Args[1]; command {
19 | case "init":
20 | // Uncomment this block to pass the first stage!
21 | //
22 | // for _, dir := range []string{".git", ".git/objects", ".git/refs"} {
23 | // if err := os.MkdirAll(dir, 0755); err != nil {
24 | // fmt.Fprintf(os.Stderr, "Error creating directory: %s\n", err)
25 | // }
26 | // }
27 | //
28 | // headFileContents := []byte("ref: refs/heads/main\n")
29 | // if err := os.WriteFile(".git/HEAD", headFileContents, 0644); err != nil {
30 | // fmt.Fprintf(os.Stderr, "Error writing file: %s\n", err)
31 | // }
32 | //
33 | // fmt.Println("Initialized git directory")
34 |
35 | default:
36 | fmt.Fprintf(os.Stderr, "Unknown command %s\n", command)
37 | os.Exit(1)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/compiled_starters/go/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Go version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: go-1.24
11 | language_pack: go-1.24
12 |
--------------------------------------------------------------------------------
/compiled_starters/go/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/codecrafters-io/git-starter-go
2 |
3 | go 1.24.0
4 |
--------------------------------------------------------------------------------
/compiled_starters/go/go.sum:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codecrafters-io/build-your-own-git/fde1d49c3b841b8a33b04f8aa0383e5ba1378dbc/compiled_starters/go/go.sum
--------------------------------------------------------------------------------
/compiled_starters/go/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | go build -o /tmp/codecrafters-build-git-go app/*.go
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec /tmp/codecrafters-build-git-go "$@"
25 |
--------------------------------------------------------------------------------
/compiled_starters/haskell/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # This compiles the program into $(stack path --local-install-root)/bin/codecrafters-git-exe.
12 | stack build
13 |
--------------------------------------------------------------------------------
/compiled_starters/haskell/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | stackInstallRoot=$(cd $(dirname "$0") && stack path --local-install-root) # Fetch the path from within the project directory
12 | exec "$stackInstallRoot/bin/codecrafters-git-exe" "$@"
--------------------------------------------------------------------------------
/compiled_starters/haskell/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/haskell/.gitignore:
--------------------------------------------------------------------------------
1 | codecrafters-git.cabal
2 | *~
3 | dist
4 | dist-*
5 | cabal-dev
6 | *.o
7 | *.hi
8 | *.hie
9 | *.chi
10 | *.chs.h
11 | *.dyn_o
12 | *.dyn_hi
13 | .hpc
14 | .hsenv
15 | .cabal-sandbox/
16 | cabal.sandbox.config
17 | *.prof
18 | *.aux
19 | *.hp
20 | *.eventlog
21 | .stack/
22 | .stack-work/
23 | cabal.project.local
24 | cabal.project.local~
25 | .HTF/
26 | .ghc.environment.*
--------------------------------------------------------------------------------
/compiled_starters/haskell/app/Main.hs:
--------------------------------------------------------------------------------
1 | {-# LANGUAGE BlockArguments #-}
2 | {-# LANGUAGE OverloadedStrings #-}
3 | {-# OPTIONS_GHC -Wno-unused-top-binds #-}
4 |
5 | module Main (main) where
6 |
7 | import System.Directory (createDirectoryIfMissing)
8 | import System.FilePath ((>))
9 | import System.IO (IOMode (WriteMode), hPutStrLn, withFile, hSetBuffering, stdout, stderr, BufferMode (NoBuffering))
10 |
11 | main :: IO ()
12 | main = do
13 | -- Disable output buffering
14 | hSetBuffering stdout NoBuffering
15 | hSetBuffering stderr NoBuffering
16 |
17 | -- You can use print statements as follows for debugging, they'll be visible when running tests.
18 | hPutStrLn stderr "Logs from your program will appear here"
19 |
20 | -- Uncomment this block to pass first stage
21 | -- let createParents = True
22 | -- createDirectoryIfMissing createParents ".git"
23 | -- createDirectoryIfMissing createParents (".git" > "objects")
24 | -- createDirectoryIfMissing createParents (".git" > "refs")
25 | -- withFile (".git" > "HEAD") WriteMode $ \f -> hPutStrLn f "ref: refs/heads/main"
26 | -- putStrLn $ "Initialized git directory"
27 |
--------------------------------------------------------------------------------
/compiled_starters/haskell/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Haskell version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: haskell-9.8
11 | language_pack: haskell-9.8
12 |
--------------------------------------------------------------------------------
/compiled_starters/haskell/package.yaml:
--------------------------------------------------------------------------------
1 | name: codecrafters-git
2 | version: 0.1.0.0
3 | license: BSD3
4 |
5 | dependencies:
6 | - base >= 4.19 && < 5
7 | - bytestring # useful to send bytes over the network
8 | - containers # may help with the database structure and debugging
9 | - cryptonite # dealing with SHA1
10 | - directory # directory manipulations
11 | - filepath # path manipulations
12 | - http-client # http
13 | - http-client-tls # https
14 | - http-types # http
15 | - memory # helpful in sha1 manipulations
16 | - mtl # may help with structuring
17 | - optparse-applicative # may help with command line argument parsing
18 | - time # may help with the expiry function
19 | - word8 # works well with attoparsec
20 | - zlib # zlib compression (git uses it)
21 | # parsing libs
22 | - attoparsec
23 | # testing
24 | - HUnit
25 |
26 | executables:
27 | codecrafters-git-exe:
28 | main: Main.hs
29 | source-dirs: app
30 | ghc-options:
31 | - -threaded
32 | - -rtsopts
33 | - -with-rtsopts=-N
34 |
--------------------------------------------------------------------------------
/compiled_starters/haskell/stack.yaml:
--------------------------------------------------------------------------------
1 | resolver: lts-23.18
2 |
3 | packages:
4 | - .
5 |
--------------------------------------------------------------------------------
/compiled_starters/haskell/stack.yaml.lock:
--------------------------------------------------------------------------------
1 | # This file was autogenerated by Stack.
2 | # You should not edit this file by hand.
3 | # For more information, please see the documentation at:
4 | # https://docs.haskellstack.org/en/stable/lock_files
5 |
6 | packages: []
7 | snapshots:
8 | - completed:
9 | sha256: d133abe75e408a407cce3f032c96ac1bbadf474a93b5156ebf4135b53382d56b
10 | size: 683827
11 | url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/18.yaml
12 | original: lts-23.18
13 |
--------------------------------------------------------------------------------
/compiled_starters/haskell/your_git.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 | (
5 | cd $(dirname "$0")
6 | stack build --copy-bins
7 | )
8 | exec hs-git-clone-exe "$@"
9 |
--------------------------------------------------------------------------------
/compiled_starters/haskell/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | stack build
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | stackInstallRoot=$(cd $(dirname "$0") && stack path --local-install-root) # Fetch the path from within the project directory
25 | exec "$stackInstallRoot/bin/codecrafters-git-exe" "$@"
26 |
--------------------------------------------------------------------------------
/compiled_starters/java/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | mvn -B package -Ddir=/tmp/codecrafters-build-git-java
12 |
--------------------------------------------------------------------------------
/compiled_starters/java/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec java -jar /tmp/codecrafters-build-git-java/codecrafters-git.jar "$@"
12 |
--------------------------------------------------------------------------------
/compiled_starters/java/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/java/.gitignore:
--------------------------------------------------------------------------------
1 | *.jar
2 | target/
3 | .idea/
4 |
--------------------------------------------------------------------------------
/compiled_starters/java/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Java version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: java-23
11 | language_pack: java-23
12 |
--------------------------------------------------------------------------------
/compiled_starters/java/src/main/java/Main.java:
--------------------------------------------------------------------------------
1 | import java.io.File;
2 | import java.io.IOException;
3 | import java.nio.file.Files;
4 |
5 | public class Main {
6 | public static void main(String[] args){
7 | // You can use print statements as follows for debugging, they'll be visible when running tests.
8 | System.err.println("Logs from your program will appear here!");
9 |
10 | // Uncomment this block to pass the first stage
11 | //
12 | // final String command = args[0];
13 | //
14 | // switch (command) {
15 | // case "init" -> {
16 | // final File root = new File(".git");
17 | // new File(root, "objects").mkdirs();
18 | // new File(root, "refs").mkdirs();
19 | // final File head = new File(root, "HEAD");
20 | //
21 | // try {
22 | // head.createNewFile();
23 | // Files.write(head.toPath(), "ref: refs/heads/main\n".getBytes());
24 | // System.out.println("Initialized git directory");
25 | // } catch (IOException e) {
26 | // throw new RuntimeException(e);
27 | // }
28 | // }
29 | // default -> System.out.println("Unknown command: " + command);
30 | // }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/compiled_starters/java/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | mvn -B package -Ddir=/tmp/codecrafters-build-git-java
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec java -jar /tmp/codecrafters-build-git-java/codecrafters-git.jar "$@"
25 |
--------------------------------------------------------------------------------
/compiled_starters/javascript/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since JavaScript programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/compiled_starters/javascript/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec node $(dirname "$0")/app/main.js "$@"
12 |
--------------------------------------------------------------------------------
/compiled_starters/javascript/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/javascript/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/compiled_starters/javascript/app/main.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const path = require("path");
3 |
4 | // You can use print statements as follows for debugging, they'll be visible when running tests.
5 | console.error("Logs from your program will appear here!");
6 |
7 | // Uncomment this block to pass the first stage
8 | // const command = process.argv[2];
9 | //
10 | // switch (command) {
11 | // case "init":
12 | // createGitDirectory();
13 | // break;
14 | // default:
15 | // throw new Error(`Unknown command ${command}`);
16 | // }
17 | //
18 | // function createGitDirectory() {
19 | // fs.mkdirSync(path.join(process.cwd(), ".git"), { recursive: true });
20 | // fs.mkdirSync(path.join(process.cwd(), ".git", "objects"), { recursive: true });
21 | // fs.mkdirSync(path.join(process.cwd(), ".git", "refs"), { recursive: true });
22 | //
23 | // fs.writeFileSync(path.join(process.cwd(), ".git", "HEAD"), "ref: refs/heads/main\n");
24 | // console.log("Initialized git directory");
25 | // }
26 |
--------------------------------------------------------------------------------
/compiled_starters/javascript/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the JavaScript version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: nodejs-21
11 | language_pack: nodejs-21
12 |
--------------------------------------------------------------------------------
/compiled_starters/javascript/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codecrafters/build-your-own-git",
3 | "version": "1.0.0",
4 | "lockfileVersion": 3,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "@codecrafters/build-your-own-git",
9 | "version": "1.0.0",
10 | "license": "MIT"
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/compiled_starters/javascript/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codecrafters/build-your-own-git",
3 | "version": "1.0.0",
4 | "description": "Build your own Git challenge, from CodeCrafters",
5 | "main": "main.js",
6 | "scripts": {
7 | "dev": "node app/main.js"
8 | },
9 | "keywords": [
10 | "build-your-own-x"
11 | ],
12 | "author": "",
13 | "license": "MIT",
14 | "dependencies": {}
15 | }
--------------------------------------------------------------------------------
/compiled_starters/javascript/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/run.sh
12 | #
13 | # - Edit this to change how your program runs locally
14 | # - Edit .codecrafters/run.sh to change how your program runs remotely
15 | exec node $(dirname "$0")/app/main.js "$@"
16 |
--------------------------------------------------------------------------------
/compiled_starters/kotlin/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | mvn -B package -Ddir=/tmp/codecrafters-build-dir
12 |
--------------------------------------------------------------------------------
/compiled_starters/kotlin/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec java -jar /tmp/codecrafters-build-dir/build-your-own-git.jar "$@"
12 |
--------------------------------------------------------------------------------
/compiled_starters/kotlin/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/kotlin/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .idea/
--------------------------------------------------------------------------------
/compiled_starters/kotlin/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Kotlin version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: kotlin-2.0
11 | language_pack: kotlin-2.0
12 |
--------------------------------------------------------------------------------
/compiled_starters/kotlin/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | import java.io.File
2 | import kotlin.system.exitProcess
3 |
4 | fun main(args: Array) {
5 | // You can use print statements as follows for debugging, they'll be visible when running tests.
6 | System.err.println("Logs from your program will appear here!")
7 |
8 | if (args.isEmpty()) {
9 | println("Usage: your_program.sh []")
10 | exitProcess(1)
11 | }
12 |
13 | if (args[0] == "init") {
14 | // Uncomment this block to pass the first stage
15 | //
16 | // val gitDir = File(".git")
17 | // gitDir.mkdir()
18 | // File(gitDir, "objects").mkdir()
19 | // File(gitDir, "refs").mkdir()
20 | // File(gitDir, "HEAD").writeText("ref: refs/heads/master\n")
21 | //
22 | // println("Initialized git directory")
23 | } else {
24 | println("Unknown command: ${args[0]}")
25 | exitProcess(1)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/compiled_starters/kotlin/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | mvn -B package -Ddir=/tmp/codecrafters-build-dir
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec java -jar /tmp/codecrafters-build-dir/build-your-own-git.jar "$@"
25 |
--------------------------------------------------------------------------------
/compiled_starters/python/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since Python programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/compiled_starters/python/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | PYTHONPATH=$(dirname $0) exec python3 -m app.main "$@"
12 |
--------------------------------------------------------------------------------
/compiled_starters/python/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/python/app/main.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 |
4 |
5 | def main():
6 | # You can use print statements as follows for debugging, they'll be visible when running tests.
7 | print("Logs from your program will appear here!", file=sys.stderr)
8 |
9 | # Uncomment this block to pass the first stage
10 | #
11 | # command = sys.argv[1]
12 | # if command == "init":
13 | # os.mkdir(".git")
14 | # os.mkdir(".git/objects")
15 | # os.mkdir(".git/refs")
16 | # with open(".git/HEAD", "w") as f:
17 | # f.write("ref: refs/heads/main\n")
18 | # print("Initialized git directory")
19 | # else:
20 | # raise RuntimeError(f"Unknown command #{command}")
21 |
22 |
23 | if __name__ == "__main__":
24 | main()
25 |
--------------------------------------------------------------------------------
/compiled_starters/python/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Python version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: python-3.13
11 | language_pack: python-3.13
12 |
--------------------------------------------------------------------------------
/compiled_starters/python/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/run.sh
12 | #
13 | # - Edit this to change how your program runs locally
14 | # - Edit .codecrafters/run.sh to change how your program runs remotely
15 | PYTHONPATH=$(dirname $0) exec python3 -m app.main "$@"
16 |
--------------------------------------------------------------------------------
/compiled_starters/ruby/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since Ruby programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/compiled_starters/ruby/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec ruby $(dirname $0)/app/main.rb "$@"
12 |
--------------------------------------------------------------------------------
/compiled_starters/ruby/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/ruby/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source "https://rubygems.org"
4 |
5 | # Add gems here if you need to use them.
6 | # Make sure to run `bundle install` before running tests or submitting your code.
7 |
--------------------------------------------------------------------------------
/compiled_starters/ruby/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 |
5 | PLATFORMS
6 | aarch64-linux-musl
7 | arm64-darwin-21
8 | arm64-darwin-23
9 | x86_64-linux
10 | ruby
11 |
12 | DEPENDENCIES
13 |
14 | BUNDLED WITH
15 | 2.5.6
16 |
--------------------------------------------------------------------------------
/compiled_starters/ruby/app/main.rb:
--------------------------------------------------------------------------------
1 | # You can use print statements as follows for debugging, they'll be visible when running tests.
2 | $stderr.puts "Logs from your program will appear here!"
3 |
4 | # Uncomment this block to pass the first stage
5 | #
6 | # command = ARGV[0]
7 | # case command
8 | # when "init"
9 | # Dir.mkdir(".git")
10 | # Dir.mkdir(".git/objects")
11 | # Dir.mkdir(".git/refs")
12 | # File.write(".git/HEAD", "ref: refs/heads/main\n")
13 | # puts "Initialized git directory"
14 | # else
15 | # raise RuntimeError.new("Unknown command #{command}")
16 | # end
17 |
--------------------------------------------------------------------------------
/compiled_starters/ruby/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Ruby version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: ruby-3.3
11 | language_pack: ruby-3.3
12 |
--------------------------------------------------------------------------------
/compiled_starters/ruby/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/run.sh
12 | #
13 | # - Edit this to change how your program runs locally
14 | # - Edit .codecrafters/run.sh to change how your program runs remotely
15 | exec ruby $(dirname $0)/app/main.rb "$@"
16 |
--------------------------------------------------------------------------------
/compiled_starters/rust/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | cargo build --release --target-dir=/tmp/codecrafters-build-git-rust --manifest-path Cargo.toml
12 |
--------------------------------------------------------------------------------
/compiled_starters/rust/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec /tmp/codecrafters-build-git-rust/release/codecrafters-git "$@"
12 |
--------------------------------------------------------------------------------
/compiled_starters/rust/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/rust/.gitignore:
--------------------------------------------------------------------------------
1 | # Generated by Cargo
2 | # will have compiled files and executables
3 | debug/
4 | target/
5 |
6 | # These are backup files generated by rustfmt
7 | **/*.rs.bk
8 |
9 | # MSVC Windows builds of rustc generate these, which store debugging information
10 | *.pdb
11 |
--------------------------------------------------------------------------------
/compiled_starters/rust/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "codecrafters-git"
3 | version = "0.1.0"
4 | authors = ["Codecrafters "]
5 | edition = "2021"
6 | rust-version = "1.80"
7 |
8 | [dependencies]
9 | anyhow = "1.0.68" # error handling
10 | bytes = "1.3.0" # helps manage buffers
11 | flate2 = "1.0.34" # compression
12 | thiserror = "1.0.38" # error handling
13 |
--------------------------------------------------------------------------------
/compiled_starters/rust/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Rust version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: rust-1.86
11 | language_pack: rust-1.86
12 |
--------------------------------------------------------------------------------
/compiled_starters/rust/src/main.rs:
--------------------------------------------------------------------------------
1 | #[allow(unused_imports)]
2 | use std::env;
3 | #[allow(unused_imports)]
4 | use std::fs;
5 |
6 | fn main() {
7 | // You can use print statements as follows for debugging, they'll be visible when running tests.
8 | eprintln!("Logs from your program will appear here!");
9 |
10 | // Uncomment this block to pass the first stage
11 | // let args: Vec = env::args().collect();
12 | // if args[1] == "init" {
13 | // fs::create_dir(".git").unwrap();
14 | // fs::create_dir(".git/objects").unwrap();
15 | // fs::create_dir(".git/refs").unwrap();
16 | // fs::write(".git/HEAD", "ref: refs/heads/main\n").unwrap();
17 | // println!("Initialized git directory")
18 | // } else {
19 | // println!("unknown command: {}", args[1])
20 | // }
21 | }
22 |
--------------------------------------------------------------------------------
/compiled_starters/rust/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | cargo build --release --target-dir=/tmp/codecrafters-build-git-rust --manifest-path Cargo.toml
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec /tmp/codecrafters-build-git-rust/release/codecrafters-git "$@"
25 |
--------------------------------------------------------------------------------
/compiled_starters/typescript/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since TypeScript programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/compiled_starters/typescript/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec bun run $(dirname $0)/app/main.ts "$@"
12 |
--------------------------------------------------------------------------------
/compiled_starters/typescript/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/typescript/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/compiled_starters/typescript/app/main.ts:
--------------------------------------------------------------------------------
1 | import * as fs from 'fs';
2 |
3 | const args = process.argv.slice(2);
4 | const command = args[0];
5 |
6 | switch (command) {
7 | case "init":
8 | // You can use print statements as follows for debugging, they'll be visible when running tests.
9 | console.error("Logs from your program will appear here!");
10 |
11 | // Uncomment this block to pass the first stage
12 | // fs.mkdirSync(".git", { recursive: true });
13 | // fs.mkdirSync(".git/objects", { recursive: true });
14 | // fs.mkdirSync(".git/refs", { recursive: true });
15 | // fs.writeFileSync(".git/HEAD", "ref: refs/heads/main\n");
16 | // console.log("Initialized git directory");
17 | break;
18 | default:
19 | throw new Error(`Unknown command ${command}`);
20 | }
21 |
--------------------------------------------------------------------------------
/compiled_starters/typescript/bun.lockb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codecrafters-io/build-your-own-git/fde1d49c3b841b8a33b04f8aa0383e5ba1378dbc/compiled_starters/typescript/bun.lockb
--------------------------------------------------------------------------------
/compiled_starters/typescript/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the TypeScript version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: bun-1.2
11 | language_pack: bun-1.2
12 |
--------------------------------------------------------------------------------
/compiled_starters/typescript/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codecrafters/git",
3 | "description": "Build your own Git challenge, from CodeCrafters",
4 | "type": "module",
5 | "scripts": {
6 | "dev": "bun run app/main.ts"
7 | },
8 | "devDependencies": {
9 | "@types/bun": "latest"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/compiled_starters/typescript/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | // Enable latest features
4 | "lib": ["ESNext", "DOM"],
5 | "target": "ESNext",
6 | "module": "ESNext",
7 | "moduleDetection": "force",
8 | "jsx": "react-jsx",
9 | "allowJs": true,
10 |
11 | // Bundler mode
12 | "moduleResolution": "bundler",
13 | "allowImportingTsExtensions": true,
14 | "verbatimModuleSyntax": true,
15 | "noEmit": true,
16 |
17 | // Best practices
18 | "strict": true,
19 | "skipLibCheck": true,
20 | "noFallthroughCasesInSwitch": true,
21 |
22 | // Some stricter flags (disabled by default)
23 | "noUnusedLocals": false,
24 | "noUnusedParameters": false,
25 | "noPropertyAccessFromIndexSignature": false
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/compiled_starters/typescript/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/run.sh
12 | #
13 | # - Edit this to change how your program runs locally
14 | # - Edit .codecrafters/run.sh to change how your program runs remotely
15 | exec bun run $(dirname $0)/app/main.ts "$@"
16 |
--------------------------------------------------------------------------------
/compiled_starters/zig/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | zig build
12 |
--------------------------------------------------------------------------------
/compiled_starters/zig/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec $(dirname $0)/zig-out/bin/main "$@"
12 |
--------------------------------------------------------------------------------
/compiled_starters/zig/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/compiled_starters/zig/.gitignore:
--------------------------------------------------------------------------------
1 | # Zig build artifacts
2 | main
3 | zig-cache/
4 | .zig-cache/
5 | zig-out/
6 |
7 | # Compiled binary output
8 | bin/
9 | !bin/.gitkeep
10 |
11 | # Ignore any .o or .h files generated during build
12 | *.o
13 | *.h
14 |
15 | # Ignore OS and editor specific files
16 | **/.DS_Store
17 | *.swp
18 | *~
19 |
--------------------------------------------------------------------------------
/compiled_starters/zig/build.zig:
--------------------------------------------------------------------------------
1 | const std = @import("std");
2 |
3 | // Learn more about this file here: https://ziglang.org/learn/build-system
4 | pub fn build(b: *std.Build) void {
5 | const exe = b.addExecutable(.{
6 | .name = "main",
7 | .root_source_file = b.path("src/main.zig"),
8 | .target = b.standardTargetOptions(.{}),
9 | .optimize = b.standardOptimizeOption(.{}),
10 | });
11 |
12 | // This declares intent for the executable to be installed into the
13 | // standard location when the user invokes the "install" step (the default
14 | // step when running `zig build`).
15 | b.installArtifact(exe);
16 |
17 | // This *creates* a Run step in the build graph, to be executed when another
18 | // step is evaluated that depends on it. The next line below will establish
19 | // such a dependency.
20 | const run_cmd = b.addRunArtifact(exe);
21 |
22 | // This creates a build step. It will be visible in the `zig build --help` menu,
23 | // and can be selected like this: `zig build run`
24 | // This will evaluate the `run` step rather than the default, which is "install".
25 | const run_step = b.step("run", "Run the app");
26 | run_step.dependOn(&run_cmd.step);
27 |
28 | // This allows the user to pass arguments to the application in the build
29 | // command itself, like this: `zig build run -- arg1 arg2 etc`
30 | if (b.args) |args| {
31 | run_cmd.addArgs(args);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/compiled_starters/zig/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Zig version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: zig-0.14
11 | language_pack: zig-0.14
12 |
--------------------------------------------------------------------------------
/compiled_starters/zig/src/main.zig:
--------------------------------------------------------------------------------
1 | const std = @import("std");
2 | const stdout = std.io.getStdOut().writer();
3 |
4 | pub fn main() !void {
5 | var gpa = std.heap.GeneralPurposeAllocator(.{}){};
6 | defer _ = gpa.deinit();
7 | const allocator = gpa.allocator();
8 |
9 | const args = try std.process.argsAlloc(allocator);
10 | defer std.process.argsFree(allocator, args);
11 |
12 | if (args.len < 2) {
13 | try std.io.getStdErr().writer().print("Usage: {s} \n", .{args[0]});
14 | return;
15 | }
16 |
17 | const command: []const u8 = args[1];
18 |
19 | // You can use print statements as follows for debugging, they'll be visible when running tests.
20 | std.debug.print("Logs from your program will appear here!\n", .{});
21 |
22 | if (std.mem.eql(u8, command, "init")) {
23 | // Uncomment this block to pass the first stage
24 | // const cwd = std.fs.cwd();
25 | // _ = try cwd.makeDir("./.git");
26 | // _ = try cwd.makeDir("./.git/objects");
27 | // _ = try cwd.makeDir("./.git/refs");
28 | // {
29 | // const head = try cwd.createFile("./.git/HEAD", .{});
30 | // defer head.close();
31 | // _ = try head.write("ref: refs/heads/main\n");
32 | // }
33 | // _ = try stdout.print("Initialized git directory\n", .{});
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/compiled_starters/zig/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | zig build
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec $(dirname $0)/zig-out/bin/main "$@"
25 |
--------------------------------------------------------------------------------
/dockerfiles/bun-1.1.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM oven/bun:1.1-alpine
3 |
4 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,bun.lockb"
5 |
6 | WORKDIR /app
7 |
8 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
9 | COPY --exclude=.git --exclude=README.md . /app
10 |
11 | # For reproducible builds.
12 | # This will install the exact versions of each package specified in the lockfile.
13 | # If package.json disagrees with bun.lockb, Bun will exit with an error. The lockfile will not be updated.
14 | RUN bun install --frozen-lockfile
15 |
16 | # If the node_modules directory exists, move it to /app-cached
17 | RUN mkdir -p /app-cached
18 | RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi
19 |
--------------------------------------------------------------------------------
/dockerfiles/bun-1.2.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM oven/bun:1.2-alpine
3 |
4 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,bun.lockb"
5 |
6 | WORKDIR /app
7 |
8 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
9 | COPY --exclude=.git --exclude=README.md . /app
10 |
11 | # For reproducible builds.
12 | # This will install the exact versions of each package specified in the lockfile.
13 | # If package.json disagrees with bun.lockb, Bun will exit with an error. The lockfile will not be updated.
14 | RUN bun install --frozen-lockfile
15 |
16 | # If the node_modules directory exists, move it to /app-cached
17 | RUN mkdir -p /app-cached
18 | RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi
19 |
--------------------------------------------------------------------------------
/dockerfiles/c-23.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM gcc:14.2.0-bookworm
3 |
4 | # Ensures the container is re-built if dependency files change
5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="vcpkg.json,vcpkg-configuration.json"
6 |
7 | RUN apt-get update && \
8 | apt-get install --no-install-recommends -y zip=3.* && \
9 | apt-get install --no-install-recommends -y g++=4:* && \
10 | apt-get install --no-install-recommends -y build-essential=12.* && \
11 | apt-get clean && \
12 | rm -rf /var/lib/apt/lists/*
13 |
14 | # cmake is required by vcpkg
15 | RUN wget --progress=dot:giga https://github.com/Kitware/CMake/releases/download/v3.30.5/cmake-3.30.5-Linux-x86_64.tar.gz && \
16 | tar -xzvf cmake-3.30.5-Linux-x86_64.tar.gz && \
17 | mv cmake-3.30.5-linux-x86_64/ /cmake
18 |
19 | ENV CMAKE_BIN="/cmake/bin"
20 | ENV PATH="${CMAKE_BIN}:$PATH"
21 |
22 | RUN git clone https://github.com/microsoft/vcpkg.git && \
23 | ./vcpkg/bootstrap-vcpkg.sh -disableMetrics
24 |
25 | ENV VCPKG_ROOT="/vcpkg"
26 | ENV PATH="${VCPKG_ROOT}:$PATH"
27 |
28 | WORKDIR /app
29 |
30 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
31 | COPY --exclude=.git --exclude=README.md . /app
32 |
33 | RUN vcpkg install --no-print-usage
34 |
35 | RUN mkdir -p /app-cached
36 | RUN if [ -d "/app/vcpkg_installed" ]; then mv /app/vcpkg_installed /app-cached; fi
37 |
--------------------------------------------------------------------------------
/dockerfiles/cpp-20.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM gcc:12.2.0-bullseye
2 |
3 | RUN apt-get update && \
4 | apt-get install --no-install-recommends -y cmake=3.18.* && \
5 | apt-get clean && \
6 | rm -rf /var/lib/apt/lists/*
7 |
8 | # TODO: Clean this up when we move to CPP23
9 | RUN printf "cd \${CODECRAFTERS_REPOSITORY_DIR} && cmake . && make && (echo '#!/bin/sh\nexec \${CODECRAFTERS_REPOSITORY_DIR}/server \"\$@\"' > your_git.sh) && chmod +x your_git.sh" > /codecrafters-precompile.sh
10 |
--------------------------------------------------------------------------------
/dockerfiles/dotnet-8.0.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM mcr.microsoft.com/dotnet/sdk:8.0-alpine
2 |
3 | RUN apk add --no-cache 'git>=2.40'
4 |
5 | COPY codecrafters-git.csproj /app/codecrafters-git.csproj
6 | COPY codecrafters-git.sln /app/codecrafters-git.sln
7 |
8 | RUN mkdir /app/src
9 | RUN (echo 'System.Console.WriteLine("If you are seeing this, there is something wrong with our caching mechanism! Please contact us at hello@codecrafters.io.");' > /app/src/Program.cs) > /dev/null
10 |
11 | WORKDIR /app
12 |
13 | # This saves nuget packages to ~/.nuget
14 | RUN dotnet build --configuration Release .
15 |
16 | # Overwrite Program.cs to remove the echoed line
17 | RUN rm /app/src/Program.cs
18 |
19 | # This seems to cause a caching issue with the dotnet build command, where contents from the removed /src/Program.cs are used
20 | RUN rm -rf /app/obj
21 | RUN rm -rf /app/bin
22 |
23 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && dotnet build --configuration Release ." > /codecrafters-precompile.sh
24 | RUN chmod +x /codecrafters-precompile.sh
25 |
26 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="codecrafters-git.csproj,codecrafters-git.sln"
27 |
--------------------------------------------------------------------------------
/dockerfiles/dotnet-9.0.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM mcr.microsoft.com/dotnet/sdk:9.0-alpine
2 |
3 | RUN apk add --no-cache 'git>=2.40'
4 |
5 | COPY codecrafters-git.csproj /app/codecrafters-git.csproj
6 | COPY codecrafters-git.sln /app/codecrafters-git.sln
7 |
8 | RUN mkdir /app/src
9 | RUN (echo 'System.Console.WriteLine("If you are seeing this, there is something wrong with our caching mechanism! Please contact us at hello@codecrafters.io.");' > /app/src/Program.cs) > /dev/null
10 |
11 | WORKDIR /app
12 |
13 | # This saves nuget packages to ~/.nuget
14 | RUN dotnet build --configuration Release .
15 |
16 | # Overwrite Program.cs to remove the echoed line
17 | RUN rm /app/src/Program.cs
18 |
19 | # This seems to cause a caching issue with the dotnet build command, where contents from the removed /src/Program.cs are used
20 | RUN rm -rf /app/obj
21 | RUN rm -rf /app/bin
22 |
23 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && dotnet build --configuration Release ." > /codecrafters-precompile.sh
24 | RUN chmod +x /codecrafters-precompile.sh
25 |
26 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="codecrafters-git.csproj,codecrafters-git.sln"
27 |
--------------------------------------------------------------------------------
/dockerfiles/go-1.13.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:1.13-alpine
2 |
3 | RUN apk add --no-cache 'git>=2.43'
--------------------------------------------------------------------------------
/dockerfiles/go-1.16.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:1.16-alpine
2 |
3 | RUN apk add --no-cache 'git>=2.40'
4 |
--------------------------------------------------------------------------------
/dockerfiles/go-1.19.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:1.19-alpine
2 |
3 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
4 |
5 | WORKDIR /app
6 |
7 | COPY go.mod go.sum ./
8 |
9 | RUN go mod download
10 |
11 | RUN apk add --no-cache 'git>=2.40'
12 |
--------------------------------------------------------------------------------
/dockerfiles/go-1.21.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM golang:1.21-alpine
2 |
3 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
4 |
5 | WORKDIR /app
6 |
7 | COPY go.mod go.sum ./
8 |
9 | # Starting from Go 1.20, the go standard library is no loger compiled
10 | # setting the GODEBUG environment to "installgoroot=all" restores the old behavior
11 | RUN GODEBUG="installgoroot=all" go install std
12 |
13 | RUN go mod download
14 |
15 | RUN apk add --no-cache 'git>=2.40'
16 |
--------------------------------------------------------------------------------
/dockerfiles/go-1.22.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM golang:1.22-alpine
3 |
4 | # Ensures the container is re-built if go.mod or go.sum changes
5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
6 |
7 | WORKDIR /app
8 |
9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10 | COPY --exclude=.git --exclude=README.md . /app
11 |
12 | # Starting from Go 1.20, the go standard library is no loger compiled.
13 | # Setting GODEBUG to "installgoroot=all" restores the old behavior
14 | RUN GODEBUG="installgoroot=all" go install std
15 |
16 | RUN go mod download
17 |
18 | RUN apk add --no-cache 'git>=2.40'
19 |
--------------------------------------------------------------------------------
/dockerfiles/go-1.24.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM golang:1.24-alpine
3 |
4 | # Ensures the container is re-built if go.mod or go.sum changes
5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="go.mod,go.sum"
6 |
7 | WORKDIR /app
8 |
9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10 | COPY --exclude=.git --exclude=README.md . /app
11 |
12 | # Starting from Go 1.20, the go standard library is no loger compiled.
13 | # Setting GODEBUG to "installgoroot=all" restores the old behavior
14 | RUN GODEBUG="installgoroot=all" go install std
15 |
16 | RUN go mod download
17 |
18 | RUN apk add --no-cache 'git>=2.40'
19 |
--------------------------------------------------------------------------------
/dockerfiles/haskell-9.4.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM haskell:9.4.6-buster
2 |
3 | WORKDIR /app
4 |
5 | RUN mkdir -p /etc/stack
6 |
7 | # Absence of this causes `stack run` to raise a permissions error
8 | RUN echo "allow-different-user: true" >> /etc/stack/config.yaml
9 |
10 | # Force usage of the system GHC installation
11 | RUN echo "install-ghc: false" >> /etc/stack/config.yaml
12 | RUN echo "system-ghc: true" >> /etc/stack/config.yaml
13 |
14 | COPY stack.yaml package.yaml stack.yaml.lock /app/
15 |
16 | # Dummy static content to circumvent the /app doesn't exist warning
17 | RUN mkdir /app/src
18 | RUN mkdir /app/app
19 | RUN echo 'main :: IO ()' >> /app/app/Main.hs
20 | RUN echo 'main = putStrLn "Hello, World!"' >> /app/app/Main.hs
21 |
22 | RUN stack build
23 | RUN stack clean hs-git-clone
24 | RUN cp -r .stack-work /tmp/
25 |
26 | RUN rm -rf /app/app
27 | RUN rm -rf /app/src
28 |
29 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cp -r /tmp/.stack-work . && stack build" > /codecrafters-precompile.sh
30 | RUN chmod +x /codecrafters-precompile.sh
31 |
32 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="stack.yaml,package.yaml,stack.yaml.lock"
33 |
--------------------------------------------------------------------------------
/dockerfiles/haskell-9.8.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM haskell:9.8.4-bullseye
2 |
3 | # Ensures the container is re-built if go.mod or go.sum changes
4 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="stack.yaml,package.yaml,stack.yaml.lock"
5 |
6 | RUN mkdir -p /etc/stack
7 |
8 | # Absence of this causes `stack run` to raise a permissions error
9 | RUN echo "allow-different-user: true" >> /etc/stack/config.yaml
10 |
11 | # Force usage of the system GHC installation
12 | RUN echo "install-ghc: false" >> /etc/stack/config.yaml
13 | RUN echo "system-ghc: true" >> /etc/stack/config.yaml
14 |
15 | WORKDIR /app
16 |
17 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
18 | COPY . /app/
19 | RUN rm -rf /app/.git /app/README.md
20 |
21 | ENV STACK_ROOT=/app/.stack
22 | RUN stack build
23 | RUN stack clean codecrafters-git
24 |
25 | RUN mkdir /app-cached
26 | RUN mv .stack-work /app-cached/.stack-work
27 | RUN mv .stack /app-cached/.stack
28 | RUN rm -rf /app/app
29 |
--------------------------------------------------------------------------------
/dockerfiles/java-21.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM maven:3.9.5-eclipse-temurin-21-alpine
2 |
3 | COPY pom.xml /app/pom.xml
4 |
5 | WORKDIR /app
6 |
7 | # Download the dependencies
8 | RUN mvn -B package -Ddir=/tmp/codecrafters-git-target
9 |
10 | # Cache Dependencies
11 | RUN mkdir -p /app-cached
12 | RUN mv /app/target /app-cached # Is this needed?
13 |
14 | # Pre-compile steps
15 | RUN printf "cd \${CODECRAFTERS_REPOSITORY_DIR} && mvn -B package -Ddir=/tmp/codecrafters-git-target && sed -i 's/^\(mvn .*\)/#\1/' ./your_git.sh" > /codecrafters-precompile.sh
16 | RUN chmod +x /codecrafters-precompile.sh
--------------------------------------------------------------------------------
/dockerfiles/java-23.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM maven:3.9.9-eclipse-temurin-23-alpine
3 |
4 | # Ensures the container is re-built if dependency files change
5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="pom.xml"
6 |
7 | WORKDIR /app
8 |
9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10 | COPY --exclude=.git --exclude=README.md . /app
11 |
12 | # Install language-specific dependencies
13 | RUN .codecrafters/compile.sh
14 |
--------------------------------------------------------------------------------
/dockerfiles/kotlin-1.3.72.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM zenika/kotlin:1.3.72-jdk11-slim
2 |
3 | RUN apt-get update && \
4 | apt-get install --no-install-recommends -y git=1:2.* && \
5 | apt-get clean && \
6 | rm -rf /var/lib/apt/lists/*
7 |
--------------------------------------------------------------------------------
/dockerfiles/kotlin-1.4.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM zenika/kotlin:1.4.20-jdk11-slim
2 |
3 | RUN apt-get update && \
4 | apt-get install --no-install-recommends -y git=1:2.* && \
5 | apt-get clean && \
6 | rm -rf /var/lib/apt/lists/*
7 |
--------------------------------------------------------------------------------
/dockerfiles/kotlin-2.0.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM maven:3.9.8-eclipse-temurin-22-alpine
3 |
4 | # Ensures the container is re-built if pom.xml changes
5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="pom.xml"
6 |
7 | WORKDIR /app
8 |
9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10 | COPY --exclude=.git --exclude=README.md . /app
11 |
12 | # Cache dependencies
13 | RUN mvn -B package -Ddir=/tmp/codecrafters-build-dir
14 |
--------------------------------------------------------------------------------
/dockerfiles/nodejs-18.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:18.18.0-alpine3.17
--------------------------------------------------------------------------------
/dockerfiles/nodejs-21.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM node:21.7-alpine3.19
2 |
3 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="package.json,package-lock.json"
4 |
5 | WORKDIR /app
6 |
7 | COPY package.json ./
8 | COPY package-lock.json ./
9 |
10 | # If dependencies in the package lock do not match those in package.json, instead of updating the package lock, npm ci will exit with an error.
11 | RUN npm ci
12 |
13 | RUN mkdir -p /app-cached
14 | # If the node_modules directory exists, move it to /app-cached
15 | RUN if [ -d "/app/node_modules" ]; then mv /app/node_modules /app-cached; fi
16 |
--------------------------------------------------------------------------------
/dockerfiles/python-3.11.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.11-alpine
2 |
3 | RUN apk add --no-cache 'git>=2.40'
4 |
--------------------------------------------------------------------------------
/dockerfiles/python-3.12.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.12-alpine
2 |
3 | RUN apk add --no-cache 'git>=2.40'
4 |
--------------------------------------------------------------------------------
/dockerfiles/python-3.13.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM python:3.13-alpine
2 |
3 | RUN apk add --no-cache 'git>=2.40'
4 |
--------------------------------------------------------------------------------
/dockerfiles/python-3.7.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM jfloff/alpine-python:3.7
2 |
3 | RUN apk add --no-cache 'git>=2.40'
4 |
--------------------------------------------------------------------------------
/dockerfiles/python-3.8.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM jfloff/alpine-python:3.8
2 |
3 | RUN apk add --no-cache 'git>=2.40'
4 |
--------------------------------------------------------------------------------
/dockerfiles/ruby-2.7.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ruby:2.7-alpine
2 |
3 | RUN apk add --no-cache 'git>=2.40'
4 |
--------------------------------------------------------------------------------
/dockerfiles/ruby-3.2.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ruby:3.2-alpine
2 |
3 | RUN apk add --no-cache 'git>=2.40'
4 |
--------------------------------------------------------------------------------
/dockerfiles/ruby-3.3.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM ruby:3.3-alpine
2 |
3 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Gemfile,Gemfile.lock"
4 |
5 | WORKDIR /app
6 |
7 | COPY Gemfile Gemfile.lock ./
8 |
9 | RUN bundle install --verbose
10 |
11 | RUN apk add --no-cache 'git>=2.40'
12 |
--------------------------------------------------------------------------------
/dockerfiles/rust-1.62.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM rust:1.62-buster
2 |
3 | RUN apt-get update && \
4 | apt-get install --no-install-recommends -y git=1:2.* && \
5 | apt-get clean && \
6 | rm -rf /var/lib/apt/lists/*
7 |
8 | COPY Cargo.toml /app/Cargo.toml
9 | COPY Cargo.lock /app/Cargo.lock
10 |
11 | RUN mkdir /app/src
12 | RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs
13 |
14 | WORKDIR /app
15 | RUN cargo build --release --target-dir=/tmp/codecrafters-git-target
16 |
17 | RUN rm /tmp/codecrafters-git-target/release/git-starter-rust
18 | RUN rm /tmp/codecrafters-git-target/release/git-starter-rust.d
19 |
20 | RUN find /tmp/codecrafters-git-target/release -type f -maxdepth 1 -delete
21 | RUN rm -f /tmp/codecrafters-git-target/release/deps/*git_starter_rust*
22 | RUN rm -f /tmp/codecrafters-git-target/release/deps/git_starter_rust*
23 | RUN rm -f /tmp/codecrafters-git-target/release/.fingerprint/*git_starter_rust*
24 | RUN rm -f /tmp/codecrafters-git-target/release/.fingerprint/git_starter_rust*
25 |
26 | RUN rm -rf /app/src
27 |
28 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cargo build --release --target-dir=/tmp/codecrafters-git-target --manifest-path Cargo.toml" > /codecrafters-precompile.sh
29 | RUN chmod +x /codecrafters-precompile.sh
30 |
31 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
32 |
--------------------------------------------------------------------------------
/dockerfiles/rust-1.68.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM rust:1.68-buster
2 |
3 | RUN apt-get update && \
4 | apt-get install --no-install-recommends -y git=1:2.* && \
5 | apt-get clean && \
6 | rm -rf /var/lib/apt/lists/*
7 |
8 | COPY Cargo.toml /app/Cargo.toml
9 | COPY Cargo.lock /app/Cargo.lock
10 |
11 | RUN mkdir /app/src
12 | RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs
13 |
14 | WORKDIR /app
15 | RUN cargo build --release --target-dir=/tmp/codecrafters-git-target
16 |
17 | RUN rm /tmp/codecrafters-git-target/release/git-starter-rust
18 | RUN rm /tmp/codecrafters-git-target/release/git-starter-rust.d
19 |
20 | RUN find /tmp/codecrafters-git-target/release -type f -maxdepth 1 -delete
21 | RUN rm -f /tmp/codecrafters-git-target/release/deps/*git_starter_rust*
22 | RUN rm -f /tmp/codecrafters-git-target/release/deps/git_starter_rust*
23 | RUN rm -f /tmp/codecrafters-git-target/release/.fingerprint/*git_starter_rust*
24 | RUN rm -f /tmp/codecrafters-git-target/release/.fingerprint/git_starter_rust*
25 |
26 | RUN rm -rf /app/src
27 |
28 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cargo build --release --target-dir=/tmp/codecrafters-git-target --manifest-path Cargo.toml" > /codecrafters-precompile.sh
29 | RUN chmod +x /codecrafters-precompile.sh
30 |
31 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
32 |
--------------------------------------------------------------------------------
/dockerfiles/rust-1.70.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM rust:1.70-buster
2 |
3 | RUN apt-get update && \
4 | apt-get install --no-install-recommends -y git=1:2.* && \
5 | apt-get clean && \
6 | rm -rf /var/lib/apt/lists/*
7 |
8 | COPY Cargo.toml /app/Cargo.toml
9 | COPY Cargo.lock /app/Cargo.lock
10 |
11 | RUN mkdir /app/src
12 | RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs
13 |
14 | WORKDIR /app
15 | RUN cargo build --release --target-dir=/tmp/codecrafters-git-target
16 |
17 | RUN rm /tmp/codecrafters-git-target/release/git-starter-rust
18 | RUN rm /tmp/codecrafters-git-target/release/git-starter-rust.d
19 |
20 | RUN find /tmp/codecrafters-git-target/release -type f -maxdepth 1 -delete
21 | RUN rm -f /tmp/codecrafters-git-target/release/deps/*git_starter_rust*
22 | RUN rm -f /tmp/codecrafters-git-target/release/deps/git_starter_rust*
23 | RUN rm -f /tmp/codecrafters-git-target/release/.fingerprint/*git_starter_rust*
24 | RUN rm -f /tmp/codecrafters-git-target/release/.fingerprint/git_starter_rust*
25 |
26 | RUN rm -rf /app/src
27 |
28 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cargo build --release --target-dir=/tmp/codecrafters-git-target --manifest-path Cargo.toml" > /codecrafters-precompile.sh
29 | RUN chmod +x /codecrafters-precompile.sh
30 |
31 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
32 |
--------------------------------------------------------------------------------
/dockerfiles/rust-1.76.Dockerfile:
--------------------------------------------------------------------------------
1 | FROM rust:1.76-buster
2 |
3 | RUN apt-get update && \
4 | apt-get install --no-install-recommends -y git=1:2.* && \
5 | apt-get clean && \
6 | rm -rf /var/lib/apt/lists/*
7 |
8 | COPY Cargo.toml /app/Cargo.toml
9 | COPY Cargo.lock /app/Cargo.lock
10 |
11 | RUN mkdir /app/src
12 | RUN echo 'fn main() { println!("Hello World!"); }' > /app/src/main.rs
13 |
14 | WORKDIR /app
15 | RUN cargo build --release --target-dir=/tmp/codecrafters-git-target
16 |
17 | RUN rm /tmp/codecrafters-git-target/release/git-starter-rust
18 | RUN rm /tmp/codecrafters-git-target/release/git-starter-rust.d
19 |
20 | RUN find /tmp/codecrafters-git-target/release -type f -maxdepth 1 -delete
21 | RUN rm -f /tmp/codecrafters-git-target/release/deps/*git_starter_rust*
22 | RUN rm -f /tmp/codecrafters-git-target/release/deps/git_starter_rust*
23 | RUN rm -f /tmp/codecrafters-git-target/release/.fingerprint/*git_starter_rust*
24 | RUN rm -f /tmp/codecrafters-git-target/release/.fingerprint/git_starter_rust*
25 |
26 | RUN rm -rf /app/src
27 |
28 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cargo build --release --target-dir=/tmp/codecrafters-git-target --manifest-path Cargo.toml" > /codecrafters-precompile.sh
29 | RUN chmod +x /codecrafters-precompile.sh
30 |
31 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
32 |
--------------------------------------------------------------------------------
/dockerfiles/rust-1.77.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM rust:1.77-buster
3 |
4 | WORKDIR /app
5 |
6 | RUN apt-get update && \
7 | apt-get install --no-install-recommends -y git=1:2.* && \
8 | apt-get clean && \
9 | rm -rf /var/lib/apt/lists/*
10 |
11 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
12 | COPY --exclude=.git --exclude=README.md . /app
13 |
14 | RUN cargo build --release --target-dir=/tmp/codecrafters-git-target
15 |
16 | RUN echo "cd \${CODECRAFTERS_REPOSITORY_DIR} && cargo build --release --target-dir=/tmp/codecrafters-git-target --manifest-path Cargo.toml" > /codecrafters-precompile.sh
17 | RUN chmod +x /codecrafters-precompile.sh
18 |
19 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
20 |
--------------------------------------------------------------------------------
/dockerfiles/rust-1.80.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM rust:1.80-bookworm
3 |
4 | # Rebuild the container if these files change
5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
6 |
7 | WORKDIR /app
8 |
9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10 | COPY --exclude=.git --exclude=README.md . /app
11 |
12 | # This runs cargo build
13 | RUN .codecrafters/compile.sh
14 |
--------------------------------------------------------------------------------
/dockerfiles/rust-1.82.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM rust:1.82-bookworm
3 |
4 | # Rebuild the container if these files change
5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
6 |
7 | WORKDIR /app
8 |
9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10 | COPY --exclude=.git --exclude=README.md . /app
11 |
12 | # This runs cargo build
13 | RUN .codecrafters/compile.sh
14 |
--------------------------------------------------------------------------------
/dockerfiles/rust-1.85.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM rust:1.85-bookworm
3 |
4 | # Rebuild the container if these files change
5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
6 |
7 | WORKDIR /app
8 |
9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10 | COPY --exclude=.git --exclude=README.md . /app
11 |
12 | # This runs cargo build
13 | RUN .codecrafters/compile.sh
14 |
--------------------------------------------------------------------------------
/dockerfiles/rust-1.86.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM rust:1.86-bookworm
3 |
4 | # Rebuild the container if these files change
5 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Cargo.toml,Cargo.lock"
6 |
7 | WORKDIR /app
8 |
9 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
10 | COPY --exclude=.git --exclude=README.md . /app
11 |
12 | # This runs cargo build
13 | RUN .codecrafters/compile.sh
14 |
--------------------------------------------------------------------------------
/dockerfiles/zig-0.12.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM alpine:3.20
3 |
4 | RUN echo "@community http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories
5 |
6 | RUN apk add --no-cache zig@community=0.12.0-r0
7 |
8 | WORKDIR /app
9 |
10 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
11 | COPY --exclude=.git --exclude=README.md . /app
12 |
13 | RUN zig build
14 |
15 | RUN printf "set -e \ncd \${CODECRAFTERS_REPOSITORY_DIR} \necho 'Running zig build' \nzig build \necho 'zig build completed.' \n" > /codecrafters-precompile.sh
16 | RUN chmod +x /codecrafters-precompile.sh
17 |
--------------------------------------------------------------------------------
/dockerfiles/zig-0.14.Dockerfile:
--------------------------------------------------------------------------------
1 | # syntax=docker/dockerfile:1.7-labs
2 | FROM alpine:3.20
3 |
4 | RUN apk add --no-cache 'xz>=5.6' 'curl>=8.9'
5 |
6 | # Download and install Zig
7 | RUN curl -O https://ziglang.org/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz \
8 | && tar -xf zig-linux-x86_64-0.14.0.tar.xz \
9 | && mv zig-linux-x86_64-0.14.0 /usr/local/zig \
10 | && rm zig-linux-x86_64-0.14.0.tar.xz
11 |
12 | # Add Zig to PATH
13 | ENV PATH="/usr/local/zig:${PATH}"
14 |
15 | ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="build.zig,build.zig.zon"
16 |
17 | WORKDIR /app
18 |
19 | # .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses
20 | COPY --exclude=.git --exclude=README.md . /app
21 |
22 | # This runs zig build
23 | RUN .codecrafters/compile.sh
24 |
25 | # Cache build directory
26 | RUN mkdir -p /app-cached
27 | RUN mv /app/.zig-cache /app-cached/.zig-cache || true
28 |
--------------------------------------------------------------------------------
/scripts/check_git_is_unavailable.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -eu
4 |
5 | tag_name() {
6 | dockerfile=$1
7 |
8 | local base
9 | base=$(basename "$dockerfile" .Dockerfile)
10 |
11 | echo "git-tester-${base}"
12 | }
13 |
14 | lang_slug() {
15 | dockerfile=$1
16 |
17 | local base
18 | base=$(basename "$dockerfile" .Dockerfile)
19 |
20 | echo "$base" | cut -d- -f1
21 | }
22 |
23 | in_image() {
24 | local tag="$1"
25 | shift
26 |
27 | docker run --rm "$tag" "$@"
28 | }
29 |
30 | ok=0
31 |
32 | for f in dockerfiles/*.Dockerfile; do
33 | lang=$(lang_slug "$f")
34 | tag=$(tag_name "$f")
35 |
36 | docker build -q -t "$tag" -f "$f" "./starter_templates/$lang/" >/dev/null
37 |
38 | if in_image "$tag" which sh >/dev/null && ! in_image "$tag" which git; then
39 | # ok
40 | echo "ok $f"
41 | else
42 | # found git or something failed in general
43 | ok=1
44 |
45 | echo "fail $f"
46 | fi
47 |
48 | docker rmi "$tag" >/dev/null
49 | done
50 |
51 | if test "$ok" -eq 0; then
52 | echo OK
53 | else
54 | echo FAIL
55 |
56 | exit "$ok"
57 | fi
58 |
59 |
--------------------------------------------------------------------------------
/solutions/c/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
12 | cmake --build ./build
13 |
--------------------------------------------------------------------------------
/solutions/c/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec $(dirname $0)/build/git "$@"
12 |
--------------------------------------------------------------------------------
/solutions/c/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/c/01-gg4/code/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Linker output
11 | *.ilk
12 | *.map
13 | *.exp
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 |
19 | # Libraries
20 | *.lib
21 | *.a
22 | *.la
23 | *.lo
24 |
25 | # Shared objects (inc. Windows DLLs)
26 | *.dll
27 | *.so
28 | *.so.*
29 | *.dylib
30 |
31 | # Executables
32 | *.exe
33 | *.out
34 | *.app
35 | *.i*86
36 | *.x86_64
37 | *.hex
38 |
39 | # Debug files
40 | *.dSYM/
41 | *.su
42 | *.idb
43 | *.pdb
44 |
45 | # Kernel Module Compile Results
46 | *.mod*
47 | *.cmd
48 | .tmp_versions/
49 | modules.order
50 | Module.symvers
51 | Mkfile.old
52 | dkms.conf
53 |
54 | build
55 | vcpkg_installed
--------------------------------------------------------------------------------
/solutions/c/01-gg4/code/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.13)
2 |
3 | project(codecrafters-git)
4 |
5 | file(GLOB_RECURSE SOURCE_FILES src/*.c src/*.h)
6 |
7 | set(CMAKE_C_STANDARD 23) # Enable the C23 standard
8 |
9 | find_package(OpenSSL REQUIRED)
10 | find_package(ZLIB REQUIRED)
11 |
12 | add_executable(git ${SOURCE_FILES})
13 |
14 | target_link_libraries(git PRIVATE OpenSSL::Crypto)
15 | target_link_libraries(git PRIVATE ZLIB::ZLIB)
16 |
--------------------------------------------------------------------------------
/solutions/c/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the C version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: c-23
11 | language_pack: c-23
12 |
--------------------------------------------------------------------------------
/solutions/c/01-gg4/code/src/main.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 |
7 | int main(int argc, char *argv[]) {
8 | // Disable output buffering
9 | setbuf(stdout, NULL);
10 | setbuf(stderr, NULL);
11 |
12 | if (argc < 2) {
13 | fprintf(stderr, "Usage: ./your_program.sh []\n");
14 | return 1;
15 | }
16 |
17 | const char *command = argv[1];
18 |
19 | if (strcmp(command, "init") == 0) {
20 | if (mkdir(".git", 0755) == -1 ||
21 | mkdir(".git/objects", 0755) == -1 ||
22 | mkdir(".git/refs", 0755) == -1) {
23 | fprintf(stderr, "Failed to create directories: %s\n", strerror(errno));
24 | return 1;
25 | }
26 |
27 | FILE *headFile = fopen(".git/HEAD", "w");
28 | if (headFile == NULL) {
29 | fprintf(stderr, "Failed to create .git/HEAD file: %s\n", strerror(errno));
30 | return 1;
31 | }
32 | fprintf(headFile, "ref: refs/heads/main\n");
33 | fclose(headFile);
34 |
35 | printf("Initialized git directory\n");
36 | } else {
37 | fprintf(stderr, "Unknown command %s\n", command);
38 | return 1;
39 | }
40 |
41 | return 0;
42 | }
43 |
--------------------------------------------------------------------------------
/solutions/c/01-gg4/code/vcpkg-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "default-registry": {
3 | "kind": "git",
4 | "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d",
5 | "repository": "https://github.com/microsoft/vcpkg"
6 | },
7 | "registries": [
8 | {
9 | "kind": "artifact",
10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11 | "name": "microsoft"
12 | }
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/solutions/c/01-gg4/code/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": []
3 | }
4 |
--------------------------------------------------------------------------------
/solutions/c/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
18 | cmake --build ./build
19 | )
20 |
21 | # Copied from .codecrafters/run.sh
22 | #
23 | # - Edit this to change how your program runs locally
24 | # - Edit .codecrafters/run.sh to change how your program runs remotely
25 | exec $(dirname $0)/build/git "$@"
26 |
--------------------------------------------------------------------------------
/solutions/c/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `src/main.c`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```c
6 | // Uncomment this block to pass the first stage
7 |
8 | if (mkdir(".git", 0755) == -1 ||
9 | mkdir(".git/objects", 0755) == -1 ||
10 | mkdir(".git/refs", 0755) == -1) {
11 | fprintf(stderr, "Failed to create directories: %s\n", strerror(errno));
12 | return 1;
13 | }
14 |
15 | FILE *headFile = fopen(".git/HEAD", "w");
16 | if (headFile == NULL) {
17 | fprintf(stderr, "Failed to create .git/HEAD file: %s\n", strerror(errno));
18 | return 1;
19 | }
20 | fprintf(headFile, "ref: refs/heads/main\n");
21 | fclose(headFile);
22 |
23 | printf("Initialized git directory\n");
24 | ```
25 |
26 | Push your changes to pass the first stage:
27 |
28 | ```
29 | git add .
30 | git commit -m "pass 1st stage" # any msg
31 | git push origin master
32 | ```
33 |
--------------------------------------------------------------------------------
/solutions/cpp/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
12 | cmake --build ./build
13 |
--------------------------------------------------------------------------------
/solutions/cpp/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec $(dirname "$0")/build/git "$@"
--------------------------------------------------------------------------------
/solutions/cpp/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/cpp/01-gg4/code/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Linker output
11 | *.ilk
12 | *.map
13 | *.exp
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 |
19 | # Libraries
20 | *.lib
21 | *.a
22 | *.la
23 | *.lo
24 |
25 | # Shared objects (inc. Windows DLLs)
26 | *.dll
27 | *.so
28 | *.so.*
29 | *.dylib
30 |
31 | # Executables
32 | *.exe
33 | *.out
34 | *.app
35 | *.i*86
36 | *.x86_64
37 | *.hex
38 |
39 | # Debug files
40 | *.dSYM/
41 | *.su
42 | *.idb
43 | *.pdb
44 |
45 | # Kernel Module Compile Results
46 | *.mod*
47 | *.cmd
48 | .tmp_versions/
49 | modules.order
50 | Module.symvers
51 | Mkfile.old
52 | dkms.conf
53 |
54 | build
55 | vcpkg_installed
--------------------------------------------------------------------------------
/solutions/cpp/01-gg4/code/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.13)
2 |
3 | project(codecrafters-git)
4 |
5 | set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard
6 |
7 | file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp)
8 |
9 | find_package(OpenSSL REQUIRED)
10 | find_package(ZLIB REQUIRED)
11 |
12 | add_executable(git ${SOURCE_FILES})
13 |
14 | target_link_libraries(git PRIVATE OpenSSL::Crypto)
15 | target_link_libraries(git PRIVATE ZLIB::ZLIB)
--------------------------------------------------------------------------------
/solutions/cpp/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the C++ version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: cpp-23
11 | language_pack: cpp-23
12 |
--------------------------------------------------------------------------------
/solutions/cpp/01-gg4/code/src/main.cpp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 |
6 | int main(int argc, char *argv[])
7 | {
8 | // Flush after every std::cout / std::cerr
9 | std::cout << std::unitbuf;
10 | std::cerr << std::unitbuf;
11 |
12 | if (argc < 2) {
13 | std::cerr << "No command provided.\n";
14 | return EXIT_FAILURE;
15 | }
16 |
17 | std::string command = argv[1];
18 |
19 | if (command == "init") {
20 | try {
21 | std::filesystem::create_directory(".git");
22 | std::filesystem::create_directory(".git/objects");
23 | std::filesystem::create_directory(".git/refs");
24 |
25 | std::ofstream headFile(".git/HEAD");
26 | if (headFile.is_open()) {
27 | headFile << "ref: refs/heads/main\n";
28 | headFile.close();
29 | } else {
30 | std::cerr << "Failed to create .git/HEAD file.\n";
31 | return EXIT_FAILURE;
32 | }
33 |
34 | std::cout << "Initialized git directory\n";
35 | } catch (const std::filesystem::filesystem_error& e) {
36 | std::cerr << e.what() << '\n';
37 | return EXIT_FAILURE;
38 | }
39 | } else {
40 | std::cerr << "Unknown command " << command << '\n';
41 | return EXIT_FAILURE;
42 | }
43 |
44 | return EXIT_SUCCESS;
45 | }
46 |
--------------------------------------------------------------------------------
/solutions/cpp/01-gg4/code/vcpkg-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "default-registry": {
3 | "kind": "git",
4 | "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d",
5 | "repository": "https://github.com/microsoft/vcpkg"
6 | },
7 | "registries": [
8 | {
9 | "kind": "artifact",
10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11 | "name": "microsoft"
12 | }
13 | ]
14 | }
--------------------------------------------------------------------------------
/solutions/cpp/01-gg4/code/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": []
3 | }
--------------------------------------------------------------------------------
/solutions/cpp/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
18 | cmake --build ./build
19 | )
20 |
21 | # Copied from .codecrafters/run.sh
22 | #
23 | # - Edit this to change how your program runs locally
24 | # - Edit .codecrafters/run.sh to change how your program runs remotely
25 | exec $(dirname "$0")/build/git "$@"
26 |
--------------------------------------------------------------------------------
/solutions/cpp/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `src/main.cpp`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```cpp
6 | // Uncomment this block to pass the first stage
7 |
8 | if (argc < 2) {
9 | std::cerr << "No command provided.\n";
10 | return EXIT_FAILURE;
11 | }
12 |
13 | std::string command = argv[1];
14 |
15 | if (command == "init") {
16 | try {
17 | std::filesystem::create_directory(".git");
18 | std::filesystem::create_directory(".git/objects");
19 | std::filesystem::create_directory(".git/refs");
20 |
21 | std::ofstream headFile(".git/HEAD");
22 | if (headFile.is_open()) {
23 | headFile << "ref: refs/heads/main\n";
24 | headFile.close();
25 | } else {
26 | std::cerr << "Failed to create .git/HEAD file.\n";
27 | return EXIT_FAILURE;
28 | }
29 |
30 | std::cout << "Initialized git directory\n";
31 | } catch (const std::filesystem::filesystem_error& e) {
32 | std::cerr << e.what() << '\n';
33 | return EXIT_FAILURE;
34 | }
35 | } else {
36 | std::cerr << "Unknown command " << command << '\n';
37 | return EXIT_FAILURE;
38 | }
39 |
40 | return EXIT_SUCCESS;
41 | ```
42 |
43 | Push your changes to pass the first stage:
44 |
45 | ```
46 | git add .
47 | git commit -m "pass 1st stage" # any msg
48 | git push origin master
49 | ```
50 |
--------------------------------------------------------------------------------
/solutions/csharp/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | dotnet build --configuration Release --output /tmp/codecrafters-build-git-csharp codecrafters-git.csproj
12 |
--------------------------------------------------------------------------------
/solutions/csharp/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec /tmp/codecrafters-build-git-csharp/codecrafters-git "$@"
12 |
--------------------------------------------------------------------------------
/solutions/csharp/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/csharp/01-gg4/code/codecrafters-git.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 | codecrafters_git
7 | enable
8 | enable
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/solutions/csharp/01-gg4/code/codecrafters-git.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31903.59
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "codecrafters-git", "codecrafters-git.csproj", "{5647EB94-C939-4AAF-BDC4-807AA270FCF0}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(SolutionProperties) = preSolution
14 | HideSolutionNode = FALSE
15 | EndGlobalSection
16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
17 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.Build.0 = Release|Any CPU
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/solutions/csharp/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the C# version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: dotnet-9.0
11 | language_pack: dotnet-9.0
12 |
--------------------------------------------------------------------------------
/solutions/csharp/01-gg4/code/src/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | if (args.Length < 1)
5 | {
6 | Console.WriteLine("Please provide a command.");
7 | return;
8 | }
9 |
10 | string command = args[0];
11 |
12 | if (command == "init")
13 | {
14 | Directory.CreateDirectory(".git");
15 | Directory.CreateDirectory(".git/objects");
16 | Directory.CreateDirectory(".git/refs");
17 | File.WriteAllText(".git/HEAD", "ref: refs/heads/main\n");
18 | Console.WriteLine("Initialized git directory");
19 | }
20 | else
21 | {
22 | throw new ArgumentException($"Unknown command {command}");
23 | }
--------------------------------------------------------------------------------
/solutions/csharp/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | dotnet build --configuration Release --output /tmp/codecrafters-build-git-csharp codecrafters-git.csproj
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec /tmp/codecrafters-build-git-csharp/codecrafters-git "$@"
25 |
--------------------------------------------------------------------------------
/solutions/csharp/01-gg4/diff/src/Program.cs.diff:
--------------------------------------------------------------------------------
1 | @@ -1,28 +1,23 @@
2 | using System;
3 | using System.IO;
4 |
5 | if (args.Length < 1)
6 | {
7 | Console.WriteLine("Please provide a command.");
8 | return;
9 | }
10 |
11 | -// You can use print statements as follows for debugging, they'll be visible when running tests.
12 | -Console.Error.WriteLine("Logs from your program will appear here!");
13 | -
14 | string command = args[0];
15 |
16 | if (command == "init")
17 | {
18 | - // Uncomment this block to pass the first stage
19 | - //
20 | - // Directory.CreateDirectory(".git");
21 | - // Directory.CreateDirectory(".git/objects");
22 | - // Directory.CreateDirectory(".git/refs");
23 | - // File.WriteAllText(".git/HEAD", "ref: refs/heads/main\n");
24 | - // Console.WriteLine("Initialized git directory");
25 | + Directory.CreateDirectory(".git");
26 | + Directory.CreateDirectory(".git/objects");
27 | + Directory.CreateDirectory(".git/refs");
28 | + File.WriteAllText(".git/HEAD", "ref: refs/heads/main\n");
29 | + Console.WriteLine("Initialized git directory");
30 | }
31 | else
32 | {
33 | throw new ArgumentException($"Unknown command {command}");
34 | }
35 | \ No newline at end of file
36 |
--------------------------------------------------------------------------------
/solutions/csharp/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `src/Program.cs`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```csharp
6 | // Uncomment this block to pass the first stage
7 |
8 | Directory.CreateDirectory(".git");
9 | Directory.CreateDirectory(".git/objects");
10 | Directory.CreateDirectory(".git/refs");
11 | File.WriteAllText(".git/HEAD", "ref: refs/heads/main\n");
12 | Console.WriteLine("Initialized git directory");
13 | ```
14 |
15 | Push your changes to pass the first stage:
16 |
17 | ```
18 | git add .
19 | git commit -m "pass 1st stage" # any msg
20 | git push origin master
21 | ```
22 |
--------------------------------------------------------------------------------
/solutions/go/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | go build -o /tmp/codecrafters-build-git-go app/*.go
12 |
--------------------------------------------------------------------------------
/solutions/go/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec /tmp/codecrafters-build-git-go "$@"
12 |
--------------------------------------------------------------------------------
/solutions/go/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/go/01-gg4/code/app/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "os"
6 | )
7 |
8 | // Usage: your_program.sh ...
9 | func main() {
10 | if len(os.Args) < 2 {
11 | fmt.Fprintf(os.Stderr, "usage: mygit [...]\n")
12 | os.Exit(1)
13 | }
14 |
15 | switch command := os.Args[1]; command {
16 | case "init":
17 | for _, dir := range []string{".git", ".git/objects", ".git/refs"} {
18 | if err := os.MkdirAll(dir, 0755); err != nil {
19 | fmt.Fprintf(os.Stderr, "Error creating directory: %s\n", err)
20 | }
21 | }
22 |
23 | headFileContents := []byte("ref: refs/heads/main\n")
24 | if err := os.WriteFile(".git/HEAD", headFileContents, 0644); err != nil {
25 | fmt.Fprintf(os.Stderr, "Error writing file: %s\n", err)
26 | }
27 |
28 | fmt.Println("Initialized git directory")
29 |
30 | default:
31 | fmt.Fprintf(os.Stderr, "Unknown command %s\n", command)
32 | os.Exit(1)
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/solutions/go/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Go version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: go-1.24
11 | language_pack: go-1.24
12 |
--------------------------------------------------------------------------------
/solutions/go/01-gg4/code/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/codecrafters-io/git-starter-go
2 |
3 | go 1.24.0
4 |
--------------------------------------------------------------------------------
/solutions/go/01-gg4/code/go.sum:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codecrafters-io/build-your-own-git/fde1d49c3b841b8a33b04f8aa0383e5ba1378dbc/solutions/go/01-gg4/code/go.sum
--------------------------------------------------------------------------------
/solutions/go/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | go build -o /tmp/codecrafters-build-git-go app/*.go
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec /tmp/codecrafters-build-git-go "$@"
25 |
--------------------------------------------------------------------------------
/solutions/go/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `app/main.go`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```go
6 | // Uncomment this block to pass the first stage!
7 |
8 | for _, dir := range []string{".git", ".git/objects", ".git/refs"} {
9 | if err := os.MkdirAll(dir, 0755); err != nil {
10 | fmt.Fprintf(os.Stderr, "Error creating directory: %s\n", err)
11 | }
12 | }
13 |
14 | headFileContents := []byte("ref: refs/heads/main\n")
15 | if err := os.WriteFile(".git/HEAD", headFileContents, 0644); err != nil {
16 | fmt.Fprintf(os.Stderr, "Error writing file: %s\n", err)
17 | }
18 |
19 | fmt.Println("Initialized git directory")
20 | ```
21 |
22 | Push your changes to pass the first stage:
23 |
24 | ```
25 | git add .
26 | git commit -m "pass 1st stage" # any msg
27 | git push origin master
28 | ```
29 |
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # This compiles the program into $(stack path --local-install-root)/bin/codecrafters-git-exe.
12 | stack build
13 |
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | stackInstallRoot=$(cd $(dirname "$0") && stack path --local-install-root) # Fetch the path from within the project directory
12 | exec "$stackInstallRoot/bin/codecrafters-git-exe" "$@"
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/code/.gitignore:
--------------------------------------------------------------------------------
1 | codecrafters-git.cabal
2 | *~
3 | dist
4 | dist-*
5 | cabal-dev
6 | *.o
7 | *.hi
8 | *.hie
9 | *.chi
10 | *.chs.h
11 | *.dyn_o
12 | *.dyn_hi
13 | .hpc
14 | .hsenv
15 | .cabal-sandbox/
16 | cabal.sandbox.config
17 | *.prof
18 | *.aux
19 | *.hp
20 | *.eventlog
21 | .stack/
22 | .stack-work/
23 | cabal.project.local
24 | cabal.project.local~
25 | .HTF/
26 | .ghc.environment.*
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/code/app/Main.hs:
--------------------------------------------------------------------------------
1 | {-# LANGUAGE BlockArguments #-}
2 | {-# LANGUAGE OverloadedStrings #-}
3 | {-# OPTIONS_GHC -Wno-unused-top-binds #-}
4 |
5 | module Main (main) where
6 |
7 | import System.Directory (createDirectoryIfMissing)
8 | import System.FilePath ((>))
9 | import System.IO (IOMode (WriteMode), hPutStrLn, withFile, hSetBuffering, stdout, stderr, BufferMode (NoBuffering))
10 |
11 | main :: IO ()
12 | main = do
13 | -- Disable output buffering
14 | hSetBuffering stdout NoBuffering
15 | hSetBuffering stderr NoBuffering
16 |
17 | let createParents = True
18 | createDirectoryIfMissing createParents ".git"
19 | createDirectoryIfMissing createParents (".git" > "objects")
20 | createDirectoryIfMissing createParents (".git" > "refs")
21 | withFile (".git" > "HEAD") WriteMode $ \f -> hPutStrLn f "ref: refs/heads/main"
22 | putStrLn $ "Initialized git directory"
23 |
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Haskell version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: haskell-9.8
11 | language_pack: haskell-9.8
12 |
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/code/package.yaml:
--------------------------------------------------------------------------------
1 | name: codecrafters-git
2 | version: 0.1.0.0
3 | license: BSD3
4 |
5 | dependencies:
6 | - base >= 4.19 && < 5
7 | - bytestring # useful to send bytes over the network
8 | - containers # may help with the database structure and debugging
9 | - cryptonite # dealing with SHA1
10 | - directory # directory manipulations
11 | - filepath # path manipulations
12 | - http-client # http
13 | - http-client-tls # https
14 | - http-types # http
15 | - memory # helpful in sha1 manipulations
16 | - mtl # may help with structuring
17 | - optparse-applicative # may help with command line argument parsing
18 | - time # may help with the expiry function
19 | - word8 # works well with attoparsec
20 | - zlib # zlib compression (git uses it)
21 | # parsing libs
22 | - attoparsec
23 | # testing
24 | - HUnit
25 |
26 | executables:
27 | codecrafters-git-exe:
28 | main: Main.hs
29 | source-dirs: app
30 | ghc-options:
31 | - -threaded
32 | - -rtsopts
33 | - -with-rtsopts=-N
34 |
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/code/stack.yaml:
--------------------------------------------------------------------------------
1 | resolver: lts-23.18
2 |
3 | packages:
4 | - .
5 |
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/code/stack.yaml.lock:
--------------------------------------------------------------------------------
1 | # This file was autogenerated by Stack.
2 | # You should not edit this file by hand.
3 | # For more information, please see the documentation at:
4 | # https://docs.haskellstack.org/en/stable/lock_files
5 |
6 | packages: []
7 | snapshots:
8 | - completed:
9 | sha256: d133abe75e408a407cce3f032c96ac1bbadf474a93b5156ebf4135b53382d56b
10 | size: 683827
11 | url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/18.yaml
12 | original: lts-23.18
13 |
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/code/your_git.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 | (
5 | cd $(dirname "$0")
6 | stack build --copy-bins
7 | )
8 | exec hs-git-clone-exe "$@"
9 |
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | stack build
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | stackInstallRoot=$(cd $(dirname "$0") && stack path --local-install-root) # Fetch the path from within the project directory
25 | exec "$stackInstallRoot/bin/codecrafters-git-exe" "$@"
26 |
--------------------------------------------------------------------------------
/solutions/haskell/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `app/Main.hs`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```haskell
6 | -- Uncomment this block to pass first stage
7 | let createParents = True
8 | createDirectoryIfMissing createParents ".git"
9 | createDirectoryIfMissing createParents (".git" > "objects")
10 | createDirectoryIfMissing createParents (".git" > "refs")
11 | withFile (".git" > "HEAD") WriteMode $ \f -> hPutStrLn f "ref: refs/heads/main"
12 | putStrLn $ "Initialized git directory"
13 | ```
14 |
15 | Push your changes to pass the first stage:
16 |
17 | ```
18 | git add .
19 | git commit -m "pass 1st stage" # any msg
20 | git push origin master
21 | ```
22 |
--------------------------------------------------------------------------------
/solutions/java/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | mvn -B package -Ddir=/tmp/codecrafters-build-git-java
12 |
--------------------------------------------------------------------------------
/solutions/java/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec java -jar /tmp/codecrafters-build-git-java/codecrafters-git.jar "$@"
12 |
--------------------------------------------------------------------------------
/solutions/java/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/java/01-gg4/code/.gitignore:
--------------------------------------------------------------------------------
1 | *.jar
2 | target/
3 | .idea/
4 |
--------------------------------------------------------------------------------
/solutions/java/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Java version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: java-23
11 | language_pack: java-23
12 |
--------------------------------------------------------------------------------
/solutions/java/01-gg4/code/src/main/java/Main.java:
--------------------------------------------------------------------------------
1 | import java.io.File;
2 | import java.io.IOException;
3 | import java.nio.file.Files;
4 |
5 | public class Main {
6 | public static void main(String[] args){
7 | final String command = args[0];
8 |
9 | switch (command) {
10 | case "init" -> {
11 | final File root = new File(".git");
12 | new File(root, "objects").mkdirs();
13 | new File(root, "refs").mkdirs();
14 | final File head = new File(root, "HEAD");
15 |
16 | try {
17 | head.createNewFile();
18 | Files.write(head.toPath(), "ref: refs/heads/main\n".getBytes());
19 | System.out.println("Initialized git directory");
20 | } catch (IOException e) {
21 | throw new RuntimeException(e);
22 | }
23 | }
24 | default -> System.out.println("Unknown command: " + command);
25 | }
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/solutions/java/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | mvn -B package -Ddir=/tmp/codecrafters-build-git-java
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec java -jar /tmp/codecrafters-build-git-java/codecrafters-git.jar "$@"
25 |
--------------------------------------------------------------------------------
/solutions/java/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `src/main/java/Main.java`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```java
6 | // Uncomment this block to pass the first stage
7 |
8 | final String command = args[0];
9 |
10 | switch (command) {
11 | case "init" -> {
12 | final File root = new File(".git");
13 | new File(root, "objects").mkdirs();
14 | new File(root, "refs").mkdirs();
15 | final File head = new File(root, "HEAD");
16 |
17 | try {
18 | head.createNewFile();
19 | Files.write(head.toPath(), "ref: refs/heads/main\n".getBytes());
20 | System.out.println("Initialized git directory");
21 | } catch (IOException e) {
22 | throw new RuntimeException(e);
23 | }
24 | }
25 | default -> System.out.println("Unknown command: " + command);
26 | }
27 | ```
28 |
29 | Push your changes to pass the first stage:
30 |
31 | ```
32 | git add .
33 | git commit -m "pass 1st stage" # any msg
34 | git push origin master
35 | ```
36 |
--------------------------------------------------------------------------------
/solutions/javascript/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since JavaScript programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/solutions/javascript/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec node $(dirname "$0")/app/main.js "$@"
12 |
--------------------------------------------------------------------------------
/solutions/javascript/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/javascript/01-gg4/code/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/solutions/javascript/01-gg4/code/app/main.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const path = require("path");
3 |
4 | const command = process.argv[2];
5 |
6 | switch (command) {
7 | case "init":
8 | createGitDirectory();
9 | break;
10 | default:
11 | throw new Error(`Unknown command ${command}`);
12 | }
13 |
14 | function createGitDirectory() {
15 | fs.mkdirSync(path.join(process.cwd(), ".git"), { recursive: true });
16 | fs.mkdirSync(path.join(process.cwd(), ".git", "objects"), { recursive: true });
17 | fs.mkdirSync(path.join(process.cwd(), ".git", "refs"), { recursive: true });
18 |
19 | fs.writeFileSync(path.join(process.cwd(), ".git", "HEAD"), "ref: refs/heads/main\n");
20 | console.log("Initialized git directory");
21 | }
22 |
--------------------------------------------------------------------------------
/solutions/javascript/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the JavaScript version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: nodejs-21
11 | language_pack: nodejs-21
12 |
--------------------------------------------------------------------------------
/solutions/javascript/01-gg4/code/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codecrafters/build-your-own-git",
3 | "version": "1.0.0",
4 | "lockfileVersion": 3,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "@codecrafters/build-your-own-git",
9 | "version": "1.0.0",
10 | "license": "MIT"
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/solutions/javascript/01-gg4/code/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codecrafters/build-your-own-git",
3 | "version": "1.0.0",
4 | "description": "Build your own Git challenge, from CodeCrafters",
5 | "main": "main.js",
6 | "scripts": {
7 | "dev": "node app/main.js"
8 | },
9 | "keywords": [
10 | "build-your-own-x"
11 | ],
12 | "author": "",
13 | "license": "MIT",
14 | "dependencies": {}
15 | }
--------------------------------------------------------------------------------
/solutions/javascript/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/run.sh
12 | #
13 | # - Edit this to change how your program runs locally
14 | # - Edit .codecrafters/run.sh to change how your program runs remotely
15 | exec node $(dirname "$0")/app/main.js "$@"
16 |
--------------------------------------------------------------------------------
/solutions/javascript/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `app/main.js`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```javascript
6 | // Uncomment this block to pass the first stage
7 | const command = process.argv[2];
8 |
9 | switch (command) {
10 | case "init":
11 | createGitDirectory();
12 | break;
13 | default:
14 | throw new Error(`Unknown command ${command}`);
15 | }
16 |
17 | function createGitDirectory() {
18 | fs.mkdirSync(path.join(process.cwd(), ".git"), { recursive: true });
19 | fs.mkdirSync(path.join(process.cwd(), ".git", "objects"), { recursive: true });
20 | fs.mkdirSync(path.join(process.cwd(), ".git", "refs"), { recursive: true });
21 |
22 | fs.writeFileSync(path.join(process.cwd(), ".git", "HEAD"), "ref: refs/heads/main\n");
23 | console.log("Initialized git directory");
24 | }
25 | ```
26 |
27 | Push your changes to pass the first stage:
28 |
29 | ```
30 | git add .
31 | git commit -m "pass 1st stage" # any msg
32 | git push origin master
33 | ```
34 |
--------------------------------------------------------------------------------
/solutions/kotlin/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | mvn -B package -Ddir=/tmp/codecrafters-build-dir
12 |
--------------------------------------------------------------------------------
/solutions/kotlin/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec java -jar /tmp/codecrafters-build-dir/build-your-own-git.jar "$@"
12 |
--------------------------------------------------------------------------------
/solutions/kotlin/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/kotlin/01-gg4/code/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .idea/
--------------------------------------------------------------------------------
/solutions/kotlin/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Kotlin version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: kotlin-2.0
11 | language_pack: kotlin-2.0
12 |
--------------------------------------------------------------------------------
/solutions/kotlin/01-gg4/code/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | import java.io.File
2 | import kotlin.system.exitProcess
3 |
4 | fun main(args: Array) {
5 | if (args.isEmpty()) {
6 | println("Usage: your_program.sh []")
7 | exitProcess(1)
8 | }
9 |
10 | if (args[0] == "init") {
11 | val gitDir = File(".git")
12 | gitDir.mkdir()
13 | File(gitDir, "objects").mkdir()
14 | File(gitDir, "refs").mkdir()
15 | File(gitDir, "HEAD").writeText("ref: refs/heads/master\n")
16 |
17 | println("Initialized git directory")
18 | } else {
19 | println("Unknown command: ${args[0]}")
20 | exitProcess(1)
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/solutions/kotlin/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | mvn -B package -Ddir=/tmp/codecrafters-build-dir
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec java -jar /tmp/codecrafters-build-dir/build-your-own-git.jar "$@"
25 |
--------------------------------------------------------------------------------
/solutions/kotlin/01-gg4/diff/src/main/kotlin/Main.kt.diff:
--------------------------------------------------------------------------------
1 | @@ -1,27 +1,22 @@
2 | import java.io.File
3 | import kotlin.system.exitProcess
4 |
5 | fun main(args: Array) {
6 | - // You can use print statements as follows for debugging, they'll be visible when running tests.
7 | - System.err.println("Logs from your program will appear here!")
8 | -
9 | if (args.isEmpty()) {
10 | println("Usage: your_program.sh []")
11 | exitProcess(1)
12 | }
13 |
14 | if (args[0] == "init") {
15 | - // Uncomment this block to pass the first stage
16 | - //
17 | - // val gitDir = File(".git")
18 | - // gitDir.mkdir()
19 | - // File(gitDir, "objects").mkdir()
20 | - // File(gitDir, "refs").mkdir()
21 | - // File(gitDir, "HEAD").writeText("ref: refs/heads/master\n")
22 | - //
23 | - // println("Initialized git directory")
24 | + val gitDir = File(".git")
25 | + gitDir.mkdir()
26 | + File(gitDir, "objects").mkdir()
27 | + File(gitDir, "refs").mkdir()
28 | + File(gitDir, "HEAD").writeText("ref: refs/heads/master\n")
29 | +
30 | + println("Initialized git directory")
31 | } else {
32 | println("Unknown command: ${args[0]}")
33 | exitProcess(1)
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/solutions/kotlin/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `src/main/kotlin/Main.kt`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```kotlin
6 | // Uncomment this block to pass the first stage
7 |
8 | val gitDir = File(".git")
9 | gitDir.mkdir()
10 | File(gitDir, "objects").mkdir()
11 | File(gitDir, "refs").mkdir()
12 | File(gitDir, "HEAD").writeText("ref: refs/heads/master\n")
13 |
14 | println("Initialized git directory")
15 | ```
16 |
17 | Push your changes to pass the first stage:
18 |
19 | ```
20 | git add .
21 | git commit -m "pass 1st stage" # any msg
22 | git push origin master
23 | ```
24 |
--------------------------------------------------------------------------------
/solutions/python/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since Python programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/solutions/python/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | PYTHONPATH=$(dirname $0) exec python3 -m app.main "$@"
12 |
--------------------------------------------------------------------------------
/solutions/python/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/python/01-gg4/code/app/main.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 |
4 |
5 | def main():
6 | command = sys.argv[1]
7 | if command == "init":
8 | os.mkdir(".git")
9 | os.mkdir(".git/objects")
10 | os.mkdir(".git/refs")
11 | with open(".git/HEAD", "w") as f:
12 | f.write("ref: refs/heads/main\n")
13 | print("Initialized git directory")
14 | else:
15 | raise RuntimeError(f"Unknown command #{command}")
16 |
17 |
18 | if __name__ == "__main__":
19 | main()
20 |
--------------------------------------------------------------------------------
/solutions/python/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Python version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: python-3.13
11 | language_pack: python-3.13
12 |
--------------------------------------------------------------------------------
/solutions/python/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/run.sh
12 | #
13 | # - Edit this to change how your program runs locally
14 | # - Edit .codecrafters/run.sh to change how your program runs remotely
15 | PYTHONPATH=$(dirname $0) exec python3 -m app.main "$@"
16 |
--------------------------------------------------------------------------------
/solutions/python/01-gg4/diff/app/main.py.diff:
--------------------------------------------------------------------------------
1 | @@ -1,24 +1,19 @@
2 | import sys
3 | import os
4 |
5 |
6 | def main():
7 | - # You can use print statements as follows for debugging, they'll be visible when running tests.
8 | - print("Logs from your program will appear here!", file=sys.stderr)
9 | -
10 | - # Uncomment this block to pass the first stage
11 | - #
12 | - # command = sys.argv[1]
13 | - # if command == "init":
14 | - # os.mkdir(".git")
15 | - # os.mkdir(".git/objects")
16 | - # os.mkdir(".git/refs")
17 | - # with open(".git/HEAD", "w") as f:
18 | - # f.write("ref: refs/heads/main\n")
19 | - # print("Initialized git directory")
20 | - # else:
21 | - # raise RuntimeError(f"Unknown command #{command}")
22 | + command = sys.argv[1]
23 | + if command == "init":
24 | + os.mkdir(".git")
25 | + os.mkdir(".git/objects")
26 | + os.mkdir(".git/refs")
27 | + with open(".git/HEAD", "w") as f:
28 | + f.write("ref: refs/heads/main\n")
29 | + print("Initialized git directory")
30 | + else:
31 | + raise RuntimeError(f"Unknown command #{command}")
32 |
33 |
34 | if __name__ == "__main__":
35 | main()
36 |
--------------------------------------------------------------------------------
/solutions/python/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `app/main.py`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```python
6 | # Uncomment this block to pass the first stage
7 |
8 | command = sys.argv[1]
9 | if command == "init":
10 | os.mkdir(".git")
11 | os.mkdir(".git/objects")
12 | os.mkdir(".git/refs")
13 | with open(".git/HEAD", "w") as f:
14 | f.write("ref: refs/heads/main\n")
15 | print("Initialized git directory")
16 | else:
17 | raise RuntimeError(f"Unknown command #{command}")
18 | ```
19 |
20 | Push your changes to pass the first stage:
21 |
22 | ```
23 | git add .
24 | git commit -m "pass 1st stage" # any msg
25 | git push origin master
26 | ```
27 |
--------------------------------------------------------------------------------
/solutions/ruby/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since Ruby programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/solutions/ruby/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec ruby $(dirname $0)/app/main.rb "$@"
12 |
--------------------------------------------------------------------------------
/solutions/ruby/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/ruby/01-gg4/code/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source "https://rubygems.org"
4 |
5 | # Add gems here if you need to use them.
6 | # Make sure to run `bundle install` before running tests or submitting your code.
7 |
--------------------------------------------------------------------------------
/solutions/ruby/01-gg4/code/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 |
5 | PLATFORMS
6 | aarch64-linux-musl
7 | arm64-darwin-21
8 | arm64-darwin-23
9 | x86_64-linux
10 | ruby
11 |
12 | DEPENDENCIES
13 |
14 | BUNDLED WITH
15 | 2.5.6
16 |
--------------------------------------------------------------------------------
/solutions/ruby/01-gg4/code/app/main.rb:
--------------------------------------------------------------------------------
1 | command = ARGV[0]
2 | case command
3 | when "init"
4 | Dir.mkdir(".git")
5 | Dir.mkdir(".git/objects")
6 | Dir.mkdir(".git/refs")
7 | File.write(".git/HEAD", "ref: refs/heads/main\n")
8 | puts "Initialized git directory"
9 | else
10 | raise RuntimeError.new("Unknown command #{command}")
11 | end
12 |
--------------------------------------------------------------------------------
/solutions/ruby/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Ruby version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: ruby-3.3
11 | language_pack: ruby-3.3
12 |
--------------------------------------------------------------------------------
/solutions/ruby/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/run.sh
12 | #
13 | # - Edit this to change how your program runs locally
14 | # - Edit .codecrafters/run.sh to change how your program runs remotely
15 | exec ruby $(dirname $0)/app/main.rb "$@"
16 |
--------------------------------------------------------------------------------
/solutions/ruby/01-gg4/diff/app/main.rb.diff:
--------------------------------------------------------------------------------
1 | @@ -1,16 +1,11 @@
2 | -# You can use print statements as follows for debugging, they'll be visible when running tests.
3 | -$stderr.puts "Logs from your program will appear here!"
4 | -
5 | -# Uncomment this block to pass the first stage
6 | -#
7 | -# command = ARGV[0]
8 | -# case command
9 | -# when "init"
10 | -# Dir.mkdir(".git")
11 | -# Dir.mkdir(".git/objects")
12 | -# Dir.mkdir(".git/refs")
13 | -# File.write(".git/HEAD", "ref: refs/heads/main\n")
14 | -# puts "Initialized git directory"
15 | -# else
16 | -# raise RuntimeError.new("Unknown command #{command}")
17 | -# end
18 | +command = ARGV[0]
19 | +case command
20 | +when "init"
21 | + Dir.mkdir(".git")
22 | + Dir.mkdir(".git/objects")
23 | + Dir.mkdir(".git/refs")
24 | + File.write(".git/HEAD", "ref: refs/heads/main\n")
25 | + puts "Initialized git directory"
26 | +else
27 | + raise RuntimeError.new("Unknown command #{command}")
28 | +end
29 |
--------------------------------------------------------------------------------
/solutions/ruby/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `app/main.rb`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```ruby
6 | # Uncomment this block to pass the first stage
7 |
8 | command = ARGV[0]
9 | case command
10 | when "init"
11 | Dir.mkdir(".git")
12 | Dir.mkdir(".git/objects")
13 | Dir.mkdir(".git/refs")
14 | File.write(".git/HEAD", "ref: refs/heads/main\n")
15 | puts "Initialized git directory"
16 | else
17 | raise RuntimeError.new("Unknown command #{command}")
18 | end
19 | ```
20 |
21 | Push your changes to pass the first stage:
22 |
23 | ```
24 | git add .
25 | git commit -m "pass 1st stage" # any msg
26 | git push origin master
27 | ```
28 |
--------------------------------------------------------------------------------
/solutions/rust/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | cargo build --release --target-dir=/tmp/codecrafters-build-git-rust --manifest-path Cargo.toml
12 |
--------------------------------------------------------------------------------
/solutions/rust/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec /tmp/codecrafters-build-git-rust/release/codecrafters-git "$@"
12 |
--------------------------------------------------------------------------------
/solutions/rust/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/rust/01-gg4/code/.gitignore:
--------------------------------------------------------------------------------
1 | # Generated by Cargo
2 | # will have compiled files and executables
3 | debug/
4 | target/
5 |
6 | # These are backup files generated by rustfmt
7 | **/*.rs.bk
8 |
9 | # MSVC Windows builds of rustc generate these, which store debugging information
10 | *.pdb
11 |
--------------------------------------------------------------------------------
/solutions/rust/01-gg4/code/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "codecrafters-git"
3 | version = "0.1.0"
4 | authors = ["Codecrafters "]
5 | edition = "2021"
6 | rust-version = "1.80"
7 |
8 | [dependencies]
9 | anyhow = "1.0.68" # error handling
10 | bytes = "1.3.0" # helps manage buffers
11 | flate2 = "1.0.34" # compression
12 | thiserror = "1.0.38" # error handling
13 |
--------------------------------------------------------------------------------
/solutions/rust/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Rust version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: rust-1.86
11 | language_pack: rust-1.86
12 |
--------------------------------------------------------------------------------
/solutions/rust/01-gg4/code/src/main.rs:
--------------------------------------------------------------------------------
1 | #[allow(unused_imports)]
2 | use std::env;
3 | #[allow(unused_imports)]
4 | use std::fs;
5 |
6 | fn main() {
7 | let args: Vec = env::args().collect();
8 | if args[1] == "init" {
9 | fs::create_dir(".git").unwrap();
10 | fs::create_dir(".git/objects").unwrap();
11 | fs::create_dir(".git/refs").unwrap();
12 | fs::write(".git/HEAD", "ref: refs/heads/main\n").unwrap();
13 | println!("Initialized git directory")
14 | } else {
15 | println!("unknown command: {}", args[1])
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/solutions/rust/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | cargo build --release --target-dir=/tmp/codecrafters-build-git-rust --manifest-path Cargo.toml
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec /tmp/codecrafters-build-git-rust/release/codecrafters-git "$@"
25 |
--------------------------------------------------------------------------------
/solutions/rust/01-gg4/diff/src/main.rs.diff:
--------------------------------------------------------------------------------
1 | @@ -1,21 +1,17 @@
2 | #[allow(unused_imports)]
3 | use std::env;
4 | #[allow(unused_imports)]
5 | use std::fs;
6 |
7 | fn main() {
8 | - // You can use print statements as follows for debugging, they'll be visible when running tests.
9 | - eprintln!("Logs from your program will appear here!");
10 | -
11 | - // Uncomment this block to pass the first stage
12 | - // let args: Vec = env::args().collect();
13 | - // if args[1] == "init" {
14 | - // fs::create_dir(".git").unwrap();
15 | - // fs::create_dir(".git/objects").unwrap();
16 | - // fs::create_dir(".git/refs").unwrap();
17 | - // fs::write(".git/HEAD", "ref: refs/heads/main\n").unwrap();
18 | - // println!("Initialized git directory")
19 | - // } else {
20 | - // println!("unknown command: {}", args[1])
21 | - // }
22 | + let args: Vec = env::args().collect();
23 | + if args[1] == "init" {
24 | + fs::create_dir(".git").unwrap();
25 | + fs::create_dir(".git/objects").unwrap();
26 | + fs::create_dir(".git/refs").unwrap();
27 | + fs::write(".git/HEAD", "ref: refs/heads/main\n").unwrap();
28 | + println!("Initialized git directory")
29 | + } else {
30 | + println!("unknown command: {}", args[1])
31 | + }
32 | }
33 |
--------------------------------------------------------------------------------
/solutions/rust/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `src/main.rs`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```rust
6 | // Uncomment this block to pass the first stage
7 | let args: Vec = env::args().collect();
8 | if args[1] == "init" {
9 | fs::create_dir(".git").unwrap();
10 | fs::create_dir(".git/objects").unwrap();
11 | fs::create_dir(".git/refs").unwrap();
12 | fs::write(".git/HEAD", "ref: refs/heads/main\n").unwrap();
13 | println!("Initialized git directory")
14 | } else {
15 | println!("unknown command: {}", args[1])
16 | }
17 | ```
18 |
19 | Push your changes to pass the first stage:
20 |
21 | ```
22 | git add .
23 | git commit -m "pass 1st stage" # any msg
24 | git push origin master
25 | ```
26 |
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since TypeScript programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec bun run $(dirname $0)/app/main.ts "$@"
12 |
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/code/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/code/app/main.ts:
--------------------------------------------------------------------------------
1 | import * as fs from 'fs';
2 |
3 | const args = process.argv.slice(2);
4 | const command = args[0];
5 |
6 | switch (command) {
7 | case "init":
8 | fs.mkdirSync(".git", { recursive: true });
9 | fs.mkdirSync(".git/objects", { recursive: true });
10 | fs.mkdirSync(".git/refs", { recursive: true });
11 | fs.writeFileSync(".git/HEAD", "ref: refs/heads/main\n");
12 | console.log("Initialized git directory");
13 | break;
14 | default:
15 | throw new Error(`Unknown command ${command}`);
16 | }
17 |
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/code/bun.lockb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codecrafters-io/build-your-own-git/fde1d49c3b841b8a33b04f8aa0383e5ba1378dbc/solutions/typescript/01-gg4/code/bun.lockb
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the TypeScript version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: bun-1.2
11 | language_pack: bun-1.2
12 |
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/code/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codecrafters/git",
3 | "description": "Build your own Git challenge, from CodeCrafters",
4 | "type": "module",
5 | "scripts": {
6 | "dev": "bun run app/main.ts"
7 | },
8 | "devDependencies": {
9 | "@types/bun": "latest"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/code/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | // Enable latest features
4 | "lib": ["ESNext", "DOM"],
5 | "target": "ESNext",
6 | "module": "ESNext",
7 | "moduleDetection": "force",
8 | "jsx": "react-jsx",
9 | "allowJs": true,
10 |
11 | // Bundler mode
12 | "moduleResolution": "bundler",
13 | "allowImportingTsExtensions": true,
14 | "verbatimModuleSyntax": true,
15 | "noEmit": true,
16 |
17 | // Best practices
18 | "strict": true,
19 | "skipLibCheck": true,
20 | "noFallthroughCasesInSwitch": true,
21 |
22 | // Some stricter flags (disabled by default)
23 | "noUnusedLocals": false,
24 | "noUnusedParameters": false,
25 | "noPropertyAccessFromIndexSignature": false
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/run.sh
12 | #
13 | # - Edit this to change how your program runs locally
14 | # - Edit .codecrafters/run.sh to change how your program runs remotely
15 | exec bun run $(dirname $0)/app/main.ts "$@"
16 |
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/diff/app/main.ts.diff:
--------------------------------------------------------------------------------
1 | @@ -1,20 +1,16 @@
2 | import * as fs from 'fs';
3 |
4 | const args = process.argv.slice(2);
5 | const command = args[0];
6 |
7 | switch (command) {
8 | case "init":
9 | - // You can use print statements as follows for debugging, they'll be visible when running tests.
10 | - console.error("Logs from your program will appear here!");
11 | -
12 | - // Uncomment this block to pass the first stage
13 | - // fs.mkdirSync(".git", { recursive: true });
14 | - // fs.mkdirSync(".git/objects", { recursive: true });
15 | - // fs.mkdirSync(".git/refs", { recursive: true });
16 | - // fs.writeFileSync(".git/HEAD", "ref: refs/heads/main\n");
17 | - // console.log("Initialized git directory");
18 | + fs.mkdirSync(".git", { recursive: true });
19 | + fs.mkdirSync(".git/objects", { recursive: true });
20 | + fs.mkdirSync(".git/refs", { recursive: true });
21 | + fs.writeFileSync(".git/HEAD", "ref: refs/heads/main\n");
22 | + console.log("Initialized git directory");
23 | break;
24 | default:
25 | throw new Error(`Unknown command ${command}`);
26 | }
27 |
--------------------------------------------------------------------------------
/solutions/typescript/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `app/main.ts`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```typescript
6 | // Uncomment this block to pass the first stage
7 | fs.mkdirSync(".git", { recursive: true });
8 | fs.mkdirSync(".git/objects", { recursive: true });
9 | fs.mkdirSync(".git/refs", { recursive: true });
10 | fs.writeFileSync(".git/HEAD", "ref: refs/heads/main\n");
11 | console.log("Initialized git directory");
12 | ```
13 |
14 | Push your changes to pass the first stage:
15 |
16 | ```
17 | git add .
18 | git commit -m "pass 1st stage" # any msg
19 | git push origin master
20 | ```
21 |
--------------------------------------------------------------------------------
/solutions/zig/01-gg4/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | zig build
12 |
--------------------------------------------------------------------------------
/solutions/zig/01-gg4/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec $(dirname $0)/zig-out/bin/main "$@"
12 |
--------------------------------------------------------------------------------
/solutions/zig/01-gg4/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/solutions/zig/01-gg4/code/.gitignore:
--------------------------------------------------------------------------------
1 | # Zig build artifacts
2 | main
3 | zig-cache/
4 | .zig-cache/
5 | zig-out/
6 |
7 | # Compiled binary output
8 | bin/
9 | !bin/.gitkeep
10 |
11 | # Ignore any .o or .h files generated during build
12 | *.o
13 | *.h
14 |
15 | # Ignore OS and editor specific files
16 | **/.DS_Store
17 | *.swp
18 | *~
19 |
--------------------------------------------------------------------------------
/solutions/zig/01-gg4/code/build.zig:
--------------------------------------------------------------------------------
1 | const std = @import("std");
2 |
3 | // Learn more about this file here: https://ziglang.org/learn/build-system
4 | pub fn build(b: *std.Build) void {
5 | const exe = b.addExecutable(.{
6 | .name = "main",
7 | .root_source_file = b.path("src/main.zig"),
8 | .target = b.standardTargetOptions(.{}),
9 | .optimize = b.standardOptimizeOption(.{}),
10 | });
11 |
12 | // This declares intent for the executable to be installed into the
13 | // standard location when the user invokes the "install" step (the default
14 | // step when running `zig build`).
15 | b.installArtifact(exe);
16 |
17 | // This *creates* a Run step in the build graph, to be executed when another
18 | // step is evaluated that depends on it. The next line below will establish
19 | // such a dependency.
20 | const run_cmd = b.addRunArtifact(exe);
21 |
22 | // This creates a build step. It will be visible in the `zig build --help` menu,
23 | // and can be selected like this: `zig build run`
24 | // This will evaluate the `run` step rather than the default, which is "install".
25 | const run_step = b.step("run", "Run the app");
26 | run_step.dependOn(&run_cmd.step);
27 |
28 | // This allows the user to pass arguments to the application in the build
29 | // command itself, like this: `zig build run -- arg1 arg2 etc`
30 | if (b.args) |args| {
31 | run_cmd.addArgs(args);
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/solutions/zig/01-gg4/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the Zig version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: zig-0.14
11 | language_pack: zig-0.14
12 |
--------------------------------------------------------------------------------
/solutions/zig/01-gg4/code/src/main.zig:
--------------------------------------------------------------------------------
1 | const std = @import("std");
2 | const stdout = std.io.getStdOut().writer();
3 |
4 | pub fn main() !void {
5 | var gpa = std.heap.GeneralPurposeAllocator(.{}){};
6 | defer _ = gpa.deinit();
7 | const allocator = gpa.allocator();
8 |
9 | const args = try std.process.argsAlloc(allocator);
10 | defer std.process.argsFree(allocator, args);
11 |
12 | if (args.len < 2) {
13 | try std.io.getStdErr().writer().print("Usage: {s} \n", .{args[0]});
14 | return;
15 | }
16 |
17 | const command: []const u8 = args[1];
18 |
19 | if (std.mem.eql(u8, command, "init")) {
20 | const cwd = std.fs.cwd();
21 | _ = try cwd.makeDir("./.git");
22 | _ = try cwd.makeDir("./.git/objects");
23 | _ = try cwd.makeDir("./.git/refs");
24 | {
25 | const head = try cwd.createFile("./.git/HEAD", .{});
26 | defer head.close();
27 | _ = try head.write("ref: refs/heads/main\n");
28 | }
29 | _ = try stdout.print("Initialized git directory\n", .{});
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/solutions/zig/01-gg4/code/your_program.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # Use this script to run your program LOCALLY.
4 | #
5 | # Note: Changing this script WILL NOT affect how CodeCrafters runs your program.
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit early if any commands fail
10 |
11 | # Copied from .codecrafters/compile.sh
12 | #
13 | # - Edit this to change how your program compiles locally
14 | # - Edit .codecrafters/compile.sh to change how your program compiles remotely
15 | (
16 | cd "$(dirname "$0")" # Ensure compile steps are run within the repository directory
17 | zig build
18 | )
19 |
20 | # Copied from .codecrafters/run.sh
21 | #
22 | # - Edit this to change how your program runs locally
23 | # - Edit .codecrafters/run.sh to change how your program runs remotely
24 | exec $(dirname $0)/zig-out/bin/main "$@"
25 |
--------------------------------------------------------------------------------
/solutions/zig/01-gg4/explanation.md:
--------------------------------------------------------------------------------
1 | The entry point for your Git implementation is in `src/main.zig`.
2 |
3 | Study and uncomment the relevant code:
4 |
5 | ```zig
6 | // Uncomment this block to pass the first stage
7 | const cwd = std.fs.cwd();
8 | _ = try cwd.makeDir("./.git");
9 | _ = try cwd.makeDir("./.git/objects");
10 | _ = try cwd.makeDir("./.git/refs");
11 | {
12 | const head = try cwd.createFile("./.git/HEAD", .{});
13 | defer head.close();
14 | _ = try head.write("ref: refs/heads/main\n");
15 | }
16 | _ = try stdout.print("Initialized git directory\n", .{});
17 | ```
18 |
19 | Push your changes to pass the first stage:
20 |
21 | ```
22 | git add .
23 | git commit -m "pass 1st stage" # any msg
24 | git push origin master
25 | ```
26 |
--------------------------------------------------------------------------------
/starter_templates/all/code/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto
2 |
--------------------------------------------------------------------------------
/starter_templates/all/code/codecrafters.yml:
--------------------------------------------------------------------------------
1 | # Set this to true if you want debug logs.
2 | #
3 | # These can be VERY verbose, so we suggest turning them off
4 | # unless you really need them.
5 | debug: false
6 |
7 | # Use this to change the {{language_name}} version used to run your code
8 | # on Codecrafters.
9 | #
10 | # Available versions: {{language_pack_with_version}}
11 | language_pack: {{language_pack_with_version}}
12 |
--------------------------------------------------------------------------------
/starter_templates/c/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
12 | cmake --build ./build
13 |
--------------------------------------------------------------------------------
/starter_templates/c/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec $(dirname $0)/build/git "$@"
12 |
--------------------------------------------------------------------------------
/starter_templates/c/code/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Linker output
11 | *.ilk
12 | *.map
13 | *.exp
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 |
19 | # Libraries
20 | *.lib
21 | *.a
22 | *.la
23 | *.lo
24 |
25 | # Shared objects (inc. Windows DLLs)
26 | *.dll
27 | *.so
28 | *.so.*
29 | *.dylib
30 |
31 | # Executables
32 | *.exe
33 | *.out
34 | *.app
35 | *.i*86
36 | *.x86_64
37 | *.hex
38 |
39 | # Debug files
40 | *.dSYM/
41 | *.su
42 | *.idb
43 | *.pdb
44 |
45 | # Kernel Module Compile Results
46 | *.mod*
47 | *.cmd
48 | .tmp_versions/
49 | modules.order
50 | Module.symvers
51 | Mkfile.old
52 | dkms.conf
53 |
54 | build
55 | vcpkg_installed
--------------------------------------------------------------------------------
/starter_templates/c/code/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.13)
2 |
3 | project(codecrafters-git)
4 |
5 | file(GLOB_RECURSE SOURCE_FILES src/*.c src/*.h)
6 |
7 | set(CMAKE_C_STANDARD 23) # Enable the C23 standard
8 |
9 | find_package(OpenSSL REQUIRED)
10 | find_package(ZLIB REQUIRED)
11 |
12 | add_executable(git ${SOURCE_FILES})
13 |
14 | target_link_libraries(git PRIVATE OpenSSL::Crypto)
15 | target_link_libraries(git PRIVATE ZLIB::ZLIB)
16 |
--------------------------------------------------------------------------------
/starter_templates/c/code/vcpkg-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "default-registry": {
3 | "kind": "git",
4 | "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d",
5 | "repository": "https://github.com/microsoft/vcpkg"
6 | },
7 | "registries": [
8 | {
9 | "kind": "artifact",
10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11 | "name": "microsoft"
12 | }
13 | ]
14 | }
15 |
--------------------------------------------------------------------------------
/starter_templates/c/code/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": []
3 | }
4 |
--------------------------------------------------------------------------------
/starter_templates/c/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: "gcc"
3 | user_editable_file: "src/main.c"
4 |
--------------------------------------------------------------------------------
/starter_templates/cpp/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | cmake -B build -S . -DCMAKE_TOOLCHAIN_FILE=${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake
12 | cmake --build ./build
13 |
--------------------------------------------------------------------------------
/starter_templates/cpp/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec $(dirname "$0")/build/git "$@"
--------------------------------------------------------------------------------
/starter_templates/cpp/code/.gitignore:
--------------------------------------------------------------------------------
1 | # Prerequisites
2 | *.d
3 |
4 | # Object files
5 | *.o
6 | *.ko
7 | *.obj
8 | *.elf
9 |
10 | # Linker output
11 | *.ilk
12 | *.map
13 | *.exp
14 |
15 | # Precompiled Headers
16 | *.gch
17 | *.pch
18 |
19 | # Libraries
20 | *.lib
21 | *.a
22 | *.la
23 | *.lo
24 |
25 | # Shared objects (inc. Windows DLLs)
26 | *.dll
27 | *.so
28 | *.so.*
29 | *.dylib
30 |
31 | # Executables
32 | *.exe
33 | *.out
34 | *.app
35 | *.i*86
36 | *.x86_64
37 | *.hex
38 |
39 | # Debug files
40 | *.dSYM/
41 | *.su
42 | *.idb
43 | *.pdb
44 |
45 | # Kernel Module Compile Results
46 | *.mod*
47 | *.cmd
48 | .tmp_versions/
49 | modules.order
50 | Module.symvers
51 | Mkfile.old
52 | dkms.conf
53 |
54 | build
55 | vcpkg_installed
--------------------------------------------------------------------------------
/starter_templates/cpp/code/CMakeLists.txt:
--------------------------------------------------------------------------------
1 | cmake_minimum_required(VERSION 3.13)
2 |
3 | project(codecrafters-git)
4 |
5 | set(CMAKE_CXX_STANDARD 23) # Enable the C++23 standard
6 |
7 | file(GLOB_RECURSE SOURCE_FILES src/*.cpp src/*.hpp)
8 |
9 | find_package(OpenSSL REQUIRED)
10 | find_package(ZLIB REQUIRED)
11 |
12 | add_executable(git ${SOURCE_FILES})
13 |
14 | target_link_libraries(git PRIVATE OpenSSL::Crypto)
15 | target_link_libraries(git PRIVATE ZLIB::ZLIB)
--------------------------------------------------------------------------------
/starter_templates/cpp/code/vcpkg-configuration.json:
--------------------------------------------------------------------------------
1 | {
2 | "default-registry": {
3 | "kind": "git",
4 | "baseline": "c4af3593e1f1aa9e14a560a09e45ea2cb0dfd74d",
5 | "repository": "https://github.com/microsoft/vcpkg"
6 | },
7 | "registries": [
8 | {
9 | "kind": "artifact",
10 | "location": "https://github.com/microsoft/vcpkg-ce-catalog/archive/refs/heads/main.zip",
11 | "name": "microsoft"
12 | }
13 | ]
14 | }
--------------------------------------------------------------------------------
/starter_templates/cpp/code/vcpkg.json:
--------------------------------------------------------------------------------
1 | {
2 | "dependencies": []
3 | }
--------------------------------------------------------------------------------
/starter_templates/cpp/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: cmake
3 | user_editable_file: src/main.cpp
4 |
--------------------------------------------------------------------------------
/starter_templates/csharp/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | dotnet build --configuration Release --output /tmp/codecrafters-build-git-csharp codecrafters-git.csproj
12 |
--------------------------------------------------------------------------------
/starter_templates/csharp/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec /tmp/codecrafters-build-git-csharp/codecrafters-git "$@"
12 |
--------------------------------------------------------------------------------
/starter_templates/csharp/code/codecrafters-git.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 | codecrafters_git
7 | enable
8 | enable
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/starter_templates/csharp/code/codecrafters-git.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 17
4 | VisualStudioVersion = 17.0.31903.59
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "codecrafters-git", "codecrafters-git.csproj", "{5647EB94-C939-4AAF-BDC4-807AA270FCF0}"
7 | EndProject
8 | Global
9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 | Debug|Any CPU = Debug|Any CPU
11 | Release|Any CPU = Release|Any CPU
12 | EndGlobalSection
13 | GlobalSection(SolutionProperties) = preSolution
14 | HideSolutionNode = FALSE
15 | EndGlobalSection
16 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
17 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
18 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
19 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
20 | {5647EB94-C939-4AAF-BDC4-807AA270FCF0}.Release|Any CPU.Build.0 = Release|Any CPU
21 | EndGlobalSection
22 | EndGlobal
23 |
--------------------------------------------------------------------------------
/starter_templates/csharp/code/src/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.IO;
3 |
4 | if (args.Length < 1)
5 | {
6 | Console.WriteLine("Please provide a command.");
7 | return;
8 | }
9 |
10 | // You can use print statements as follows for debugging, they'll be visible when running tests.
11 | Console.Error.WriteLine("Logs from your program will appear here!");
12 |
13 | string command = args[0];
14 |
15 | if (command == "init")
16 | {
17 | // Uncomment this block to pass the first stage
18 | //
19 | // Directory.CreateDirectory(".git");
20 | // Directory.CreateDirectory(".git/objects");
21 | // Directory.CreateDirectory(".git/refs");
22 | // File.WriteAllText(".git/HEAD", "ref: refs/heads/main\n");
23 | // Console.WriteLine("Initialized git directory");
24 | }
25 | else
26 | {
27 | throw new ArgumentException($"Unknown command {command}");
28 | }
--------------------------------------------------------------------------------
/starter_templates/csharp/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: dotnet (9.0)
3 | user_editable_file: src/Program.cs
4 |
--------------------------------------------------------------------------------
/starter_templates/go/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | go build -o /tmp/codecrafters-build-git-go app/*.go
12 |
--------------------------------------------------------------------------------
/starter_templates/go/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec /tmp/codecrafters-build-git-go "$@"
12 |
--------------------------------------------------------------------------------
/starter_templates/go/code/app/main.go:
--------------------------------------------------------------------------------
1 | package main
2 |
3 | import (
4 | "fmt"
5 | "os"
6 | )
7 |
8 | // Usage: your_program.sh ...
9 | func main() {
10 | // You can use print statements as follows for debugging, they'll be visible when running tests.
11 | fmt.Fprintf(os.Stderr, "Logs from your program will appear here!\n")
12 |
13 | if len(os.Args) < 2 {
14 | fmt.Fprintf(os.Stderr, "usage: mygit [...]\n")
15 | os.Exit(1)
16 | }
17 |
18 | switch command := os.Args[1]; command {
19 | case "init":
20 | // Uncomment this block to pass the first stage!
21 | //
22 | // for _, dir := range []string{".git", ".git/objects", ".git/refs"} {
23 | // if err := os.MkdirAll(dir, 0755); err != nil {
24 | // fmt.Fprintf(os.Stderr, "Error creating directory: %s\n", err)
25 | // }
26 | // }
27 | //
28 | // headFileContents := []byte("ref: refs/heads/main\n")
29 | // if err := os.WriteFile(".git/HEAD", headFileContents, 0644); err != nil {
30 | // fmt.Fprintf(os.Stderr, "Error writing file: %s\n", err)
31 | // }
32 | //
33 | // fmt.Println("Initialized git directory")
34 |
35 | default:
36 | fmt.Fprintf(os.Stderr, "Unknown command %s\n", command)
37 | os.Exit(1)
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/starter_templates/go/code/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/codecrafters-io/git-starter-go
2 |
3 | go 1.24.0
4 |
--------------------------------------------------------------------------------
/starter_templates/go/code/go.sum:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codecrafters-io/build-your-own-git/fde1d49c3b841b8a33b04f8aa0383e5ba1378dbc/starter_templates/go/code/go.sum
--------------------------------------------------------------------------------
/starter_templates/go/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: go (1.24)
3 | user_editable_file: app/main.go
4 |
--------------------------------------------------------------------------------
/starter_templates/haskell/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # This compiles the program into $(stack path --local-install-root)/bin/codecrafters-git-exe.
12 | stack build
13 |
--------------------------------------------------------------------------------
/starter_templates/haskell/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | stackInstallRoot=$(cd $(dirname "$0") && stack path --local-install-root) # Fetch the path from within the project directory
12 | exec "$stackInstallRoot/bin/codecrafters-git-exe" "$@"
--------------------------------------------------------------------------------
/starter_templates/haskell/code/.gitignore:
--------------------------------------------------------------------------------
1 | codecrafters-git.cabal
2 | *~
3 | dist
4 | dist-*
5 | cabal-dev
6 | *.o
7 | *.hi
8 | *.hie
9 | *.chi
10 | *.chs.h
11 | *.dyn_o
12 | *.dyn_hi
13 | .hpc
14 | .hsenv
15 | .cabal-sandbox/
16 | cabal.sandbox.config
17 | *.prof
18 | *.aux
19 | *.hp
20 | *.eventlog
21 | .stack/
22 | .stack-work/
23 | cabal.project.local
24 | cabal.project.local~
25 | .HTF/
26 | .ghc.environment.*
--------------------------------------------------------------------------------
/starter_templates/haskell/code/app/Main.hs:
--------------------------------------------------------------------------------
1 | {-# LANGUAGE BlockArguments #-}
2 | {-# LANGUAGE OverloadedStrings #-}
3 | {-# OPTIONS_GHC -Wno-unused-top-binds #-}
4 |
5 | module Main (main) where
6 |
7 | import System.Directory (createDirectoryIfMissing)
8 | import System.FilePath ((>))
9 | import System.IO (IOMode (WriteMode), hPutStrLn, withFile, hSetBuffering, stdout, stderr, BufferMode (NoBuffering))
10 |
11 | main :: IO ()
12 | main = do
13 | -- Disable output buffering
14 | hSetBuffering stdout NoBuffering
15 | hSetBuffering stderr NoBuffering
16 |
17 | -- You can use print statements as follows for debugging, they'll be visible when running tests.
18 | hPutStrLn stderr "Logs from your program will appear here"
19 |
20 | -- Uncomment this block to pass first stage
21 | -- let createParents = True
22 | -- createDirectoryIfMissing createParents ".git"
23 | -- createDirectoryIfMissing createParents (".git" > "objects")
24 | -- createDirectoryIfMissing createParents (".git" > "refs")
25 | -- withFile (".git" > "HEAD") WriteMode $ \f -> hPutStrLn f "ref: refs/heads/main"
26 | -- putStrLn $ "Initialized git directory"
27 |
--------------------------------------------------------------------------------
/starter_templates/haskell/code/package.yaml:
--------------------------------------------------------------------------------
1 | name: codecrafters-git
2 | version: 0.1.0.0
3 | license: BSD3
4 |
5 | dependencies:
6 | - base >= 4.19 && < 5
7 | - bytestring # useful to send bytes over the network
8 | - containers # may help with the database structure and debugging
9 | - cryptonite # dealing with SHA1
10 | - directory # directory manipulations
11 | - filepath # path manipulations
12 | - http-client # http
13 | - http-client-tls # https
14 | - http-types # http
15 | - memory # helpful in sha1 manipulations
16 | - mtl # may help with structuring
17 | - optparse-applicative # may help with command line argument parsing
18 | - time # may help with the expiry function
19 | - word8 # works well with attoparsec
20 | - zlib # zlib compression (git uses it)
21 | # parsing libs
22 | - attoparsec
23 | # testing
24 | - HUnit
25 |
26 | executables:
27 | codecrafters-git-exe:
28 | main: Main.hs
29 | source-dirs: app
30 | ghc-options:
31 | - -threaded
32 | - -rtsopts
33 | - -with-rtsopts=-N
34 |
--------------------------------------------------------------------------------
/starter_templates/haskell/code/stack.yaml:
--------------------------------------------------------------------------------
1 | resolver: lts-23.18
2 |
3 | packages:
4 | - .
5 |
--------------------------------------------------------------------------------
/starter_templates/haskell/code/stack.yaml.lock:
--------------------------------------------------------------------------------
1 | # This file was autogenerated by Stack.
2 | # You should not edit this file by hand.
3 | # For more information, please see the documentation at:
4 | # https://docs.haskellstack.org/en/stable/lock_files
5 |
6 | packages: []
7 | snapshots:
8 | - completed:
9 | sha256: d133abe75e408a407cce3f032c96ac1bbadf474a93b5156ebf4135b53382d56b
10 | size: 683827
11 | url: https://raw.githubusercontent.com/commercialhaskell/stackage-snapshots/master/lts/23/18.yaml
12 | original: lts-23.18
13 |
--------------------------------------------------------------------------------
/starter_templates/haskell/code/your_git.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | set -e
4 | (
5 | cd $(dirname "$0")
6 | stack build --copy-bins
7 | )
8 | exec hs-git-clone-exe "$@"
9 |
--------------------------------------------------------------------------------
/starter_templates/haskell/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: stack (23.18)
3 | user_editable_file: app/Main.hs
4 |
--------------------------------------------------------------------------------
/starter_templates/java/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | mvn -B package -Ddir=/tmp/codecrafters-build-git-java
12 |
--------------------------------------------------------------------------------
/starter_templates/java/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec java -jar /tmp/codecrafters-build-git-java/codecrafters-git.jar "$@"
12 |
--------------------------------------------------------------------------------
/starter_templates/java/code/.gitignore:
--------------------------------------------------------------------------------
1 | *.jar
2 | target/
3 | .idea/
4 |
--------------------------------------------------------------------------------
/starter_templates/java/code/src/main/java/Main.java:
--------------------------------------------------------------------------------
1 | import java.io.File;
2 | import java.io.IOException;
3 | import java.nio.file.Files;
4 |
5 | public class Main {
6 | public static void main(String[] args){
7 | // You can use print statements as follows for debugging, they'll be visible when running tests.
8 | System.err.println("Logs from your program will appear here!");
9 |
10 | // Uncomment this block to pass the first stage
11 | //
12 | // final String command = args[0];
13 | //
14 | // switch (command) {
15 | // case "init" -> {
16 | // final File root = new File(".git");
17 | // new File(root, "objects").mkdirs();
18 | // new File(root, "refs").mkdirs();
19 | // final File head = new File(root, "HEAD");
20 | //
21 | // try {
22 | // head.createNewFile();
23 | // Files.write(head.toPath(), "ref: refs/heads/main\n".getBytes());
24 | // System.out.println("Initialized git directory");
25 | // } catch (IOException e) {
26 | // throw new RuntimeException(e);
27 | // }
28 | // }
29 | // default -> System.out.println("Unknown command: " + command);
30 | // }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/starter_templates/java/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: mvn
3 | user_editable_file: src/main/java/Main.java
4 |
--------------------------------------------------------------------------------
/starter_templates/javascript/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since JavaScript programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/starter_templates/javascript/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec node $(dirname "$0")/app/main.js "$@"
12 |
--------------------------------------------------------------------------------
/starter_templates/javascript/code/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/starter_templates/javascript/code/app/main.js:
--------------------------------------------------------------------------------
1 | const fs = require("fs");
2 | const path = require("path");
3 |
4 | // You can use print statements as follows for debugging, they'll be visible when running tests.
5 | console.error("Logs from your program will appear here!");
6 |
7 | // Uncomment this block to pass the first stage
8 | // const command = process.argv[2];
9 | //
10 | // switch (command) {
11 | // case "init":
12 | // createGitDirectory();
13 | // break;
14 | // default:
15 | // throw new Error(`Unknown command ${command}`);
16 | // }
17 | //
18 | // function createGitDirectory() {
19 | // fs.mkdirSync(path.join(process.cwd(), ".git"), { recursive: true });
20 | // fs.mkdirSync(path.join(process.cwd(), ".git", "objects"), { recursive: true });
21 | // fs.mkdirSync(path.join(process.cwd(), ".git", "refs"), { recursive: true });
22 | //
23 | // fs.writeFileSync(path.join(process.cwd(), ".git", "HEAD"), "ref: refs/heads/main\n");
24 | // console.log("Initialized git directory");
25 | // }
26 |
--------------------------------------------------------------------------------
/starter_templates/javascript/code/package-lock.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codecrafters/build-your-own-git",
3 | "version": "1.0.0",
4 | "lockfileVersion": 3,
5 | "requires": true,
6 | "packages": {
7 | "": {
8 | "name": "@codecrafters/build-your-own-git",
9 | "version": "1.0.0",
10 | "license": "MIT"
11 | }
12 | }
13 | }
--------------------------------------------------------------------------------
/starter_templates/javascript/code/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codecrafters/build-your-own-git",
3 | "version": "1.0.0",
4 | "description": "Build your own Git challenge, from CodeCrafters",
5 | "main": "main.js",
6 | "scripts": {
7 | "dev": "node app/main.js"
8 | },
9 | "keywords": [
10 | "build-your-own-x"
11 | ],
12 | "author": "",
13 | "license": "MIT",
14 | "dependencies": {}
15 | }
--------------------------------------------------------------------------------
/starter_templates/javascript/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: node (21)
3 | user_editable_file: app/main.js
4 |
--------------------------------------------------------------------------------
/starter_templates/kotlin/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | mvn -B package -Ddir=/tmp/codecrafters-build-dir
12 |
--------------------------------------------------------------------------------
/starter_templates/kotlin/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec java -jar /tmp/codecrafters-build-dir/build-your-own-git.jar "$@"
12 |
--------------------------------------------------------------------------------
/starter_templates/kotlin/code/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | .idea/
--------------------------------------------------------------------------------
/starter_templates/kotlin/code/src/main/kotlin/Main.kt:
--------------------------------------------------------------------------------
1 | import java.io.File
2 | import kotlin.system.exitProcess
3 |
4 | fun main(args: Array) {
5 | // You can use print statements as follows for debugging, they'll be visible when running tests.
6 | System.err.println("Logs from your program will appear here!")
7 |
8 | if (args.isEmpty()) {
9 | println("Usage: your_program.sh []")
10 | exitProcess(1)
11 | }
12 |
13 | if (args[0] == "init") {
14 | // Uncomment this block to pass the first stage
15 | //
16 | // val gitDir = File(".git")
17 | // gitDir.mkdir()
18 | // File(gitDir, "objects").mkdir()
19 | // File(gitDir, "refs").mkdir()
20 | // File(gitDir, "HEAD").writeText("ref: refs/heads/master\n")
21 | //
22 | // println("Initialized git directory")
23 | } else {
24 | println("Unknown command: ${args[0]}")
25 | exitProcess(1)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/starter_templates/kotlin/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: "kotlin (>=2.0)"
3 | user_editable_file: src/main/kotlin/Main.kt
4 |
--------------------------------------------------------------------------------
/starter_templates/python/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since Python programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/starter_templates/python/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | PYTHONPATH=$(dirname $0) exec python3 -m app.main "$@"
12 |
--------------------------------------------------------------------------------
/starter_templates/python/code/app/main.py:
--------------------------------------------------------------------------------
1 | import sys
2 | import os
3 |
4 |
5 | def main():
6 | # You can use print statements as follows for debugging, they'll be visible when running tests.
7 | print("Logs from your program will appear here!", file=sys.stderr)
8 |
9 | # Uncomment this block to pass the first stage
10 | #
11 | # command = sys.argv[1]
12 | # if command == "init":
13 | # os.mkdir(".git")
14 | # os.mkdir(".git/objects")
15 | # os.mkdir(".git/refs")
16 | # with open(".git/HEAD", "w") as f:
17 | # f.write("ref: refs/heads/main\n")
18 | # print("Initialized git directory")
19 | # else:
20 | # raise RuntimeError(f"Unknown command #{command}")
21 |
22 |
23 | if __name__ == "__main__":
24 | main()
25 |
--------------------------------------------------------------------------------
/starter_templates/python/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: python (3.13)
3 | user_editable_file: app/main.py
4 |
--------------------------------------------------------------------------------
/starter_templates/ruby/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since Ruby programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/starter_templates/ruby/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec ruby $(dirname $0)/app/main.rb "$@"
12 |
--------------------------------------------------------------------------------
/starter_templates/ruby/code/Gemfile:
--------------------------------------------------------------------------------
1 | # frozen_string_literal: true
2 |
3 | source "https://rubygems.org"
4 |
5 | # Add gems here if you need to use them.
6 | # Make sure to run `bundle install` before running tests or submitting your code.
7 |
--------------------------------------------------------------------------------
/starter_templates/ruby/code/Gemfile.lock:
--------------------------------------------------------------------------------
1 | GEM
2 | remote: https://rubygems.org/
3 | specs:
4 |
5 | PLATFORMS
6 | aarch64-linux-musl
7 | arm64-darwin-21
8 | arm64-darwin-23
9 | x86_64-linux
10 | ruby
11 |
12 | DEPENDENCIES
13 |
14 | BUNDLED WITH
15 | 2.5.6
16 |
--------------------------------------------------------------------------------
/starter_templates/ruby/code/app/main.rb:
--------------------------------------------------------------------------------
1 | # You can use print statements as follows for debugging, they'll be visible when running tests.
2 | $stderr.puts "Logs from your program will appear here!"
3 |
4 | # Uncomment this block to pass the first stage
5 | #
6 | # command = ARGV[0]
7 | # case command
8 | # when "init"
9 | # Dir.mkdir(".git")
10 | # Dir.mkdir(".git/objects")
11 | # Dir.mkdir(".git/refs")
12 | # File.write(".git/HEAD", "ref: refs/heads/main\n")
13 | # puts "Initialized git directory"
14 | # else
15 | # raise RuntimeError.new("Unknown command #{command}")
16 | # end
17 |
--------------------------------------------------------------------------------
/starter_templates/ruby/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: ruby (3.3)
3 | user_editable_file: app/main.rb
4 |
--------------------------------------------------------------------------------
/starter_templates/rust/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | cargo build --release --target-dir=/tmp/codecrafters-build-git-rust --manifest-path Cargo.toml
12 |
--------------------------------------------------------------------------------
/starter_templates/rust/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec /tmp/codecrafters-build-git-rust/release/codecrafters-git "$@"
12 |
--------------------------------------------------------------------------------
/starter_templates/rust/code/.gitignore:
--------------------------------------------------------------------------------
1 | # Generated by Cargo
2 | # will have compiled files and executables
3 | debug/
4 | target/
5 |
6 | # These are backup files generated by rustfmt
7 | **/*.rs.bk
8 |
9 | # MSVC Windows builds of rustc generate these, which store debugging information
10 | *.pdb
11 |
--------------------------------------------------------------------------------
/starter_templates/rust/code/Cargo.toml:
--------------------------------------------------------------------------------
1 | [package]
2 | name = "codecrafters-git"
3 | version = "0.1.0"
4 | authors = ["Codecrafters "]
5 | edition = "2021"
6 | rust-version = "1.80"
7 |
8 | [dependencies]
9 | anyhow = "1.0.68" # error handling
10 | bytes = "1.3.0" # helps manage buffers
11 | flate2 = "1.0.34" # compression
12 | thiserror = "1.0.38" # error handling
13 |
--------------------------------------------------------------------------------
/starter_templates/rust/code/src/main.rs:
--------------------------------------------------------------------------------
1 | #[allow(unused_imports)]
2 | use std::env;
3 | #[allow(unused_imports)]
4 | use std::fs;
5 |
6 | fn main() {
7 | // You can use print statements as follows for debugging, they'll be visible when running tests.
8 | eprintln!("Logs from your program will appear here!");
9 |
10 | // Uncomment this block to pass the first stage
11 | // let args: Vec = env::args().collect();
12 | // if args[1] == "init" {
13 | // fs::create_dir(".git").unwrap();
14 | // fs::create_dir(".git/objects").unwrap();
15 | // fs::create_dir(".git/refs").unwrap();
16 | // fs::write(".git/HEAD", "ref: refs/heads/main\n").unwrap();
17 | // println!("Initialized git directory")
18 | // } else {
19 | // println!("unknown command: {}", args[1])
20 | // }
21 | }
22 |
--------------------------------------------------------------------------------
/starter_templates/rust/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: cargo (1.86)
3 | user_editable_file: src/main.rs
4 |
--------------------------------------------------------------------------------
/starter_templates/typescript/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | # (This file is empty since TypeScript programs don't use a compile step)
12 |
--------------------------------------------------------------------------------
/starter_templates/typescript/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec bun run $(dirname $0)/app/main.ts "$@"
12 |
--------------------------------------------------------------------------------
/starter_templates/typescript/code/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 |
--------------------------------------------------------------------------------
/starter_templates/typescript/code/app/main.ts:
--------------------------------------------------------------------------------
1 | import * as fs from 'fs';
2 |
3 | const args = process.argv.slice(2);
4 | const command = args[0];
5 |
6 | switch (command) {
7 | case "init":
8 | // You can use print statements as follows for debugging, they'll be visible when running tests.
9 | console.error("Logs from your program will appear here!");
10 |
11 | // Uncomment this block to pass the first stage
12 | // fs.mkdirSync(".git", { recursive: true });
13 | // fs.mkdirSync(".git/objects", { recursive: true });
14 | // fs.mkdirSync(".git/refs", { recursive: true });
15 | // fs.writeFileSync(".git/HEAD", "ref: refs/heads/main\n");
16 | // console.log("Initialized git directory");
17 | break;
18 | default:
19 | throw new Error(`Unknown command ${command}`);
20 | }
21 |
--------------------------------------------------------------------------------
/starter_templates/typescript/code/bun.lockb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/codecrafters-io/build-your-own-git/fde1d49c3b841b8a33b04f8aa0383e5ba1378dbc/starter_templates/typescript/code/bun.lockb
--------------------------------------------------------------------------------
/starter_templates/typescript/code/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@codecrafters/git",
3 | "description": "Build your own Git challenge, from CodeCrafters",
4 | "type": "module",
5 | "scripts": {
6 | "dev": "bun run app/main.ts"
7 | },
8 | "devDependencies": {
9 | "@types/bun": "latest"
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/starter_templates/typescript/code/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | // Enable latest features
4 | "lib": ["ESNext", "DOM"],
5 | "target": "ESNext",
6 | "module": "ESNext",
7 | "moduleDetection": "force",
8 | "jsx": "react-jsx",
9 | "allowJs": true,
10 |
11 | // Bundler mode
12 | "moduleResolution": "bundler",
13 | "allowImportingTsExtensions": true,
14 | "verbatimModuleSyntax": true,
15 | "noEmit": true,
16 |
17 | // Best practices
18 | "strict": true,
19 | "skipLibCheck": true,
20 | "noFallthroughCasesInSwitch": true,
21 |
22 | // Some stricter flags (disabled by default)
23 | "noUnusedLocals": false,
24 | "noUnusedParameters": false,
25 | "noPropertyAccessFromIndexSignature": false
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/starter_templates/typescript/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: bun (1.2)
3 | user_editable_file: app/main.ts
4 |
--------------------------------------------------------------------------------
/starter_templates/zig/code/.codecrafters/compile.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to compile your program on CodeCrafters
4 | #
5 | # This runs before .codecrafters/run.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | zig build
12 |
--------------------------------------------------------------------------------
/starter_templates/zig/code/.codecrafters/run.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh
2 | #
3 | # This script is used to run your program on CodeCrafters
4 | #
5 | # This runs after .codecrafters/compile.sh
6 | #
7 | # Learn more: https://codecrafters.io/program-interface
8 |
9 | set -e # Exit on failure
10 |
11 | exec $(dirname $0)/zig-out/bin/main "$@"
12 |
--------------------------------------------------------------------------------
/starter_templates/zig/code/.gitignore:
--------------------------------------------------------------------------------
1 | # Zig build artifacts
2 | main
3 | zig-cache/
4 | .zig-cache/
5 | zig-out/
6 |
7 | # Compiled binary output
8 | bin/
9 | !bin/.gitkeep
10 |
11 | # Ignore any .o or .h files generated during build
12 | *.o
13 | *.h
14 |
15 | # Ignore OS and editor specific files
16 | **/.DS_Store
17 | *.swp
18 | *~
19 |
--------------------------------------------------------------------------------
/starter_templates/zig/code/src/main.zig:
--------------------------------------------------------------------------------
1 | const std = @import("std");
2 | const stdout = std.io.getStdOut().writer();
3 |
4 | pub fn main() !void {
5 | var gpa = std.heap.GeneralPurposeAllocator(.{}){};
6 | defer _ = gpa.deinit();
7 | const allocator = gpa.allocator();
8 |
9 | const args = try std.process.argsAlloc(allocator);
10 | defer std.process.argsFree(allocator, args);
11 |
12 | if (args.len < 2) {
13 | try std.io.getStdErr().writer().print("Usage: {s} \n", .{args[0]});
14 | return;
15 | }
16 |
17 | const command: []const u8 = args[1];
18 |
19 | // You can use print statements as follows for debugging, they'll be visible when running tests.
20 | std.debug.print("Logs from your program will appear here!\n", .{});
21 |
22 | if (std.mem.eql(u8, command, "init")) {
23 | // Uncomment this block to pass the first stage
24 | // const cwd = std.fs.cwd();
25 | // _ = try cwd.makeDir("./.git");
26 | // _ = try cwd.makeDir("./.git/objects");
27 | // _ = try cwd.makeDir("./.git/refs");
28 | // {
29 | // const head = try cwd.createFile("./.git/HEAD", .{});
30 | // defer head.close();
31 | // _ = try head.write("ref: refs/heads/main\n");
32 | // }
33 | // _ = try stdout.print("Initialized git directory\n", .{});
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/starter_templates/zig/config.yml:
--------------------------------------------------------------------------------
1 | attributes:
2 | required_executable: zig (0.14)
3 | user_editable_file: src/main.zig
4 |
--------------------------------------------------------------------------------