Skip to content
This repository was archived by the owner on Oct 17, 2021. It is now read-only.

Commit 8bd943c

Browse files
committed
Move add methods to index
1 parent c7b7c64 commit 8bd943c

File tree

3 files changed

+25
-25
lines changed

3 files changed

+25
-25
lines changed

Sources/Git/Repository.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -168,30 +168,6 @@ public final class Repository {
168168
return (ahead, behind)
169169
}
170170

171-
public func add(path: String, force: Bool = false) throws {
172-
try path.withCString { cString in
173-
try attempt { git_index_add_bypath(index?.pointer, cString) }
174-
}
175-
}
176-
177-
// TODO: Add dry-run option
178-
public func add(paths: [String], update: Bool = false, force: Bool = false, disableGlobExpansion: Bool = false) throws {
179-
let options = (force ? GIT_INDEX_ADD_FORCE.rawValue : 0) |
180-
(disableGlobExpansion ? GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH.rawValue : 0)
181-
182-
try paths.withGitStringArray { array in
183-
try withUnsafePointer(to: array) { paths in
184-
if update {
185-
try attempt { git_index_update_all(index?.pointer, paths, nil, nil) }
186-
} else {
187-
try attempt { git_index_add_all(index?.pointer, paths, options, nil, nil) }
188-
}
189-
}
190-
}
191-
192-
try attempt { git_index_write(index?.pointer) }
193-
}
194-
195171
@discardableResult
196172
public func createCommit(message: String, author: Signature? = nil, committer: Signature? = nil) throws -> Commit {
197173
let tree = try lookup(try Object.ID { oid in

Sources/Git/Repository/Index.swift

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ extension Repository {
6161
public func reload(force: Bool) throws {
6262
try attempt { git_index_read(pointer, force ? 1 : 0)}
6363
}
64+
65+
public func add(path: String, force: Bool = false) throws {
66+
try path.withCString { cString in
67+
try attempt { git_index_add_bypath(pointer, cString) }
68+
}
69+
}
70+
71+
// TODO: Add dry-run option
72+
public func add(paths: [String], update: Bool = false, force: Bool = false, disableGlobExpansion: Bool = false) throws {
73+
let options = (force ? GIT_INDEX_ADD_FORCE.rawValue : 0) |
74+
(disableGlobExpansion ? GIT_INDEX_ADD_DISABLE_PATHSPEC_MATCH.rawValue : 0)
75+
76+
try paths.withGitStringArray { array in
77+
try withUnsafePointer(to: array) { paths in
78+
if update {
79+
try attempt { git_index_update_all(pointer, paths, nil, nil) }
80+
} else {
81+
try attempt { git_index_add_all(pointer, paths, options, nil, nil) }
82+
}
83+
}
84+
}
85+
86+
try attempt { git_index_write(pointer) }
87+
}
6488
}
6589
}
6690

Tests/GitTests/GitTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ final class GitTests: XCTestCase {
8181
Hello, world!
8282
""".write(toFile: localURL.appendingPathComponent("hello.txt").path, atomically: true, encoding: .utf8)
8383

84-
try repository.add(paths: ["hello.txt"])
84+
try repository.index?.add(paths: ["hello.txt"])
8585

8686
let signature = try Signature(name: "Mona Lisa Octocat", email: "mona@github.com")
8787
let commit = try repository.createCommit(message: "Initial commit", author: signature, committer: signature)

0 commit comments

Comments
 (0)