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

Check out shallowly and allow updating a checkout #115

Merged
merged 2 commits into from
Oct 7, 2024
Merged
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
31 changes: 25 additions & 6 deletions crates/ubrn_cli/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub(crate) struct GitRepoArgs {
pub(crate) repo: String,
/// The branch or tag which to checkout
#[clap(long, default_value = "main")]
#[serde(default = "GitRepoArgs::default_branch")]
#[serde(alias = "rev", alias = "ref", default = "GitRepoArgs::default_branch")]
pub(crate) branch: String,
}

Expand Down Expand Up @@ -68,12 +68,31 @@ impl GitRepoArgs {
}

pub(crate) fn checkout(&self, project_root: &Utf8Path) -> Result<()> {
// git clone --depth 1 if directory doesn't already exist
if !self.directory(project_root)?.exists() {
let mut cmd = Command::new("git");
cmd.arg("clone")
.arg(&self.repo)
.arg(self.directory(project_root)?)
.arg("--depth")
.arg("1");
run_cmd(&mut cmd)?;
}

// git fetch --depth 1 origin $branch
let mut cmd = Command::new("git");
cmd.current_dir(self.directory(project_root)?)
.arg("fetch")
.arg("--depth")
.arg("1")
.arg("origin")
.arg(&self.branch);
run_cmd(&mut cmd)?;

// git checkout $branch
let mut cmd = Command::new("git");
cmd.arg("clone")
.arg(&self.repo)
.arg(self.directory(project_root)?)
.arg("--single-branch")
.arg("--branch")
cmd.current_dir(self.directory(project_root)?)
.arg("checkout")
.arg(&self.branch);
run_cmd(&mut cmd)
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/api/config-yaml.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ rust:
branch: main
manifest-path: crates/my-api/Cargo.toml
```
In this case, the `ubrn checkout` command will clone the given repo with the branch/ref into the `rust_modules` directory of the project.
In this case, the `ubrn checkout` command will clone the given repo with the branch/ref into the `rust_modules` directory of the project. Note that instead of `branch` you can also use `rev` or `ref`.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👨‍🍳 🤌

Chef's kiss. Thank you so much.


If run a second time, no overwriting will occur.

Expand Down