|
| 1 | + |
| 2 | + |
| 3 | +This is a starting point for Swift solutions to the |
| 4 | +["Build Your Own Git" Challenge](https://codecrafters.io/challenges/git). |
| 5 | + |
| 6 | +In this challenge, you'll build a small Git implementation that's capable of |
| 7 | +initializing a repository, creating commits and cloning a public repository. |
| 8 | +Along the way we'll learn about the `.git` directory, Git objects (blobs, |
| 9 | +commits, trees etc.), Git's transfer protocols and more. |
| 10 | + |
| 11 | +**Note**: If you're viewing this repo on GitHub, head over to |
| 12 | +[codecrafters.io](https://codecrafters.io) to try the challenge. |
| 13 | + |
| 14 | +# Passing the first stage |
| 15 | + |
| 16 | +The entry point for your Git implementation is in `Sources/main.swift`. Study |
| 17 | +and uncomment the relevant code, and push your changes to pass the first stage: |
| 18 | + |
| 19 | +```sh |
| 20 | +git add . |
| 21 | +git commit -m "pass 1st stage" # any msg |
| 22 | +git push origin master |
| 23 | +``` |
| 24 | + |
| 25 | +That's all! |
| 26 | + |
| 27 | +# Stage 2 & beyond |
| 28 | + |
| 29 | +Note: This section is for stages 2 and beyond. |
| 30 | + |
| 31 | +1. Ensure you have `swift` installed locally |
| 32 | +1. Run `./your_git.sh` to run your Git implementation, which is implemented in |
| 33 | + `Sources/main.swift`. |
| 34 | +1. Commit your changes and run `git push origin master` to submit your solution |
| 35 | + to CodeCrafters. Test output will be streamed to your terminal. |
| 36 | + |
| 37 | +# Testing locally |
| 38 | + |
| 39 | +The `your_git.sh` script is expected to operate on the `.git` folder inside the |
| 40 | +current working directory. If you're running this inside the root of this |
| 41 | +repository, you might end up accidentally damaging your repository's `.git` |
| 42 | +folder. |
| 43 | + |
| 44 | +We suggest executing `your_git.sh` in a different folder when testing locally. |
| 45 | +For example: |
| 46 | + |
| 47 | +```sh |
| 48 | +mkdir -p /tmp/testing && cd /tmp/testing |
| 49 | +/path/to/your/repo/your_git.sh init |
| 50 | +``` |
| 51 | + |
| 52 | +To make this easier to type out, you could add a |
| 53 | +[shell alias](https://shapeshed.com/unix-alias/): |
| 54 | + |
| 55 | +```sh |
| 56 | +alias mygit=/path/to/your/repo/your_git.sh |
| 57 | + |
| 58 | +mkdir -p /tmp/testing && cd /tmp/testing |
| 59 | +mygit init |
| 60 | +``` |
0 commit comments