Skip to content

Commit c43fab6

Browse files
committed
Fix isIgnored and add test for it
1 parent 124c6af commit c43fab6

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Sources/SourceControl/GitRepository.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ public class GitRepository: Repository, WorkingCheckout {
404404
/// Returns true if the file at `path` is ignored by `git`
405405
public func isIgnored(_ path: AbsolutePath) throws -> Bool {
406406
return try queue.sync {
407-
let result = try Process.popen(args: Git.tool, "check-ignore", path.asString)
407+
let result = try Process.popen(args: Git.tool, "-C", self.path.asString, "check-ignore", path.asString)
408408

409409
switch result.exitStatus {
410410
case .terminated(code: 0):

Tests/SourceControlTests/GitRepositoryTests.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,22 @@ class GitRepositoryTests: XCTestCase {
605605
}
606606
}
607607

608+
func testIgnored() throws {
609+
mktmpdir { path in
610+
// Create a repo.
611+
let testRepoPath = path.appending(component: "test-repo")
612+
try makeDirectories(testRepoPath)
613+
initGitRepo(testRepoPath)
614+
let repo = GitRepository(path: testRepoPath)
615+
616+
// Add a .gitignore
617+
try localFileSystem.writeFileContents(testRepoPath.appending(component: ".gitignore"), bytes: "ignored_file")
618+
619+
XCTAssertTrue(try repo.isIgnored(testRepoPath.appending(component: "ignored_file")))
620+
XCTAssertFalse(try repo.isIgnored(testRepoPath.appending(component: "not_ignored_file")))
621+
}
622+
}
623+
608624
static var allTests = [
609625
("testBranchOperations", testBranchOperations),
610626
("testCheckoutRevision", testCheckoutRevision),

0 commit comments

Comments
 (0)