authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-25 00:26:24 -07:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-08-25 00:26:24 -07:00
logea57504f22fcd8d92e3bb536c2f7bf874f771b4d
treeb601631fe60970d012f667a419aafcab4cec611c
parent7ef751ed074ac1b6b70f0e0f5aa56047cfb4895e

cmd/init- add check for missing newline ending gitignore, fixes #28


1 files changed, 6 insertions(+), 3 deletions(-)

src/cmd/init.zig+6-3
...@@ -79,11 +79,14 @@ pub fn execute(args: [][]u8) !void {...@@ -79,11 +79,14 @@ pub fn execute(args: [][]u8) !void {
79 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa);79 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitignore?", gpa);
80 if (do) {80 if (do) {
81 const exists = try u.does_file_exist(".gitignore", null);81 const exists = try u.does_file_exist(".gitignore", null);
82 const file = try (if (exists) cwd.openFile(".gitignore", .{ .read = true, .write = true }) else cwd.createFile(".gitignore", .{}));82 const file: std.fs.File = try (if (exists) cwd.openFile(".gitignore", .{ .read = true, .write = true }) else cwd.createFile(".gitignore", .{}));
83 defer file.close();83 defer file.close();
84 try file.seekTo(try file.getEndPos());84 const len = try file.getEndPos();
85 if (len > 0) try file.seekTo(len - 1);
85 const w = file.writer();86 const w = file.writer();
8687 if (len > 0 and (try file.reader().readByte()) != '\n') {
88 try w.writeAll("\n");
89 }
87 if (!exists) try w.writeAll("zig-*\n");90 if (!exists) try w.writeAll("zig-*\n");
88 try w.writeAll(".zigmod\n");91 try w.writeAll(".zigmod\n");
89 try w.writeAll("deps.zig\n");92 try w.writeAll("deps.zig\n");