Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Adding SCM option for init command #2342

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 42 additions & 3 deletions src/cli/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ pub struct Args {
// BREAK (0.27.0): Remove this option from the cli in favor of the `format` option.
#[arg(long, conflicts_with_all = ["env_file", "format"], alias = "pyproject", hide = true)]
pub pyproject_toml: bool,

/// Source Control Management used for this project
#[arg(short = 's', long = "scm", default_value = "github")]
pub scm: Option<String>,
}

/// The pixi.toml template
Expand Down Expand Up @@ -149,9 +153,42 @@ const GITIGNORE_TEMPLATE: &str = r#"
*.egg-info
"#;

const GITATTRIBUTES_TEMPLATE: &str = r#"# GitHub syntax highlighting
enum GitAttributes {
GitHub,
GitLab,
Codeberg,
}

impl GitAttributes {
fn template(&self) -> &'static str {
match self {
GitAttributes::GitHub => {
r#"# GitHub syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
"#;
"#
}
GitAttributes::GitLab => {
r#"# GitLab syntax highlighting
pixi.lock gitlab-language=yaml gitlab-generated=true
"#
}
GitAttributes::Codeberg => {
r#"# Codeberg syntax highlighting
pixi.lock linguist-language=YAML linguist-generated=true
"#
}
}
}

fn from_str(s: &str) -> Option<Self> {
match s.to_lowercase().as_str() {
"github" => Some(GitAttributes::GitHub),
"gitlab" => Some(GitAttributes::GitLab),
"codeberg" => Some(GitAttributes::Codeberg),
_ => None,
}
}
}

pub async fn execute(args: Args) -> miette::Result<()> {
let env = Environment::new();
Expand Down Expand Up @@ -412,8 +449,10 @@ pub async fn execute(args: Args) -> miette::Result<()> {
);
}

let git_attributes = GitAttributes::from_str(args.scm.unwrap().as_str()).unwrap();

// create a .gitattributes if one is missing
if let Err(e) = create_or_append_file(&gitattributes_path, GITATTRIBUTES_TEMPLATE) {
if let Err(e) = create_or_append_file(&gitattributes_path, git_attributes.template()) {
tracing::warn!(
"Warning, couldn't update '{}' because of: {}",
gitattributes_path.to_string_lossy(),
Expand Down
2 changes: 2 additions & 0 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@ impl PixiControl {
env_file: None,
format: None,
pyproject_toml: false,
scm: Some("github".to_string()),
},
}
}
Expand All @@ -278,6 +279,7 @@ impl PixiControl {
env_file: None,
format: None,
pyproject_toml: false,
scm: Some("github".to_string()),
},
}
}
Expand Down
Loading