'Git Clone with Swift Script
I want to clone the team projects into a predefined structure (as they are on the Git) on my local machine. Manually I have to create a new folder for every new project and then clone it with https via the terminal. However, I want to automate this now and just want to know if there is a simple solution to this. I have searched a-lot on this and found no solution to this particular problem. I know ho to create a folder and clone a certain git repo via swift script but it is not efficient if I still have to write the names of new folders(which are basically just the repos names) and then manually put the git url in the script to clone it.
let git = Process()
git.executableURL = URL(fileURLWithPath: "/usr/bin/git")
I am adding a snippet of how I am doing it; by defining a Process and then initialising it with git url.
do{
try fileManager.createDirectory(atPath: "\(path)/\(folder)/Local",
withIntermediateDirectories: true)
try fileManager.createDirectory(atPath: "\(path)/\(folder)/Local/NewFolder",
withIntermediateDirectories: true)
let repo = "http://[email protected]/mobile/local/NewFolder.git"
let pathForRepo = "\(path)/\(folder)/Local/NewFolder"
git.arguments = ["clone", repo, pathForRepo]
try git.run()
} catch {
print("Error creating new folder")
exit(1)
}
Solution 1:[1]
It looks like you are using a private git server (git.tyre24.local
). You don't say what you are running on it (is it GitLab? something else?).
In any case, "Teams" are not part of git, they are a concept in whatever git web software you have installed at git.tyre24.local
-- that software probably has an API that you could use to get a list of repositories given a team.
If this server is just a raw git server (no other management software), then I don't think there is an automatic way to discover the repo URLs on it (but not 100% sure). Perhaps, if this server has a way to ssh
to it as well, you could programmatically do that and get a listing of folders.
For Gitlab, see this: https://docs.gitlab.com/ee/api/projects.html
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |