Skip to content

Commit

Permalink
Make 'buck2 init --git' ignore .git directories by default (#201)
Browse files Browse the repository at this point in the history
Summary:
Makes the behavior in #197 the default for new projects.

Pull Request resolved: #201

Test Plan: CI, enhanced unit test

Reviewed By: krallin

Differential Revision: D45291794

Pulled By: themarwhal

fbshipit-source-id: 88111efbc8fc30201013291348e77f98c37b9e34
  • Loading branch information
Benjamin Brittain authored and facebook-github-bot committed Apr 26, 2023
1 parent 823b372 commit 2083261
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions app/buck2_client/src/commands/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ fn exec_impl(
set_up_project(&absolute, git, !cmd.no_prelude)
}

fn initialize_buckconfig(repo_root: &Path, prelude: bool) -> anyhow::Result<()> {
fn initialize_buckconfig(repo_root: &Path, prelude: bool, git: bool) -> anyhow::Result<()> {
let mut buckconfig = std::fs::File::create(repo_root.join(".buckconfig"))?;
writeln!(buckconfig, "[repositories]")?;
writeln!(buckconfig, "root = .")?;
Expand Down Expand Up @@ -146,6 +146,11 @@ fn initialize_buckconfig(repo_root: &Path, prelude: bool) -> anyhow::Result<()>
fs_util::create_dir(prelude_dir.as_path())?;
fs_util::create_file(prelude_dir.join("prelude.bzl"))?;
}
if git {
writeln!(buckconfig)?;
writeln!(buckconfig, "[project]")?;
writeln!(buckconfig, "ignore = .git")?;
}
Ok(())
}

Expand Down Expand Up @@ -248,7 +253,7 @@ fn set_up_project(repo_root: &Path, git: bool, prelude: bool) -> anyhow::Result<
return Ok(());
}

initialize_buckconfig(repo_root, prelude)?;
initialize_buckconfig(repo_root, prelude, git)?;
if prelude {
let toolchains = repo_root.join("toolchains");
if !toolchains.exists() {
Expand Down Expand Up @@ -324,7 +329,7 @@ mod tests {
fs_util::create_dir_all(tempdir_path)?;

let buckconfig_path = tempdir_path.join(".buckconfig");
initialize_buckconfig(tempdir_path, true)?;
initialize_buckconfig(tempdir_path, true, true)?;
let actual_buckconfig = fs_util::read_to_string(buckconfig_path)?;
let expected_buckconfig = "[repositories]
root = .
Expand All @@ -340,6 +345,9 @@ buck = none
[parser]
target_platform_detector_spec = target:root//...->prelude//platforms:default
[project]
ignore = .git
";
assert_eq!(actual_buckconfig, expected_buckconfig);
Ok(())
Expand All @@ -352,7 +360,7 @@ target_platform_detector_spec = target:root//...->prelude//platforms:default
fs_util::create_dir_all(tempdir_path)?;

let buckconfig_path = tempdir_path.join(".buckconfig");
initialize_buckconfig(tempdir_path, false)?;
initialize_buckconfig(tempdir_path, false, false)?;
let actual_buckconfig = fs_util::read_to_string(buckconfig_path)?;
let expected_buckconfig = "[repositories]
root = .
Expand Down

0 comments on commit 2083261

Please sign in to comment.