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

Modified git fetch command to method to use correct root folder. #6119

Merged
merged 4 commits into from
Oct 26, 2023
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
3 changes: 2 additions & 1 deletion crates/cli/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,11 +363,12 @@ impl<'a> Git<'a> {
}

pub fn fetch(
self,
shallow: bool,
remote: impl AsRef<OsStr>,
branch: Option<impl AsRef<OsStr>>,
) -> Result<()> {
Self::cmd_no_root()
self.cmd()
.stderr(Stdio::inherit())
.arg("fetch")
.args(shallow.then_some("--no-tags"))
Expand Down
2 changes: 1 addition & 1 deletion crates/forge/bin/cmd/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl InitArgs {

// fetch the template - always fetch shallow for templates since git history will be
// collapsed. gitmodules will be initialized after the template is fetched
Git::fetch(true, &template, branch)?;
git.fetch(true, &template, branch)?;
// reset git history to the head of the template
// first get the commit hash that was fetched
let commit_hash = git.commit_hash(true, "FETCH_HEAD")?;
Expand Down
36 changes: 36 additions & 0 deletions crates/forge/tests/cli/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,42 @@ forgetest!(can_init_with_dir, |prj: TestProject, mut cmd: TestCommand| {
assert!(prj.root().join("foobar").exists());
});

// `forge init foobar --template [template]` works with dir argument
forgetest!(can_init_with_dir_and_template, |prj: TestProject, mut cmd: TestCommand| {
cmd.args(["init", "foobar", "--template", "foundry-rs/forge-template"]);

cmd.assert_success();
cmd.assert_non_empty_stdout();
assert!(prj.root().join("foobar/.git").exists());
assert!(prj.root().join("foobar/foundry.toml").exists());
assert!(prj.root().join("foobar/lib/forge-std").exists());
// assert that gitmodules were correctly initialized
assert!(prj.root().join("foobar/.git/modules").exists());
assert!(prj.root().join("foobar/src").exists());
assert!(prj.root().join("foobar/test").exists());
});

// `forge init foobar --template [template] --branch [branch]` works with dir argument
forgetest!(can_init_with_dir_and_template_and_branch, |prj: TestProject, mut cmd: TestCommand| {
cmd.args([
"init",
"foobar",
"--template",
"foundry-rs/forge-template",
"--branch",
"test/deployments",
]);

cmd.assert_success();
cmd.assert_non_empty_stdout();
assert!(prj.root().join("foobar/.dapprc").exists());
assert!(prj.root().join("foobar/lib/ds-test").exists());
// assert that gitmodules were correctly initialized
assert!(prj.root().join("foobar/.git/modules").exists());
assert!(prj.root().join("foobar/src").exists());
assert!(prj.root().join("foobar/scripts").exists());
});

// `forge init --force` works on non-empty dirs
forgetest!(can_init_non_empty, |prj: TestProject, mut cmd: TestCommand| {
prj.create_file("README.md", "non-empty dir");
Expand Down