Skip to content

Commit 686c085

Browse files
committed
Write .gitignore with CRLF on Win32
1 parent c5ce0ad commit 686c085

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

.gitattributes

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
*.c text
2626
*.c++ text
2727
*.h text
28+
.gitignore text
2829
*.java text
2930
*.json text
3031
*.md text

src/DkStd_Std/Project/Init.ml

+10-8
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ exp-grouping=preserve
117117
nested-match=align
118118
|}
119119

120+
let write_crlf_on_win32 fp s =
121+
Out_channel.with_open_text (Fpath.to_string fp) (fun oc ->
122+
Out_channel.output_string oc s)
123+
120124
let () =
121125
Arg.parse speclist anon_fun usage_msg;
122126
if !new_project_dir = "" then Utils.fail "NEW_PROJECT_DIR argument is missing";
@@ -154,15 +158,15 @@ let () =
154158
let gitignore = Fpath.(new_project_dirp / ".gitignore") in
155159
if not (Bos.OS.File.exists gitignore |> Utils.rmsg) then (
156160
Printf.eprintf "dkcoder: create .gitignore\n%!";
157-
Bos.OS.File.write gitignore (String.trim contents_gitignore_untrimmed) |> Utils.rmsg);
161+
(* Use CRLF on Windows since ".gitignore text" in .gitattributes *)
162+
write_crlf_on_win32 gitignore (String.trim contents_gitignore_untrimmed));
158163

159164
(* .ocamlformat *)
160165
let ocamlformat = Fpath.(new_project_dirp / ".ocamlformat") in
161166
if not (Bos.OS.File.exists ocamlformat |> Utils.rmsg) then (
162167
Printf.eprintf "dkcoder: create .ocamlformat\n%!";
163-
(* Use CRLF on Windows since .ocamlformat is ".ocamlformat text" in .gitattributes *)
164-
Out_channel.with_open_text (Fpath.to_string ocamlformat) (fun oc ->
165-
Out_channel.output_string oc (String.trim contents_ocamlformat_untrimmed)));
168+
(* Use CRLF on Windows since ".ocamlformat text" in .gitattributes *)
169+
write_crlf_on_win32 ocamlformat (String.trim contents_ocamlformat_untrimmed));
166170

167171
(* .vscode/ *)
168172
let vscode_dirp = Fpath.(new_project_dirp / ".vscode") in
@@ -173,16 +177,14 @@ let () =
173177
if not (Bos.OS.File.exists extensions_json |> Utils.rmsg) then (
174178
Printf.eprintf "dkcoder: create .vscode/extensions.json\n%!";
175179
(* Use CRLF on Windows since .json are "*.json text" in .gitattributes *)
176-
Out_channel.with_open_text (Fpath.to_string extensions_json) (fun oc ->
177-
Out_channel.output_string oc (String.trim contents_extensions_json_untrimmed)));
180+
write_crlf_on_win32 extensions_json (String.trim contents_extensions_json_untrimmed));
178181

179182
(* .vscode/settings.json *)
180183
let settings_json = Fpath.(vscode_dirp / "settings.json") in
181184
if not (Bos.OS.File.exists settings_json |> Utils.rmsg) then (
182185
Printf.eprintf "dkcoder: create .vscode/settings.json\n%!";
183186
(* Use CRLF on Windows since .json are "*.json text" in .gitattributes *)
184-
Out_channel.with_open_text (Fpath.to_string settings_json) (fun oc ->
185-
Out_channel.output_string oc (String.trim contents_settings_json_untrimmed)));
187+
write_crlf_on_win32 settings_json (String.trim contents_settings_json_untrimmed));
186188

187189
(* git add, git update-index *)
188190
let project_files = ["dk"; "dk.cmd"; "__dk.cmake";

0 commit comments

Comments
 (0)