Skip to content

Commit ed7255d

Browse files
init [skip ci]
0 parents  commit ed7255d

8 files changed

Lines changed: 285 additions & 0 deletions

File tree

.codecrafters/compile.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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)

.codecrafters/run.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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 "$@"

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# poetry
98+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102+
#poetry.lock
103+
104+
# pdm
105+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106+
#pdm.lock
107+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108+
# in version control.
109+
# https://pdm.fming.dev/#use-with-ide
110+
.pdm.toml
111+
112+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113+
__pypackages__/
114+
115+
# Celery stuff
116+
celerybeat-schedule
117+
celerybeat.pid
118+
119+
# SageMath parsed files
120+
*.sage.py
121+
122+
# Environments
123+
.env
124+
.venv
125+
env/
126+
venv/
127+
ENV/
128+
env.bak/
129+
venv.bak/
130+
131+
# Spyder project settings
132+
.spyderproject
133+
.spyproject
134+
135+
# Rope project settings
136+
.ropeproject
137+
138+
# mkdocs documentation
139+
/site
140+
141+
# mypy
142+
.mypy_cache/
143+
.dmypy.json
144+
dmypy.json
145+
146+
# Pyre type checker
147+
.pyre/
148+
149+
# pytype static type analyzer
150+
.pytype/
151+
152+
# Cython debug symbols
153+
cython_debug/

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
[![progress-banner](https://backend.codecrafters.io/progress/git/1cbb831d-900d-4aab-9ca3-31a739f008a6)](https://app.codecrafters.io/users/codecrafters-bot?r=2qF)
2+
3+
This is a starting point for Python 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 `app/main.py`. Study and
17+
uncomment the relevant code, and push your changes to pass the first stage:
18+
19+
```sh
20+
git commit -am "pass 1st stage" # any msg
21+
git push origin master
22+
```
23+
24+
That's all!
25+
26+
# Stage 2 & beyond
27+
28+
Note: This section is for stages 2 and beyond.
29+
30+
1. Ensure you have `python (3.13)` installed locally
31+
1. Run `./your_program.sh` to run your Git implementation, which is implemented
32+
in `app/main.py`.
33+
1. Commit your changes and run `git push origin master` to submit your solution
34+
to CodeCrafters. Test output will be streamed to your terminal.
35+
36+
# Testing locally
37+
38+
The `your_program.sh` script is expected to operate on the `.git` folder inside
39+
the current working directory. If you're running this inside the root of this
40+
repository, you might end up accidentally damaging your repository's `.git`
41+
folder.
42+
43+
We suggest executing `your_program.sh` in a different folder when testing
44+
locally. For example:
45+
46+
```sh
47+
mkdir -p /tmp/testing && cd /tmp/testing
48+
/path/to/your/repo/your_program.sh init
49+
```
50+
51+
To make this easier to type out, you could add a
52+
[shell alias](https://shapeshed.com/unix-alias/):
53+
54+
```sh
55+
alias mygit=/path/to/your/repo/your_program.sh
56+
57+
mkdir -p /tmp/testing && cd /tmp/testing
58+
mygit init
59+
```

app/main.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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()

codecrafters.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
buildpack: python-3.13

your_program.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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 "$@"

0 commit comments

Comments
 (0)