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: --no-git to cargo shuttle init #1501

Merged
merged 5 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 3 additions & 0 deletions cargo-shuttle/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,9 @@ pub struct InitArgs {
/// Whether to start the container for this project on Shuttle, and claim the project name
#[arg(long)]
pub create_env: bool,
/// Whethere to initialize git repository or not during the init command
#[arg(long)]
pub no_git: bool,
#[command(flatten)]
pub login_args: LoginArgs,
}
Expand Down
16 changes: 12 additions & 4 deletions cargo-shuttle/src/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ use url::Url;

use crate::args::TemplateLocation;

pub fn generate_project(dest: PathBuf, name: &str, temp_loc: TemplateLocation) -> Result<()> {
pub fn generate_project(
dest: PathBuf,
name: &str,
temp_loc: TemplateLocation,
no_git: bool
) -> Result<()> {
println!(r#"Creating project "{name}" in "{}""#, dest.display());

let temp_dir: TempDir = setup_template(&temp_loc.auto_path)
Expand Down Expand Up @@ -52,9 +57,12 @@ pub fn generate_project(dest: PathBuf, name: &str, temp_loc: TemplateLocation) -

// Initialize a Git repository in the destination directory if there
// is no existing Git repository present in the surrounding folders.
let no_git_repo = gix::discover(&dest).is_err();
if no_git_repo {
gix::init(&dest).context("Failed to initialize project repository")?;
// only if no-git argument is not passed otherwise initialize git repo
if !no_git {
let no_git_repo = gix::discover(&dest).is_err();
if no_git_repo {
gix::init(&dest).context("Failed to initialize project repository")?;
}
}

Ok(())
Expand Down
2 changes: 2 additions & 0 deletions cargo-shuttle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ impl Shuttle {
) -> Result<CommandOutcome> {
// Turns the template or git args (if present) to a repo+folder.
let git_template = args.git_template()?;
let no_git = args.no_git;

let unauthorized = self.ctx.api_key().is_err() && args.login_args.api_key.is_none();

Expand Down Expand Up @@ -459,6 +460,7 @@ impl Shuttle {
.as_ref()
.expect("to have a project name provided"),
template,
no_git,
)?;
println!();

Expand Down