From 9bde797b2448cabcf6669cd02355554d776a8cfc Mon Sep 17 00:00:00 2001 From: leo Date: Wed, 30 Apr 2025 20:41:00 +0800 Subject: [PATCH] fix: make sure the new pattern is appended as a new line (#1264) Signed-off-by: leo --- src/Commands/GitIgnore.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/Commands/GitIgnore.cs b/src/Commands/GitIgnore.cs index e666eba6..8b351f5e 100644 --- a/src/Commands/GitIgnore.cs +++ b/src/Commands/GitIgnore.cs @@ -8,7 +8,14 @@ namespace SourceGit.Commands { var file = Path.Combine(repo, ".gitignore"); if (!File.Exists(file)) + { File.WriteAllLines(file, [pattern]); + return; + } + + var org = File.ReadAllText(file); + if (!org.EndsWith('\n')) + File.AppendAllLines(file, ["", pattern]); else File.AppendAllLines(file, [pattern]); }