Skip to content

Commit 1fdaec6

Browse files
author
Miguel Perez
committed
Fixed pull
-C needed to come first
1 parent 2ba6a43 commit 1fdaec6

File tree

2 files changed

+22
-16
lines changed

2 files changed

+22
-16
lines changed

Sources/Commands/SwiftPackageTool.swift

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -312,31 +312,36 @@ extension SwiftPackageTool {
312312
throw InternalError("Could not find config path")
313313
}
314314

315+
let templatePath: AbsolutePath
315316
if let path = try? AbsolutePath(validating: url) {
316-
if localFileSystem.exists(path) {
317-
let currentTemplateLocation = path
318-
let templateDirectory = configPath.appending(components: "templates", "new-package", url)
319-
320-
guard localFileSystem.exists(currentTemplateLocation) && localFileSystem.isDirectory(currentTemplateLocation) else {
321-
throw StringError("Could not find template: \(url)")
322-
}
323-
324-
try localFileSystem.copy(from: currentTemplateLocation, to: templateDirectory)
317+
guard localFileSystem.exists(path) else {
318+
throw StringError("Could not find template: \(path)")
319+
}
320+
321+
guard localFileSystem.isDirectory(path) else {
322+
throw StringError("\(path) is not a valid directory")
325323
}
324+
325+
templatePath = configPath.appending(components: "templates", "new-package", path.basename)
326+
try localFileSystem.copy(from: path, to: templatePath)
326327
} else {
327-
let templatePath: AbsolutePath
328328
let provider = GitRepositoryProvider()
329329

330330
if let templateName = name {
331331
templatePath = configPath.appending(components: "templates", "new-package", templateName)
332-
} else if let templateName = url.split(separator: "/").last {
333-
templatePath = configPath.appending(components: "templates", "new-package", String(templateName.replacingOccurrences(of: ".git", with: "")))
332+
} else if let templateName = url.split(separator: "/").last?.replacingOccurrences(of: ".git", with: "").flatMap({ String($0) }) {
333+
templatePath = configPath.appending(components: "templates", "new-package", String(templateName))
334334
} else {
335335
throw InternalError("Could not determine template name")
336336
}
337337

338338
try provider.fetch(repository: RepositorySpecifier(url: url), to: templatePath, mirror: false)
339339
}
340+
341+
guard localFileSystem.exists(templatePath.appending(component: "Package.swift")) else {
342+
try localFileSystem.removeFileTree(templatePath)
343+
throw StringError("\(templatePath) is not a valid template directory, missing 'Package.swift'")
344+
}
340345
}
341346
}
342347

@@ -362,11 +367,12 @@ extension SwiftPackageTool {
362367
let provider = GitRepositoryProvider()
363368
let templatePath = configPath.appending(components: "templates", "new-package", templateName)
364369

365-
if provider.isValidDirectory(templatePath.pathString) {
366-
try provider.pull(templatePath.pathString)
367-
} else {
370+
guard provider.isValidDirectory(templatePath.pathString) else {
368371
throw StringError("Template: \(templateName) is not a git repo, and therefore could not be updated")
369372
}
373+
374+
try provider.pull(templatePath.pathString)
375+
370376
}
371377
}
372378

Sources/SourceControl/GitRepository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public struct GitRepositoryProvider: RepositoryProvider {
108108
}
109109

110110
public func pull(_ directory: String) throws {
111-
try self.callGit("pull", "-C", directory, repository: RepositorySpecifier(url: directory))
111+
try self.callGit("-C", directory, "pull", "--ff-only", repository: RepositorySpecifier(url: directory))
112112
}
113113

114114
public func isValidDirectory(_ directory: String) -> Bool {

0 commit comments

Comments
 (0)