adds nice git interface
This commit is contained in:
@@ -51,6 +51,30 @@ import Testing
|
||||
#expect(result.canPush == canPush)
|
||||
}
|
||||
|
||||
@Test("the behind count comes from the header", arguments: [
|
||||
("main...origin/main [ahead 1, behind 2]", 2),
|
||||
("main...origin/main [behind 5]", 5),
|
||||
("main...origin/main [ahead 3]", 0),
|
||||
("main...origin/main", 0),
|
||||
("feature/x", 0),
|
||||
("HEAD (no branch)", 0),
|
||||
])
|
||||
func behind(header: String, count: Int) {
|
||||
#expect(Porcelain.parseBehind(header: header) == count)
|
||||
}
|
||||
|
||||
@Test("the upstream comes from the header", arguments: [
|
||||
("main...origin/main [ahead 1, behind 2]", "origin/main"),
|
||||
("feature/x...origin/feature/x", "origin/feature/x"),
|
||||
("main...origin/main [gone]", "origin/main"),
|
||||
("main", nil),
|
||||
("No commits yet on main", nil),
|
||||
("HEAD (no branch)", nil),
|
||||
] as [(String, String?)])
|
||||
func upstream(header: String, name: String?) {
|
||||
#expect(Porcelain.parseUpstream(header: header) == name)
|
||||
}
|
||||
|
||||
@Test("the branch name comes from the header", arguments: [
|
||||
("main...origin/main [ahead 1]", "main"),
|
||||
("main", "main"),
|
||||
@@ -72,6 +96,8 @@ import Testing
|
||||
#expect(parsed.branch == "main")
|
||||
#expect(parsed.ahead == 2)
|
||||
#expect(parsed.canPush)
|
||||
#expect(parsed.behind == 0)
|
||||
#expect(parsed.upstream == "origin/main")
|
||||
#expect(parsed.entries == [
|
||||
StatusEntry(index: " ", working: "M", path: "src/a.ts"),
|
||||
StatusEntry(index: "?", working: "?", path: "new file.txt"),
|
||||
@@ -107,6 +133,12 @@ import Testing
|
||||
#expect(parsed.entries.count == 1)
|
||||
}
|
||||
|
||||
@Test("a header ahead and behind carries both counts and the upstream")
|
||||
func aheadAndBehind() {
|
||||
let parsed = Porcelain.parseStatus("## main...origin/main [ahead 1, behind 2]\0")
|
||||
#expect(parsed == ParsedStatus(branch: "main", ahead: 1, canPush: true, behind: 2, upstream: "origin/main", entries: []))
|
||||
}
|
||||
|
||||
@Test("empty output is a clean tree")
|
||||
func empty() {
|
||||
#expect(Porcelain.parseStatus("") == ParsedStatus(branch: "HEAD", ahead: 0, canPush: false, entries: []))
|
||||
@@ -120,14 +152,6 @@ import Testing
|
||||
|
||||
// MARK: push
|
||||
|
||||
@Test("a push toast prefers the ref line, a failure its last line")
|
||||
func pushSummary() {
|
||||
let ok = Porcelain.pushSummary(exitCode: 0, stdout: "", stderr: "To github.com:x/y.git\n abc..def main -> main\n")
|
||||
#expect(ok == PushResult(ok: true, message: "abc..def main -> main"))
|
||||
let failed = Porcelain.pushSummary(exitCode: 1, stdout: "", stderr: "error: failed to push\nhint: pull first\n")
|
||||
#expect(failed == PushResult(ok: false, message: "hint: pull first"))
|
||||
}
|
||||
|
||||
@Test("a missing upstream is detected from git's hint")
|
||||
func needsUpstream() {
|
||||
#expect(Porcelain.needsUpstream(stderr: "fatal: The current branch x has no upstream branch."))
|
||||
|
||||
Reference in New Issue
Block a user