| ... | @@ -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(); |
| 86 | | 87 | 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"); |