Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/App/Core/Extensions/ShellOutCommand+ext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

Expand Down
3 changes: 2 additions & 1 deletion Tests/AppTests/AnalyzerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions Tests/AppTests/GitTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions Tests/AppTests/ShellOutCommandExtensionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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' --"
)
}

Expand All @@ -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 *'"#
Expand Down
Loading