From 542593e1376f2d67ac1b4f5944ab22d2330b2cfb Mon Sep 17 00:00:00 2001 From: "Sven A. Schmidt" Date: Sat, 15 Nov 2025 12:16:19 +0100 Subject: [PATCH] Fixes #3902 --- Sources/App/Core/Extensions/ShellOutCommand+ext.swift | 3 ++- Tests/AppTests/AnalyzerTests.swift | 3 ++- Tests/AppTests/GitTests.swift | 4 ++-- Tests/AppTests/ShellOutCommandExtensionTests.swift | 8 ++++---- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Sources/App/Core/Extensions/ShellOutCommand+ext.swift b/Sources/App/Core/Extensions/ShellOutCommand+ext.swift index 301dafaaa..52816857c 100644 --- a/Sources/App/Core/Extensions/ShellOutCommand+ext.swift +++ b/Sources/App/Core/Extensions/ShellOutCommand+ext.swift @@ -62,7 +62,8 @@ extension ShellOutCommand { static func gitRevisionInfo(reference: Reference, separator: String = "-") -> Self { .init(command: "git", arguments: ["log", "-n1", #"--format=tformat:"%H\#(separator)%ct""#, - "\(reference.quoted)"]) + "\(reference.quoted)", + "--"]) // trailing -- ensures reference is taken as a reference even if a file exists with the same name } diff --git a/Tests/AppTests/AnalyzerTests.swift b/Tests/AppTests/AnalyzerTests.swift index 05e3f73fe..80826df88 100644 --- a/Tests/AppTests/AnalyzerTests.swift +++ b/Tests/AppTests/AnalyzerTests.swift @@ -1699,7 +1699,8 @@ private struct Command: CustomStringConvertible { case _ where command.description.starts(with: #"git show -s --format=%ct"#): self.kind = .showDate case _ where command.description.starts(with: #"git log -n1 --format=tformat:"%H\#(separator)%ct""#): - let ref = String(command.description.split(separator: " ").last!) + let trimmed = command.description.removingSuffix(" --") + let ref = String(trimmed.split(separator: " ").last!) .trimmingCharacters(in: quotes) self.kind = .revisionInfo(ref) case .swiftDumpPackage: diff --git a/Tests/AppTests/GitTests.swift b/Tests/AppTests/GitTests.swift index 4ce29003d..8d1cc82c8 100644 --- a/Tests/AppTests/GitTests.swift +++ b/Tests/AppTests/GitTests.swift @@ -46,7 +46,7 @@ extension AllTests.GitTests { @Test func revInfo() async throws { try await withDependencies { $0.shell.run = { @Sendable cmd, _, _ in - if cmd.description == #"git log -n1 --format=tformat:"%H-%ct" 2.2.1"# { + if cmd.description == #"git log -n1 --format=tformat:"%H-%ct" 2.2.1 --"# { return "63c973f3c2e632a340936c285e94d59f9ffb01d5-1536799579" } throw TestError.unknownCommand @@ -63,7 +63,7 @@ extension AllTests.GitTests { // https://github.com/SwiftPackageIndex/SwiftPackageIndex-Server/issues/139 try await withDependencies { $0.shell.run = { @Sendable cmd, _, _ in - if cmd.description == #"git log -n1 --format=tformat:"%H-%ct" v2.2.1"# { + if cmd.description == #"git log -n1 --format=tformat:"%H-%ct" v2.2.1 --"# { return "63c973f3c2e632a340936c285e94d59f9ffb01d5-1536799579" } throw TestError.unknownCommand diff --git a/Tests/AppTests/ShellOutCommandExtensionTests.swift b/Tests/AppTests/ShellOutCommandExtensionTests.swift index bdbd14735..dc5fbbc4f 100644 --- a/Tests/AppTests/ShellOutCommandExtensionTests.swift +++ b/Tests/AppTests/ShellOutCommandExtensionTests.swift @@ -54,15 +54,15 @@ extension AllTests.ShellOutCommandExtensionTests { let dash = "-" #expect( ShellOutCommand - .gitRevisionInfo(reference: .tag(1, 2, 3), separator: dash).description == #"git log -n1 --format=tformat:"%H\#(dash)%ct" 1.2.3"# + .gitRevisionInfo(reference: .tag(1, 2, 3), separator: dash).description == #"git log -n1 --format=tformat:"%H\#(dash)%ct" 1.2.3 --"# ) #expect( ShellOutCommand - .gitRevisionInfo(reference: .branch("foo"), separator: dash).description == #"git log -n1 --format=tformat:"%H\#(dash)%ct" foo"# + .gitRevisionInfo(reference: .branch("foo"), separator: dash).description == #"git log -n1 --format=tformat:"%H\#(dash)%ct" foo --"# ) #expect( ShellOutCommand - .gitRevisionInfo(reference: .branch("ba\nd"), separator: dash).description == "git log -n1 --format=tformat:\"%H\(dash)%ct\" 'ba\nd'" + .gitRevisionInfo(reference: .branch("ba\nd"), separator: dash).description == "git log -n1 --format=tformat:\"%H\(dash)%ct\" 'ba\nd' --" ) } @@ -79,7 +79,7 @@ extension AllTests.ShellOutCommandExtensionTests { ShellOutCommand.gitReset(to: "foo ; rm *", hard: false).description == "git reset origin/'foo ; rm *'" ) #expect( - ShellOutCommand.gitRevisionInfo(reference: .branch("foo ; rm *")).description == #"git log -n1 --format=tformat:"%H-%ct" 'foo ; rm *'"# + ShellOutCommand.gitRevisionInfo(reference: .branch("foo ; rm *")).description == #"git log -n1 --format=tformat:"%H-%ct" 'foo ; rm *' --"# ) #expect( ShellOutCommand.gitShowDate("foo ; rm *").description == #"git show -s --format=%ct 'foo ; rm *'"#