authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-28 13:57:33 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2021-12-28 13:57:33 -08:00
log1c93f00212b37bf480bc7f30d7ac4576a74d8303
treebc26af6356a95d15f9b68d64b3d9db9402102d57
parent7619f605fe17c34ff99ae95c0b0b4555ef7d912d

cmd/init- ask about .gitattributes, fixes #42


1 files changed, 22 insertions(+), 0 deletions(-)

src/cmd/init.zig+22
...@@ -120,6 +120,28 @@ pub fn execute(args: [][]u8) !void {...@@ -120,6 +120,28 @@ pub fn execute(args: [][]u8) !void {
120 try w.writeAll("deps.zig\n");120 try w.writeAll("deps.zig\n");
121 }121 }
122 }122 }
123
124 // ask about .gitattributes
125 if (try u.does_folder_exist(".git")) {
126 const do = try inquirer.forConfirm(stdout, stdin, "It appears you're using git. Do you want init to add Zigmod to your .gitattributes?", gpa);
127 if (do) {
128 const exists = try u.does_file_exist(null, ".gitattributes");
129 const file: std.fs.File = try (if (exists) cwd.openFile(".gitattributes", .{ .read = true, .write = true }) else cwd.createFile(".gitattributes", .{}));
130 defer file.close();
131 const len = try file.getEndPos();
132 if (len > 0) try file.seekTo(len - 1);
133 const w = file.writer();
134 if (len > 0 and (try file.reader().readByte()) != '\n') {
135 try w.writeAll("\n");
136 }
137 if (!exists) try w.writeAll("* text=auto\n");
138 if (!exists) try w.writeAll("*.zig text eol=lf # See https://github.com/ziglang/zig-spec/issues/38\n");
139 try w.writeAll("zig.mod text eol=lf\n");
140 try w.writeAll("zigmod.* text eol=lf\n");
141 try w.writeAll("zig.mod linguist-language=YAML\n");
142 try w.writeAll("zig.mod gitlab-language=yaml\n");
143 }
144 }
123}145}
124146
125pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license: ?string, description: ?string) !void {147pub fn writeExeManifest(w: std.fs.File.Writer, id: string, name: string, license: ?string, description: ?string) !void {