Skip to content

Commit 88c3614

Browse files
committed
Backport template repository updating fix from v3
Now makes sure to checkout the right branch when pulling for the first time AND when updating the repository
1 parent 4efd83b commit 88c3614

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

Sources/swift-bundler/Bundler/Templater/Templater.swift

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -218,18 +218,32 @@ enum Templater {
218218
static func updateTemplates() -> Result<Void, TemplaterError> {
219219
return getDefaultTemplatesDirectory(downloadIfNecessary: false)
220220
.flatMap { templatesDirectory in
221-
if FileManager.default.itemExists(at: templatesDirectory, withType: .directory) {
222-
let process = Process.create(
223-
"/usr/bin/git",
224-
arguments: ["pull"],
225-
directory: templatesDirectory)
226-
if case let .failure(error) = process.runAndWait() {
227-
return .failure(.failedToPullLatestTemplates(error))
228-
}
229-
return .success()
230-
} else {
221+
print(templatesDirectory)
222+
guard FileManager.default.itemExists(at: templatesDirectory, withType: .directory) else {
231223
return downloadDefaultTemplates(into: templatesDirectory)
232224
}
225+
226+
return Process.create(
227+
"/usr/bin/git",
228+
arguments: [
229+
"fetch"
230+
],
231+
directory: templatesDirectory
232+
).runAndWait().flatMap { _ in
233+
Process.create(
234+
"/usr/bin/git",
235+
arguments: [
236+
"checkout", "v\(SwiftBundler.version.major)",
237+
],
238+
directory: templatesDirectory
239+
).runAndWait()
240+
}.flatMap { _ in
241+
Process.create(
242+
"/usr/bin/git",
243+
arguments: ["pull"],
244+
directory: templatesDirectory
245+
).runAndWait()
246+
}.mapError(TemplaterError.failedToPullLatestTemplates)
233247
}
234248
}
235249

@@ -296,7 +310,8 @@ enum Templater {
296310
let process = Process.create(
297311
"/usr/bin/git",
298312
arguments: [
299-
"clone", "\(defaultTemplateRepository)",
313+
"clone", "-b", "v\(SwiftBundler.version.major)",
314+
"\(defaultTemplateRepository)",
300315
directory.path
301316
])
302317

Sources/swift-bundler/SwiftBundler.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
import Foundation
22
import ArgumentParser
33
import Darwin
4+
import Version
45

56
/// The root command of Swift Bundler.
67
struct SwiftBundler: ParsableCommand {
8+
public static let version = Version(2, 0, 7)
9+
710
static let configuration = CommandConfiguration(
811
commandName: "swift-bundler",
912
abstract: "A tool for creating macOS apps from Swift packages.",
10-
version: "v2.0.3",
13+
version: "v" + version.description,
1114
shouldDisplay: true,
1215
subcommands: [
1316
BundleCommand.self,

0 commit comments

Comments
 (0)