Skip to content

Commit

Permalink
Merge pull request #14 from faberNovel/feature/fix-url
Browse files Browse the repository at this point in the history
Fix URL in git download
  • Loading branch information
gaetanzanella authored Sep 6, 2021
2 parents d825f57 + 2a78a7d commit ad3990f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
15 changes: 13 additions & 2 deletions Sources/XCResource/Shared/Shell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public struct GitReference {

enum ShellCommand {
case open(path: String)
case gitDownload(url: String, reference: GitReference, destination: String)
case gitDownload(url: URL, reference: GitReference, destination: URL)
}

class Shell {
Expand Down Expand Up @@ -56,9 +56,20 @@ private extension ShellCommand {
func shell() -> String {
switch self {
case let .gitDownload(url, reference, destination):
return "git clone -b '\(reference.name)' --single-branch --depth 1 \(url) \(destination)"
return "git clone -b '\(reference.name)' --single-branch --depth 1 \(url.toString()) \(destination.toString())"
case let .open(path):
return "open \(path)"
}
}
}

private extension URL {

func toString() -> String {
if isFileURL {
return path // we remove the file: prefix
} else {
return absoluteString
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ struct GitSourceSnippetDownloadingStrategy: XCSnippetDownloadingStrategy {
try? fileManager.removeItem(at: tmp)
}
try Shell().execute(
.gitDownload(url: url.absoluteString, reference: reference, destination: tmp.path)
.gitDownload(url: url, reference: reference, destination: tmp)
)
let snippetsDirectoryURL = tmp.appendingPathComponent(folderPath)
let snippetURLs = try fileManager.contentsOfDirectory(at: snippetsDirectoryURL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ struct GitSourceDownloadingStrategy: XCTemplateFolderDownloadingStrategy {
}
try Shell().execute(
.gitDownload(
url: url.path,
url: url,
reference: reference,
destination: tmp.path
destination: tmp
)
)
let folder = try templateManager.templateFolder(at: tmp.appendingPathComponent(folderPath))
Expand Down

0 comments on commit ad3990f

Please sign in to comment.