diff --git a/compiled_starters/clojure/.codecrafters/compile.sh b/compiled_starters/clojure/.codecrafters/compile.sh new file mode 100755 index 0000000..9a332c5 --- /dev/null +++ b/compiled_starters/clojure/.codecrafters/compile.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure diff --git a/compiled_starters/clojure/.codecrafters/install.sh b/compiled_starters/clojure/.codecrafters/install.sh new file mode 100755 index 0000000..29e2b3b --- /dev/null +++ b/compiled_starters/clojure/.codecrafters/install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +set -e # Exit on failure +echo "Downloading babashka" +curl -L -o babashka.tar.gz https://github.com/babashka/babashka/releases/download/v1.12.200/babashka-1.12.200-linux-amd64-static.tar.gz + +echo "Unpacking babashka" +tar -xzf babashka.tar.gz + +echo "Installing babashka" +mv bb /usr/local/bin/ +chmod +x /usr/local/bin/bb + +echo "Cleaning up" +rm babashka.tar.gz + +echo "babashka installed successfully!" diff --git a/compiled_starters/clojure/.codecrafters/run.sh b/compiled_starters/clojure/.codecrafters/run.sh new file mode 100755 index 0000000..430f2b9 --- /dev/null +++ b/compiled_starters/clojure/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +bb --config /app/bb.edn -m git.core "$@" diff --git a/compiled_starters/clojure/.gitattributes b/compiled_starters/clojure/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/compiled_starters/clojure/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/compiled_starters/clojure/README.md b/compiled_starters/clojure/README.md new file mode 100644 index 0000000..2073acb --- /dev/null +++ b/compiled_starters/clojure/README.md @@ -0,0 +1,59 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/git.png) + +This is a starting point for Clojure solutions to the +["Build Your Own Git" Challenge](https://codecrafters.io/challenges/git). + +In this challenge, you'll build a small Git implementation that's capable of +initializing a repository, creating commits and cloning a public repository. +Along the way we'll learn about the `.git` directory, Git objects (blobs, +commits, trees etc.), Git's transfer protocols and more. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your Git implementation is in `src/git/core.clj`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git commit -am "pass 1st stage" # any msg +git push origin master +``` + +That's all! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `bb` installed locally +1. Run `./your_program.sh` to run your Git implementation, which is implemented + in `src/git/core.clj`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. + +# Testing locally + +The `your_program.sh` script is expected to operate on the `.git` folder inside +the current working directory. If you're running this inside the root of this +repository, you might end up accidentally damaging your repository's `.git` +folder. + +We suggest executing `your_program.sh` in a different folder when testing +locally. For example: + +```sh +mkdir -p /tmp/testing && cd /tmp/testing +/path/to/your/repo/your_program.sh init +``` + +To make this easier to type out, you could add a +[shell alias](https://shapeshed.com/unix-alias/): + +```sh +alias mygit=/path/to/your/repo/your_program.sh + +mkdir -p /tmp/testing && cd /tmp/testing +mygit init +``` diff --git a/compiled_starters/clojure/bb.edn b/compiled_starters/clojure/bb.edn new file mode 100644 index 0000000..ccd9a31 --- /dev/null +++ b/compiled_starters/clojure/bb.edn @@ -0,0 +1 @@ +{:paths ["src"]} diff --git a/compiled_starters/clojure/codecrafters.yml b/compiled_starters/clojure/codecrafters.yml new file mode 100644 index 0000000..addefcf --- /dev/null +++ b/compiled_starters/clojure/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the Clojure version used to run your code +# on Codecrafters. +# +# Available versions: clojure-1.12.0 +language_pack: clojure-1.12.0 diff --git a/compiled_starters/clojure/src/git/core.clj b/compiled_starters/clojure/src/git/core.clj new file mode 100644 index 0000000..ff88ca8 --- /dev/null +++ b/compiled_starters/clojure/src/git/core.clj @@ -0,0 +1,21 @@ +(ns git.core + (:require + [babashka.fs :as fs]) + (:gen-class)) + +(defn -main [& args] + ;; You can use print statements as follows for debugging, they'll be visible when running tests. + (println "Logs from your program will appear here!") + + ;; Uncomment this block to pass the first stage + ;; (let [command (first args)] + ;; (case command + ;; "init" + ;; (do + ;; (fs/create-dir ".git") + ;; (fs/create-dir ".git/objects") + ;; (fs/create-dir ".git/refs") + ;; (spit ".git/HEAD" "ref: refs/heads/main\n") + ;; (println "Initialized git directory")) + ;; (throw (ex-info (str "Unknown command " command) {})))) + ) diff --git a/compiled_starters/clojure/your_program.sh b/compiled_starters/clojure/your_program.sh new file mode 100755 index 0000000..0461543 --- /dev/null +++ b/compiled_starters/clojure/your_program.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Use this script to run your program LOCALLY. +# +# Note: Changing this script WILL NOT affect how CodeCrafters runs your program. +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit early if any commands fail + +# Copied from .codecrafters/run.sh +# +# - Edit this to change how your program runs locally +# - Edit .codecrafters/run.sh to change how your program runs remotely +bb --config /app/bb.edn -m git.core "$@" diff --git a/dockerfiles/clojure-1.12.0.Dockerfile b/dockerfiles/clojure-1.12.0.Dockerfile new file mode 100644 index 0000000..18f228f --- /dev/null +++ b/dockerfiles/clojure-1.12.0.Dockerfile @@ -0,0 +1,13 @@ +# syntax=docker/dockerfile:1.7-labs +FROM clojure:tools-deps-bookworm + +# Ensures the container is re-built if dependency files change +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="deps.edn" + +WORKDIR /app + +# .git & README.md are unique per-repository. We ignore them on first copy to prevent cache misses +COPY --exclude=.git --exclude=README.md . /app + +# Install language-specific dependencies +RUN .codecrafters/install.sh diff --git a/solutions/clojure/01-gg4/code/.codecrafters/compile.sh b/solutions/clojure/01-gg4/code/.codecrafters/compile.sh new file mode 100755 index 0000000..9a332c5 --- /dev/null +++ b/solutions/clojure/01-gg4/code/.codecrafters/compile.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure diff --git a/solutions/clojure/01-gg4/code/.codecrafters/install.sh b/solutions/clojure/01-gg4/code/.codecrafters/install.sh new file mode 100755 index 0000000..29e2b3b --- /dev/null +++ b/solutions/clojure/01-gg4/code/.codecrafters/install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +set -e # Exit on failure +echo "Downloading babashka" +curl -L -o babashka.tar.gz https://github.com/babashka/babashka/releases/download/v1.12.200/babashka-1.12.200-linux-amd64-static.tar.gz + +echo "Unpacking babashka" +tar -xzf babashka.tar.gz + +echo "Installing babashka" +mv bb /usr/local/bin/ +chmod +x /usr/local/bin/bb + +echo "Cleaning up" +rm babashka.tar.gz + +echo "babashka installed successfully!" diff --git a/solutions/clojure/01-gg4/code/.codecrafters/run.sh b/solutions/clojure/01-gg4/code/.codecrafters/run.sh new file mode 100755 index 0000000..430f2b9 --- /dev/null +++ b/solutions/clojure/01-gg4/code/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +bb --config /app/bb.edn -m git.core "$@" diff --git a/solutions/clojure/01-gg4/code/.gitattributes b/solutions/clojure/01-gg4/code/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/solutions/clojure/01-gg4/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/clojure/01-gg4/code/README.md b/solutions/clojure/01-gg4/code/README.md new file mode 100644 index 0000000..2073acb --- /dev/null +++ b/solutions/clojure/01-gg4/code/README.md @@ -0,0 +1,59 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/git.png) + +This is a starting point for Clojure solutions to the +["Build Your Own Git" Challenge](https://codecrafters.io/challenges/git). + +In this challenge, you'll build a small Git implementation that's capable of +initializing a repository, creating commits and cloning a public repository. +Along the way we'll learn about the `.git` directory, Git objects (blobs, +commits, trees etc.), Git's transfer protocols and more. + +**Note**: If you're viewing this repo on GitHub, head over to +[codecrafters.io](https://codecrafters.io) to try the challenge. + +# Passing the first stage + +The entry point for your Git implementation is in `src/git/core.clj`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git commit -am "pass 1st stage" # any msg +git push origin master +``` + +That's all! + +# Stage 2 & beyond + +Note: This section is for stages 2 and beyond. + +1. Ensure you have `bb` installed locally +1. Run `./your_program.sh` to run your Git implementation, which is implemented + in `src/git/core.clj`. +1. Commit your changes and run `git push origin master` to submit your solution + to CodeCrafters. Test output will be streamed to your terminal. + +# Testing locally + +The `your_program.sh` script is expected to operate on the `.git` folder inside +the current working directory. If you're running this inside the root of this +repository, you might end up accidentally damaging your repository's `.git` +folder. + +We suggest executing `your_program.sh` in a different folder when testing +locally. For example: + +```sh +mkdir -p /tmp/testing && cd /tmp/testing +/path/to/your/repo/your_program.sh init +``` + +To make this easier to type out, you could add a +[shell alias](https://shapeshed.com/unix-alias/): + +```sh +alias mygit=/path/to/your/repo/your_program.sh + +mkdir -p /tmp/testing && cd /tmp/testing +mygit init +``` diff --git a/solutions/clojure/01-gg4/code/bb.edn b/solutions/clojure/01-gg4/code/bb.edn new file mode 100644 index 0000000..ccd9a31 --- /dev/null +++ b/solutions/clojure/01-gg4/code/bb.edn @@ -0,0 +1 @@ +{:paths ["src"]} diff --git a/solutions/clojure/01-gg4/code/codecrafters.yml b/solutions/clojure/01-gg4/code/codecrafters.yml new file mode 100644 index 0000000..addefcf --- /dev/null +++ b/solutions/clojure/01-gg4/code/codecrafters.yml @@ -0,0 +1,11 @@ +# Set this to true if you want debug logs. +# +# These can be VERY verbose, so we suggest turning them off +# unless you really need them. +debug: false + +# Use this to change the Clojure version used to run your code +# on Codecrafters. +# +# Available versions: clojure-1.12.0 +language_pack: clojure-1.12.0 diff --git a/solutions/clojure/01-gg4/code/src/git/core.clj b/solutions/clojure/01-gg4/code/src/git/core.clj new file mode 100644 index 0000000..7f234d8 --- /dev/null +++ b/solutions/clojure/01-gg4/code/src/git/core.clj @@ -0,0 +1,17 @@ +(ns git.core + (:require + [babashka.fs :as fs]) + (:gen-class)) + +(defn -main [& args] + (let [command (first args)] + (case command + "init" + (do + (fs/create-dir ".git") + (fs/create-dir ".git/objects") + (fs/create-dir ".git/refs") + (spit ".git/HEAD" "ref: refs/heads/main\n") + (println "Initialized git directory")) + (throw (ex-info (str "Unknown command " command) {})))) + ) diff --git a/solutions/clojure/01-gg4/code/your_program.sh b/solutions/clojure/01-gg4/code/your_program.sh new file mode 100755 index 0000000..0461543 --- /dev/null +++ b/solutions/clojure/01-gg4/code/your_program.sh @@ -0,0 +1,15 @@ +#!/bin/sh +# +# Use this script to run your program LOCALLY. +# +# Note: Changing this script WILL NOT affect how CodeCrafters runs your program. +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit early if any commands fail + +# Copied from .codecrafters/run.sh +# +# - Edit this to change how your program runs locally +# - Edit .codecrafters/run.sh to change how your program runs remotely +bb --config /app/bb.edn -m git.core "$@" diff --git a/solutions/clojure/01-gg4/diff/src/git/core.clj.diff b/solutions/clojure/01-gg4/diff/src/git/core.clj.diff new file mode 100644 index 0000000..c287571 --- /dev/null +++ b/solutions/clojure/01-gg4/diff/src/git/core.clj.diff @@ -0,0 +1,32 @@ +@@ -1,21 +1,17 @@ + (ns git.core + (:require + [babashka.fs :as fs]) + (:gen-class)) + + (defn -main [& args] +- ;; You can use print statements as follows for debugging, they'll be visible when running tests. +- (println "Logs from your program will appear here!") +- +- ;; Uncomment this block to pass the first stage +- ;; (let [command (first args)] +- ;; (case command +- ;; "init" +- ;; (do +- ;; (fs/create-dir ".git") +- ;; (fs/create-dir ".git/objects") +- ;; (fs/create-dir ".git/refs") +- ;; (spit ".git/HEAD" "ref: refs/heads/main\n") +- ;; (println "Initialized git directory")) +- ;; (throw (ex-info (str "Unknown command " command) {})))) ++ (let [command (first args)] ++ (case command ++ "init" ++ (do ++ (fs/create-dir ".git") ++ (fs/create-dir ".git/objects") ++ (fs/create-dir ".git/refs") ++ (spit ".git/HEAD" "ref: refs/heads/main\n") ++ (println "Initialized git directory")) ++ (throw (ex-info (str "Unknown command " command) {})))) + ) diff --git a/solutions/clojure/01-gg4/explanation.md b/solutions/clojure/01-gg4/explanation.md new file mode 100644 index 0000000..ed201ac --- /dev/null +++ b/solutions/clojure/01-gg4/explanation.md @@ -0,0 +1,25 @@ +The entry point for your Git implementation is in `src/git/core.clj`. + +Study and uncomment the relevant code: + +```clojure +;; Uncomment this block to pass the first stage +(let [command (first args)] + (case command + "init" + (do + (fs/create-dir ".git") + (fs/create-dir ".git/objects") + (fs/create-dir ".git/refs") + (spit ".git/HEAD" "ref: refs/heads/main\n") + (println "Initialized git directory")) + (throw (ex-info (str "Unknown command " command) {})))) +``` + +Push your changes to pass the first stage: + +``` +git add . +git commit -m "pass 1st stage" # any msg +git push origin master +``` diff --git a/starter_templates/clojure/code/.codecrafters/compile.sh b/starter_templates/clojure/code/.codecrafters/compile.sh new file mode 100755 index 0000000..9a332c5 --- /dev/null +++ b/starter_templates/clojure/code/.codecrafters/compile.sh @@ -0,0 +1,9 @@ +#!/bin/sh +# +# This script is used to compile your program on CodeCrafters +# +# This runs before .codecrafters/run.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure diff --git a/starter_templates/clojure/code/.codecrafters/install.sh b/starter_templates/clojure/code/.codecrafters/install.sh new file mode 100755 index 0000000..29e2b3b --- /dev/null +++ b/starter_templates/clojure/code/.codecrafters/install.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env sh + +set -e # Exit on failure +echo "Downloading babashka" +curl -L -o babashka.tar.gz https://github.com/babashka/babashka/releases/download/v1.12.200/babashka-1.12.200-linux-amd64-static.tar.gz + +echo "Unpacking babashka" +tar -xzf babashka.tar.gz + +echo "Installing babashka" +mv bb /usr/local/bin/ +chmod +x /usr/local/bin/bb + +echo "Cleaning up" +rm babashka.tar.gz + +echo "babashka installed successfully!" diff --git a/starter_templates/clojure/code/.codecrafters/run.sh b/starter_templates/clojure/code/.codecrafters/run.sh new file mode 100755 index 0000000..430f2b9 --- /dev/null +++ b/starter_templates/clojure/code/.codecrafters/run.sh @@ -0,0 +1,11 @@ +#!/bin/sh +# +# This script is used to run your program on CodeCrafters +# +# This runs after .codecrafters/compile.sh +# +# Learn more: https://codecrafters.io/program-interface + +set -e # Exit on failure + +bb --config /app/bb.edn -m git.core "$@" diff --git a/starter_templates/clojure/code/bb.edn b/starter_templates/clojure/code/bb.edn new file mode 100644 index 0000000..ccd9a31 --- /dev/null +++ b/starter_templates/clojure/code/bb.edn @@ -0,0 +1 @@ +{:paths ["src"]} diff --git a/starter_templates/clojure/code/src/git/core.clj b/starter_templates/clojure/code/src/git/core.clj new file mode 100644 index 0000000..ff88ca8 --- /dev/null +++ b/starter_templates/clojure/code/src/git/core.clj @@ -0,0 +1,21 @@ +(ns git.core + (:require + [babashka.fs :as fs]) + (:gen-class)) + +(defn -main [& args] + ;; You can use print statements as follows for debugging, they'll be visible when running tests. + (println "Logs from your program will appear here!") + + ;; Uncomment this block to pass the first stage + ;; (let [command (first args)] + ;; (case command + ;; "init" + ;; (do + ;; (fs/create-dir ".git") + ;; (fs/create-dir ".git/objects") + ;; (fs/create-dir ".git/refs") + ;; (spit ".git/HEAD" "ref: refs/heads/main\n") + ;; (println "Initialized git directory")) + ;; (throw (ex-info (str "Unknown command " command) {})))) + ) diff --git a/starter_templates/clojure/config.yml b/starter_templates/clojure/config.yml new file mode 100644 index 0000000..2ac4cc0 --- /dev/null +++ b/starter_templates/clojure/config.yml @@ -0,0 +1,3 @@ +attributes: + required_executable: bb + user_editable_file: src/git/core.clj