diff --git a/compiled_starters/swift/.gitattributes b/compiled_starters/swift/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/compiled_starters/swift/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/compiled_starters/swift/.gitignore b/compiled_starters/swift/.gitignore new file mode 100644 index 0000000..e0897a1 --- /dev/null +++ b/compiled_starters/swift/.gitignore @@ -0,0 +1,49 @@ +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ diff --git a/compiled_starters/swift/Package.swift b/compiled_starters/swift/Package.swift new file mode 100644 index 0000000..e97bfd1 --- /dev/null +++ b/compiled_starters/swift/Package.swift @@ -0,0 +1,14 @@ +// swift-tools-version: 5.9 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "OwnGit", + targets: [ + // Targets are the basic building blocks of a package, defining a module or a test suite. + // Targets can depend on other targets in this package and products from dependencies. + .executableTarget( + name: "OwnGit"), + ] +) diff --git a/compiled_starters/swift/README.md b/compiled_starters/swift/README.md new file mode 100644 index 0000000..49928ce --- /dev/null +++ b/compiled_starters/swift/README.md @@ -0,0 +1,60 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/git.png) + +This is a starting point for Swift 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 `Sources/main.swift`. Study +and uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git add . +git commit -m "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 `swift` installed locally +1. Run `./your_git.sh` to run your Git implementation, which is implemented in + `Sources/main.swift`. +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_git.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_git.sh` in a different folder when testing locally. +For example: + +```sh +mkdir -p /tmp/testing && cd /tmp/testing +/path/to/your/repo/your_git.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_git.sh + +mkdir -p /tmp/testing && cd /tmp/testing +mygit init +``` diff --git a/compiled_starters/swift/Sources/main.swift b/compiled_starters/swift/Sources/main.swift new file mode 100644 index 0000000..a59a8ee --- /dev/null +++ b/compiled_starters/swift/Sources/main.swift @@ -0,0 +1,39 @@ +// The Swift Programming Language +// https://docs.swift.org/swift-book +import Foundation + +// You can use print statements as follows for debugging, they'll be visible when running tests. +print("Logs from your program will appear here!") + +// Uncomment this block to pass the first stage +// +// +//guard CommandLine.arguments.count > 1 else { +// throw ArgumentError.missingCommand +//} +// +//switch CommandLine.arguments[1] { +//case "init": +// try createGitDirectory() +//default: +// throw ArgumentError.unknownCommand +//} +// +//enum ArgumentError: Error { +// case missingCommand +// case unknownCommand +//} +// +//func createGitDirectory() throws { +// let currentPath = FileManager.default.currentDirectoryPath +// let gitFolder = currentPath + "/.git" +// try FileManager.default.createDirectory(atPath: gitFolder, withIntermediateDirectories: true) +// let objectFolder = gitFolder + "/objects" +// try FileManager.default.createDirectory(atPath: objectFolder, withIntermediateDirectories: true) +// let refsFolder = gitFolder + "/refs" +// try FileManager.default.createDirectory(atPath: refsFolder, withIntermediateDirectories: true) +// +// let head = "ref: refs/heads/master\n" +// let headPath = gitFolder + "/HEAD" +// try head.write(toFile: headPath, atomically: true, encoding: .utf8) +//} diff --git a/compiled_starters/swift/codecrafters.yml b/compiled_starters/swift/codecrafters.yml new file mode 100644 index 0000000..655defb --- /dev/null +++ b/compiled_starters/swift/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 Swift version used to run your code +# on Codecrafters. +# +# Available versions: swift-5.10 +language_pack: swift-5.10 diff --git a/compiled_starters/swift/your_git.sh b/compiled_starters/swift/your_git.sh new file mode 100755 index 0000000..be5a9ee --- /dev/null +++ b/compiled_starters/swift/your_git.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +swift run --package-path $(dirname $0) OwnGit "$@" diff --git a/dockerfiles/swift-5.10.Dockerfile b/dockerfiles/swift-5.10.Dockerfile new file mode 100644 index 0000000..944e2c2 --- /dev/null +++ b/dockerfiles/swift-5.10.Dockerfile @@ -0,0 +1,13 @@ +FROM swift:5.10 + +ENV CODECRAFTERS_DEPENDENCY_FILE_PATHS="Package.swift" + +COPY Package.swift /app/Package.swift +RUN mkdir -p /app/Sources +RUN echo "print(\"Hello, world!\")" > /app/Sources/main.swift + +WORKDIR /app +RUN swift build + +RUN echo "cd \${CODECRAFTERS_SUBMISSION_DIR} && swift build" > /codecrafters-precompile.sh +RUN chmod +x /codecrafters-precompile.sh diff --git a/solutions/swift/01-init/code/.gitattributes b/solutions/swift/01-init/code/.gitattributes new file mode 100644 index 0000000..176a458 --- /dev/null +++ b/solutions/swift/01-init/code/.gitattributes @@ -0,0 +1 @@ +* text=auto diff --git a/solutions/swift/01-init/code/.gitignore b/solutions/swift/01-init/code/.gitignore new file mode 100644 index 0000000..e0897a1 --- /dev/null +++ b/solutions/swift/01-init/code/.gitignore @@ -0,0 +1,49 @@ +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ diff --git a/solutions/swift/01-init/code/Package.swift b/solutions/swift/01-init/code/Package.swift new file mode 100644 index 0000000..e97bfd1 --- /dev/null +++ b/solutions/swift/01-init/code/Package.swift @@ -0,0 +1,14 @@ +// swift-tools-version: 5.9 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "OwnGit", + targets: [ + // Targets are the basic building blocks of a package, defining a module or a test suite. + // Targets can depend on other targets in this package and products from dependencies. + .executableTarget( + name: "OwnGit"), + ] +) diff --git a/solutions/swift/01-init/code/README.md b/solutions/swift/01-init/code/README.md new file mode 100644 index 0000000..49928ce --- /dev/null +++ b/solutions/swift/01-init/code/README.md @@ -0,0 +1,60 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/git.png) + +This is a starting point for Swift 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 `Sources/main.swift`. Study +and uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git add . +git commit -m "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 `swift` installed locally +1. Run `./your_git.sh` to run your Git implementation, which is implemented in + `Sources/main.swift`. +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_git.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_git.sh` in a different folder when testing locally. +For example: + +```sh +mkdir -p /tmp/testing && cd /tmp/testing +/path/to/your/repo/your_git.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_git.sh + +mkdir -p /tmp/testing && cd /tmp/testing +mygit init +``` diff --git a/solutions/swift/01-init/code/Sources/main.swift b/solutions/swift/01-init/code/Sources/main.swift new file mode 100644 index 0000000..e8a2aa5 --- /dev/null +++ b/solutions/swift/01-init/code/Sources/main.swift @@ -0,0 +1,34 @@ +// The Swift Programming Language +// https://docs.swift.org/swift-book +import Foundation + + +guard CommandLine.arguments.count > 1 else { + throw ArgumentError.missingCommand +} + +switch CommandLine.arguments[1] { +case "init": + try createGitDirectory() +default: + throw ArgumentError.unknownCommand +} + +enum ArgumentError: Error { + case missingCommand + case unknownCommand +} + +func createGitDirectory() throws { + let currentPath = FileManager.default.currentDirectoryPath + let gitFolder = currentPath + "/.git" + try FileManager.default.createDirectory(atPath: gitFolder, withIntermediateDirectories: true) + let objectFolder = gitFolder + "/objects" + try FileManager.default.createDirectory(atPath: objectFolder, withIntermediateDirectories: true) + let refsFolder = gitFolder + "/refs" + try FileManager.default.createDirectory(atPath: refsFolder, withIntermediateDirectories: true) + + let head = "ref: refs/heads/master\n" + let headPath = gitFolder + "/HEAD" + try head.write(toFile: headPath, atomically: true, encoding: .utf8) +} diff --git a/solutions/swift/01-init/code/codecrafters.yml b/solutions/swift/01-init/code/codecrafters.yml new file mode 100644 index 0000000..655defb --- /dev/null +++ b/solutions/swift/01-init/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 Swift version used to run your code +# on Codecrafters. +# +# Available versions: swift-5.10 +language_pack: swift-5.10 diff --git a/solutions/swift/01-init/code/your_git.sh b/solutions/swift/01-init/code/your_git.sh new file mode 100755 index 0000000..be5a9ee --- /dev/null +++ b/solutions/swift/01-init/code/your_git.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +swift run --package-path $(dirname $0) OwnGit "$@" diff --git a/solutions/swift/01-init/diff/Sources/main.swift.diff b/solutions/swift/01-init/diff/Sources/main.swift.diff new file mode 100644 index 0000000..6516683 --- /dev/null +++ b/solutions/swift/01-init/diff/Sources/main.swift.diff @@ -0,0 +1,69 @@ +@@ -1,39 +1,34 @@ + // The Swift Programming Language + // https://docs.swift.org/swift-book + import Foundation + +-// You can use print statements as follows for debugging, they'll be visible when running tests. +-print("Logs from your program will appear here!") + +-// Uncomment this block to pass the first stage +-// +-// +-//guard CommandLine.arguments.count > 1 else { +-// throw ArgumentError.missingCommand +-//} +-// +-//switch CommandLine.arguments[1] { +-//case "init": +-// try createGitDirectory() +-//default: +-// throw ArgumentError.unknownCommand +-//} +-// +-//enum ArgumentError: Error { +-// case missingCommand +-// case unknownCommand +-//} +-// +-//func createGitDirectory() throws { +-// let currentPath = FileManager.default.currentDirectoryPath +-// let gitFolder = currentPath + "/.git" +-// try FileManager.default.createDirectory(atPath: gitFolder, withIntermediateDirectories: true) +-// let objectFolder = gitFolder + "/objects" +-// try FileManager.default.createDirectory(atPath: objectFolder, withIntermediateDirectories: true) +-// let refsFolder = gitFolder + "/refs" +-// try FileManager.default.createDirectory(atPath: refsFolder, withIntermediateDirectories: true) +-// +-// let head = "ref: refs/heads/master\n" +-// let headPath = gitFolder + "/HEAD" +-// try head.write(toFile: headPath, atomically: true, encoding: .utf8) +-//} ++guard CommandLine.arguments.count > 1 else { ++ throw ArgumentError.missingCommand ++} ++ ++switch CommandLine.arguments[1] { ++case "init": ++ try createGitDirectory() ++default: ++ throw ArgumentError.unknownCommand ++} ++ ++enum ArgumentError: Error { ++ case missingCommand ++ case unknownCommand ++} ++ ++func createGitDirectory() throws { ++ let currentPath = FileManager.default.currentDirectoryPath ++ let gitFolder = currentPath + "/.git" ++ try FileManager.default.createDirectory(atPath: gitFolder, withIntermediateDirectories: true) ++ let objectFolder = gitFolder + "/objects" ++ try FileManager.default.createDirectory(atPath: objectFolder, withIntermediateDirectories: true) ++ let refsFolder = gitFolder + "/refs" ++ try FileManager.default.createDirectory(atPath: refsFolder, withIntermediateDirectories: true) ++ ++ let head = "ref: refs/heads/master\n" ++ let headPath = gitFolder + "/HEAD" ++ try head.write(toFile: headPath, atomically: true, encoding: .utf8) ++} diff --git a/solutions/swift/01-init/explanation.md b/solutions/swift/01-init/explanation.md new file mode 100644 index 0000000..2a9229a --- /dev/null +++ b/solutions/swift/01-init/explanation.md @@ -0,0 +1,46 @@ +The entry point for your Git implementation is in `Sources/main.swift`. + +Study and uncomment the relevant code: + +```swift +// Uncomment this block to pass the first stage + + +guard CommandLine.arguments.count > 1 else { + throw ArgumentError.missingCommand +} + +switch CommandLine.arguments[1] { +case "init": + try createGitDirectory() +default: + throw ArgumentError.unknownCommand +} + +enum ArgumentError: Error { + case missingCommand + case unknownCommand +} + +func createGitDirectory() throws { + let currentPath = FileManager.default.currentDirectoryPath + let gitFolder = currentPath + "/.git" + try FileManager.default.createDirectory(atPath: gitFolder, withIntermediateDirectories: true) + let objectFolder = gitFolder + "/objects" + try FileManager.default.createDirectory(atPath: objectFolder, withIntermediateDirectories: true) + let refsFolder = gitFolder + "/refs" + try FileManager.default.createDirectory(atPath: refsFolder, withIntermediateDirectories: true) + + let head = "ref: refs/heads/master\n" + let headPath = gitFolder + "/HEAD" + try head.write(toFile: headPath, atomically: true, encoding: .utf8) +} +``` + +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/solutions/swift/code/.gitignore b/solutions/swift/code/.gitignore new file mode 100644 index 0000000..e0897a1 --- /dev/null +++ b/solutions/swift/code/.gitignore @@ -0,0 +1,49 @@ +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ diff --git a/solutions/swift/code/Package.swift b/solutions/swift/code/Package.swift new file mode 100644 index 0000000..e97bfd1 --- /dev/null +++ b/solutions/swift/code/Package.swift @@ -0,0 +1,14 @@ +// swift-tools-version: 5.9 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "OwnGit", + targets: [ + // Targets are the basic building blocks of a package, defining a module or a test suite. + // Targets can depend on other targets in this package and products from dependencies. + .executableTarget( + name: "OwnGit"), + ] +) diff --git a/solutions/swift/code/README.md b/solutions/swift/code/README.md new file mode 100644 index 0000000..45a5240 --- /dev/null +++ b/solutions/swift/code/README.md @@ -0,0 +1,61 @@ +![progress-banner](https://codecrafters.io/landing/images/default_progress_banners/git.png) + +This is a starting point for Rust 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/main.rs`. Study and +uncomment the relevant code, and push your changes to pass the first stage: + +```sh +git add . +git commit -m "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 `swift (5.10)` installed locally +1. Run `./your_git.sh` to run your Git implementation, which is implemented in + `Sources/main.swift`. This command compiles your Rust project, so it might be slow + the first time you run it. Subsequent runs will be fast. +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_git.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_git.sh` in a different folder when testing locally. +For example: + +```sh +mkdir -p /tmp/testing && cd /tmp/testing +/path/to/your/repo/your_git.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_git.sh + +mkdir -p /tmp/testing && cd /tmp/testing +mygit init +``` diff --git a/solutions/swift/code/Sources/main.swift b/solutions/swift/code/Sources/main.swift new file mode 100644 index 0000000..44e20d5 --- /dev/null +++ b/solutions/swift/code/Sources/main.swift @@ -0,0 +1,4 @@ +// The Swift Programming Language +// https://docs.swift.org/swift-book + +print("Hello, world!") diff --git a/solutions/swift/code/codecrafters.yml b/solutions/swift/code/codecrafters.yml new file mode 100644 index 0000000..d34e5cd --- /dev/null +++ b/solutions/swift/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 Rust version used to run your code +# on Codecrafters. +# +# Available versions: swift-5.10 +language_pack: swift-5.10 diff --git a/solutions/swift/code/your_git.sh b/solutions/swift/code/your_git.sh new file mode 100644 index 0000000..be5a9ee --- /dev/null +++ b/solutions/swift/code/your_git.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +swift run --package-path $(dirname $0) OwnGit "$@" diff --git a/solutions/swift/explanation.md b/solutions/swift/explanation.md new file mode 100644 index 0000000..e83909e --- /dev/null +++ b/solutions/swift/explanation.md @@ -0,0 +1,44 @@ +The entry point for your Git implementation is in `Sources/main.swift`. + +Study and uncomment the relevant code: + +```swift +// Uncomment this block to pass the first stage +if CommandLine.arguments.count < 2 { + throw ArgumentError.missingCommand +} + +switch CommandLine.arguments[1] { +case "init": + try createGitDirectory() +default: + throw ArgumentError.unknownCommand +} + +enum ArgumentError: Error { + case missingCommand + case unknownCommand +} + +func createGitDirectory() throws { + let currentPath = FileManager.default.currentDirectoryPath + let gitFolder = currentPath + "/.git" + try FileManager.default.createDirectory(atPath: gitFolder, withIntermediateDirectories: true) + let objectFolder = gitFolder + "/objects" + try FileManager.default.createDirectory(atPath: objectFolder, withIntermediateDirectories: true) + let refsFolder = gitFolder + "/refs" + try FileManager.default.createDirectory(atPath: refsFolder, withIntermediateDirectories: true) + + let head = "ref: refs/heads/master\n" + let headPath = gitFolder + "/HEAD" + try head.write(toFile: headPath, atomically: true, encoding: .utf8) +} +``` + +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-repository-definitions.yml b/starter-repository-definitions.yml index c1eb549..ad2776f 100644 --- a/starter-repository-definitions.yml +++ b/starter-repository-definitions.yml @@ -1,211 +1,231 @@ - language: cpp file_mappings: - - source: starter_templates/README.md - target: README.md - - source: starter_templates/codecrafters.yml - target: codecrafters.yml - - source: starter_templates/cpp/.gitignore - target: .gitignore - - source: starter_templates/cpp/src/Server.cpp - target: src/Server.cpp - - source: starter_templates/cpp/CMakeLists.txt - target: CMakeLists.txt - - source: starter_templates/cpp/your_git.sh - target: your_git.sh - - source: starter_templates/.gitattributes - target: .gitattributes + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/cpp/.gitignore + target: .gitignore + - source: starter_templates/cpp/src/Server.cpp + target: src/Server.cpp + - source: starter_templates/cpp/CMakeLists.txt + target: CMakeLists.txt + - source: starter_templates/cpp/your_git.sh + target: your_git.sh + - source: starter_templates/.gitattributes + target: .gitattributes template_attributes: - required_executable: "cmake" - user_editable_file: "src/Server.cpp" + required_executable: "cmake" + user_editable_file: "src/Server.cpp" - language: go file_mappings: - - source: starter_templates/README.md - target: README.md - - source: starter_templates/codecrafters.yml - target: codecrafters.yml - - source: starter_templates/go/go.mod - target: go.mod - - source: starter_templates/go/go.sum - target: go.sum - - source: starter_templates/go/cmd/mygit/main.go - target: cmd/mygit/main.go - - source: starter_templates/go/your_git.sh - target: your_git.sh - - source: starter_templates/.gitattributes - target: .gitattributes + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/go/go.mod + target: go.mod + - source: starter_templates/go/go.sum + target: go.sum + - source: starter_templates/go/cmd/mygit/main.go + target: cmd/mygit/main.go + - source: starter_templates/go/your_git.sh + target: your_git.sh + - source: starter_templates/.gitattributes + target: .gitattributes template_attributes: - required_executable: "go" - user_editable_file: "cmd/mygit/main.go" + required_executable: "go" + user_editable_file: "cmd/mygit/main.go" - language: python file_mappings: - - source: starter_templates/README.md - target: README.md - - source: starter_templates/codecrafters.yml - target: codecrafters.yml - - source: starter_templates/python/app/main.py - target: app/main.py - - source: starter_templates/python/your_git.sh - target: your_git.sh - - source: starter_templates/python/.gitignore - target: .gitignore - - source: starter_templates/.gitattributes - target: .gitattributes + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/python/app/main.py + target: app/main.py + - source: starter_templates/python/your_git.sh + target: your_git.sh + - source: starter_templates/python/.gitignore + target: .gitignore + - source: starter_templates/.gitattributes + target: .gitattributes template_attributes: - required_executable: "python" - user_editable_file: "app/main.py" + required_executable: "python" + user_editable_file: "app/main.py" - language: ruby file_mappings: - - source: starter_templates/README.md - target: README.md - - source: starter_templates/codecrafters.yml - target: codecrafters.yml - - source: starter_templates/ruby/app/main.rb - target: app/main.rb - - source: starter_templates/ruby/your_git.sh - target: your_git.sh - - source: starter_templates/.gitattributes - target: .gitattributes - - source: starter_templates/ruby/Gemfile - target: Gemfile - - source: starter_templates/ruby/Gemfile.lock - target: Gemfile.lock + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/ruby/app/main.rb + target: app/main.rb + - source: starter_templates/ruby/your_git.sh + target: your_git.sh + - source: starter_templates/.gitattributes + target: .gitattributes + - source: starter_templates/ruby/Gemfile + target: Gemfile + - source: starter_templates/ruby/Gemfile.lock + target: Gemfile.lock template_attributes: - required_executable: "ruby (3.3)" - user_editable_file: "app/main.rb" + required_executable: "ruby (3.3)" + user_editable_file: "app/main.rb" - language: rust file_mappings: - - source: starter_templates/README.md - target: README.md - - source: starter_templates/codecrafters.yml - target: codecrafters.yml - - source: starter_templates/rust/.gitignore - target: .gitignore - - source: starter_templates/rust/src/main.rs - target: src/main.rs - - source: starter_templates/rust/Cargo.toml - target: Cargo.toml - - source: starter_templates/rust/Cargo.lock - target: Cargo.lock - - source: starter_templates/rust/your_git.sh - target: your_git.sh - - source: starter_templates/.gitattributes - target: .gitattributes + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/rust/.gitignore + target: .gitignore + - source: starter_templates/rust/src/main.rs + target: src/main.rs + - source: starter_templates/rust/Cargo.toml + target: Cargo.toml + - source: starter_templates/rust/Cargo.lock + target: Cargo.lock + - source: starter_templates/rust/your_git.sh + target: your_git.sh + - source: starter_templates/.gitattributes + target: .gitattributes template_attributes: - required_executable: "cargo (1.54)" - user_editable_file: "src/main.rs" + required_executable: "cargo (1.54)" + user_editable_file: "src/main.rs" - language: javascript file_mappings: - - source: starter_templates/README.md - target: README.md - - source: starter_templates/codecrafters.yml - target: codecrafters.yml - - source: starter_templates/javascript/package.json - target: package.json - - source: starter_templates/javascript/package-lock.json - target: package-lock.json - - source: starter_templates/javascript/app/main.js - target: app/main.js - - source: starter_templates/javascript/your_git.sh - target: your_git.sh - - source: starter_templates/.gitattributes - target: .gitattributes - - source: starter_templates/javascript/.gitignore - target: .gitignore + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/javascript/package.json + target: package.json + - source: starter_templates/javascript/package-lock.json + target: package-lock.json + - source: starter_templates/javascript/app/main.js + target: app/main.js + - source: starter_templates/javascript/your_git.sh + target: your_git.sh + - source: starter_templates/.gitattributes + target: .gitattributes + - source: starter_templates/javascript/.gitignore + target: .gitignore template_attributes: - required_executable: "node (21)" - user_editable_file: "app/main.js" + required_executable: "node (21)" + user_editable_file: "app/main.js" - language: haskell file_mappings: - - source: starter_templates/README.md - target: README.md - - source: starter_templates/codecrafters.yml - target: codecrafters.yml - - source: starter_templates/haskell/.gitignore - target: .gitignore - - source: starter_templates/haskell/package.yaml - target: package.yaml - - source: starter_templates/haskell/stack.yaml - target: stack.yaml - - source: starter_templates/haskell/stack.yaml.lock - target: stack.yaml.lock - - source: starter_templates/haskell/your_git.sh - target: your_git.sh - - source: starter_templates/haskell/app/Main.hs - target: app/Main.hs - - source: starter_templates/.gitattributes - target: .gitattributes + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/haskell/.gitignore + target: .gitignore + - source: starter_templates/haskell/package.yaml + target: package.yaml + - source: starter_templates/haskell/stack.yaml + target: stack.yaml + - source: starter_templates/haskell/stack.yaml.lock + target: stack.yaml.lock + - source: starter_templates/haskell/your_git.sh + target: your_git.sh + - source: starter_templates/haskell/app/Main.hs + target: app/Main.hs + - source: starter_templates/.gitattributes + target: .gitattributes template_attributes: - required_executable: "stack" - user_editable_file: "app/Main.hs" + required_executable: "stack" + user_editable_file: "app/Main.hs" - language: java file_mappings: - - source: starter_templates/README.md - target: README.md - - source: starter_templates/codecrafters.yml - target: codecrafters.yml - - source: starter_templates/java/your_git.sh - target: your_git.sh - - source: starter_templates/java/.gitignore - target: .gitignore - - source: starter_templates/java/src/main/java/Main.java - target: src/main/java/Main.java - - source: starter_templates/java/pom.xml - target: pom.xml - - source: starter_templates/.gitattributes - target: .gitattributes + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/java/your_git.sh + target: your_git.sh + - source: starter_templates/java/.gitignore + target: .gitignore + - source: starter_templates/java/src/main/java/Main.java + target: src/main/java/Main.java + - source: starter_templates/java/pom.xml + target: pom.xml + - source: starter_templates/.gitattributes + target: .gitattributes template_attributes: - required_executable: "java (21)" - user_editable_file: "src/main/java/Main.java" + required_executable: "java (21)" + user_editable_file: "src/main/java/Main.java" # TODO: Add kotlin here once it's supported again! - language: csharp file_mappings: - - source: starter_templates/README.md - target: README.md - - source: starter_templates/codecrafters.yml - target: codecrafters.yml - - source: starter_templates/csharp/.gitignore - target: .gitignore - - source: starter_templates/csharp/src/Program.cs - target: src/Program.cs - - source: starter_templates/csharp/codecrafters-git.csproj - target: codecrafters-git.csproj - - source: starter_templates/csharp/codecrafters-git.sln - target: codecrafters-git.sln - - source: starter_templates/csharp/your_git.sh - target: your_git.sh - - source: starter_templates/.gitattributes - target: .gitattributes + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/csharp/.gitignore + target: .gitignore + - source: starter_templates/csharp/src/Program.cs + target: src/Program.cs + - source: starter_templates/csharp/codecrafters-git.csproj + target: codecrafters-git.csproj + - source: starter_templates/csharp/codecrafters-git.sln + target: codecrafters-git.sln + - source: starter_templates/csharp/your_git.sh + target: your_git.sh + - source: starter_templates/.gitattributes + target: .gitattributes template_attributes: - required_executable: "dotnet (8.0)" - user_editable_file: "src/Program.cs" + required_executable: "dotnet (8.0)" + user_editable_file: "src/Program.cs" - language: typescript file_mappings: - - source: starter_templates/README.md - target: README.md - - source: starter_templates/codecrafters.yml - target: codecrafters.yml - - source: starter_templates/typescript/app/main.ts - target: app/main.ts - - source: starter_templates/typescript/package.json - target: package.json - - source: starter_templates/typescript/bun.lockb - target: bun.lockb - - source: starter_templates/typescript/your_git.sh - target: your_git.sh - - source: starter_templates/.gitattributes - target: .gitattributes - - source: starter_templates/typescript/.gitignore - target: .gitignore + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/typescript/app/main.ts + target: app/main.ts + - source: starter_templates/typescript/package.json + target: package.json + - source: starter_templates/typescript/bun.lockb + target: bun.lockb + - source: starter_templates/typescript/your_git.sh + target: your_git.sh + - source: starter_templates/.gitattributes + target: .gitattributes + - source: starter_templates/typescript/.gitignore + target: .gitignore template_attributes: - required_executable: "bun (1.1)" - user_editable_file: "app/main.ts" + required_executable: "bun (1.1)" + user_editable_file: "app/main.ts" + +- language: swift + file_mappings: + - source: starter_templates/README.md + target: README.md + - source: starter_templates/codecrafters.yml + target: codecrafters.yml + - source: starter_templates/swift/.gitignore + target: .gitignore + - source: starter_templates/swift/Package.swift + target: Package.swift + - source: starter_templates/swift/Sources/main.swift + target: Sources/main.swift + - source: starter_templates/swift/your_git.sh + target: your_git.sh + - source: starter_templates/.gitattributes + target: .gitattributes + template_attributes: + required_executable: "swift" + user_editable_file: "Sources/main.swift" diff --git a/starter_templates/codecrafters.yml b/starter_templates/codecrafters.yml index f632df2..b29cd31 100644 --- a/starter_templates/codecrafters.yml +++ b/starter_templates/codecrafters.yml @@ -12,8 +12,8 @@ debug: false language_pack: python-3.12 {{/ language_is_python }} {{# language_is_swift }} -# Available versions: swift-5.1 -language_pack: swift-5.1 +# Available versions: swift-5.10 +language_pack: swift-5.10 {{/ language_is_swift }} {{# language_is_go }} # Available versions: go-1.22 @@ -78,4 +78,4 @@ language_pack: cpp-20 {{#language_is_typescript}} # Available versions: bun-1.1 language_pack: bun-1.1 -{{/language_is_typescript}} \ No newline at end of file +{{/language_is_typescript}} diff --git a/starter_templates/swift/.gitignore b/starter_templates/swift/.gitignore new file mode 100644 index 0000000..e0897a1 --- /dev/null +++ b/starter_templates/swift/.gitignore @@ -0,0 +1,49 @@ +# Xcode +# +# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore + +## User settings +xcuserdata/ + +## compatibility with Xcode 8 and earlier (ignoring not required starting Xcode 9) +*.xcscmblueprint +*.xccheckout + +## compatibility with Xcode 3 and earlier (ignoring not required starting Xcode 4) +build/ +DerivedData/ +*.moved-aside +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 + +## Obj-C/Swift specific +*.hmap + +## App packaging +*.ipa +*.dSYM.zip +*.dSYM + +## Playgrounds +timeline.xctimeline +playground.xcworkspace + +# Swift Package Manager +# +# Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. +# Packages/ +# Package.pins +# Package.resolved +# *.xcodeproj +# +# Xcode automatically generates this directory with a .xcworkspacedata file and xcuserdata +# hence it is not needed unless you have added a package configuration file to your project +# .swiftpm + +.build/ diff --git a/starter_templates/swift/Package.swift b/starter_templates/swift/Package.swift new file mode 100644 index 0000000..e97bfd1 --- /dev/null +++ b/starter_templates/swift/Package.swift @@ -0,0 +1,14 @@ +// swift-tools-version: 5.9 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "OwnGit", + targets: [ + // Targets are the basic building blocks of a package, defining a module or a test suite. + // Targets can depend on other targets in this package and products from dependencies. + .executableTarget( + name: "OwnGit"), + ] +) diff --git a/starter_templates/swift/Sources/main.swift b/starter_templates/swift/Sources/main.swift new file mode 100644 index 0000000..a59a8ee --- /dev/null +++ b/starter_templates/swift/Sources/main.swift @@ -0,0 +1,39 @@ +// The Swift Programming Language +// https://docs.swift.org/swift-book +import Foundation + +// You can use print statements as follows for debugging, they'll be visible when running tests. +print("Logs from your program will appear here!") + +// Uncomment this block to pass the first stage +// +// +//guard CommandLine.arguments.count > 1 else { +// throw ArgumentError.missingCommand +//} +// +//switch CommandLine.arguments[1] { +//case "init": +// try createGitDirectory() +//default: +// throw ArgumentError.unknownCommand +//} +// +//enum ArgumentError: Error { +// case missingCommand +// case unknownCommand +//} +// +//func createGitDirectory() throws { +// let currentPath = FileManager.default.currentDirectoryPath +// let gitFolder = currentPath + "/.git" +// try FileManager.default.createDirectory(atPath: gitFolder, withIntermediateDirectories: true) +// let objectFolder = gitFolder + "/objects" +// try FileManager.default.createDirectory(atPath: objectFolder, withIntermediateDirectories: true) +// let refsFolder = gitFolder + "/refs" +// try FileManager.default.createDirectory(atPath: refsFolder, withIntermediateDirectories: true) +// +// let head = "ref: refs/heads/master\n" +// let headPath = gitFolder + "/HEAD" +// try head.write(toFile: headPath, atomically: true, encoding: .utf8) +//} diff --git a/starter_templates/swift/your_git.sh b/starter_templates/swift/your_git.sh new file mode 100755 index 0000000..be5a9ee --- /dev/null +++ b/starter_templates/swift/your_git.sh @@ -0,0 +1,8 @@ +#!/bin/sh +# +# DON'T EDIT THIS! +# +# CodeCrafters uses this file to test your code. Don't make any changes here! +# +# DON'T EDIT THIS! +swift run --package-path $(dirname $0) OwnGit "$@"