Skip to content

Commit

Permalink
Writing relative url to gitconfig upon adding first pattern
Browse files Browse the repository at this point in the history
  • Loading branch information
austincondiff committed Nov 26, 2024
1 parent eab7301 commit b31e07d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,12 @@ class IgnorePatternModel: ObservableObject {

private func writeAllPatterns() {
let content = patterns.map(\.value).joined(separator: "\n")
Task {
let excludesfile: String? = try await gitConfig.get(key: "core.excludesfile")
if excludesfile == "" {
await gitConfig.set(key: "core.excludesfile", value: "~/\(fileURL.lastPathComponent)")
}
}
try? content.write(to: fileURL, atomically: true, encoding: .utf8)
}

Expand Down Expand Up @@ -271,6 +277,6 @@ class IgnorePatternModel: ObservableObject {
func setupGlobalIgnoreFile() async {
guard !FileManager.default.fileExists(atPath: fileURL.path) else { return }
FileManager.default.createFile(atPath: fileURL.path, contents: nil)
await gitConfig.set(key: "core.excludesfile", value: fileURL.path, global: true)
await gitConfig.set(key: "core.excludesfile", value: "~/\(fileURL.lastPathComponent)")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private extension SourceControlGitView {
// Fallback to `.gitignore_global` in the home directory
fileURL = FileManager.default.homeDirectoryForCurrentUser.appendingPathComponent(".gitignore_global")
// Set the default path in Git config if not set
await gitConfig.set(key: "core.excludesfile", value: fileURL.path, global: true)
await gitConfig.set(key: "core.excludesfile", value: "~/\(fileURL.lastPathComponent)")
}

// Ensure the file exists
Expand Down

0 comments on commit b31e07d

Please sign in to comment.