Skip to content

Commit

Permalink
Test dependencies on git tags and branches
Browse files Browse the repository at this point in the history
  • Loading branch information
jneem committed Nov 13, 2024
1 parent b2a6392 commit 2e928b2
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cành
6 changes: 6 additions & 0 deletions package/tests/integration/inputs/git/branch-leaf/package.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
name = "branch-leaf",
version = "0.1.0",
nickel_version = "1.9.0",
dependencies = {},
} | std.package.Manifest
6 changes: 6 additions & 0 deletions package/tests/integration/inputs/git/tag-leaf/package.ncl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
name = "leaf",
version = "0.1.0",
nickel_version = "1.9.0",
dependencies = {},
} | std.package.Manifest
1 change: 1 addition & 0 deletions package/tests/integration/inputs/git/tag-leaf/tag.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mytag
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
name = "single-git-dep",
version = "0.1.0",
nickel_version = "1.9.0",
dependencies = {
branch = 'Git { url = "https://example.com/branch-leaf", ref = 'Branch "cành" },
tag = 'Git { url = "https://example.com/tag-leaf", ref = 'Tag "mytag" },
},
} | std.package.Manifest
52 changes: 30 additions & 22 deletions package/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,32 +39,41 @@ fn set_up_git_repos(config: &mut Config) -> TempDir {
let file_name = input_path.file_name().unwrap();

let dir_path = tmp.path().join(file_name);
// TODO: allow some annotations for configuring the git structure. (e.g. branches/tags)

let run = |cmd: &mut Command| {
assert!(cmd.output().unwrap().status.success());
};

let run_in_dir = |cmd: &mut Command| {
run(cmd.current_dir(&dir_path));
};

// The rust stdlib doesn't have anything for recursively copying a directory. There are
// some crates for that, but it's easier just to shell out.
Command::new("cp")
run(Command::new("cp")
.arg("-r")
.arg(&input_path)
.arg(tmp.path())
.output()
.unwrap();

Command::new("git")
.arg("init")
.current_dir(&dir_path)
.output()
.unwrap();
Command::new("git")
.args(["add", "--all"])
.current_dir(&dir_path)
.output()
.unwrap();
Command::new("git")
.args(["commit", "-m", "initial"])
.current_dir(&dir_path)
.output()
.unwrap();
.arg(tmp.path()));

// We have some hacky ways to test branch/tag fetching: if the input contains a tag.txt file,
// make a git tag named with the contents of that file. If the input contains a branch.txt file,
// make a git branch named with the contents of that file.
let tag = std::fs::read_to_string(dir_path.join("tag.txt")).ok();
let branch = std::fs::read_to_string(dir_path.join("branch.txt")).ok();

run_in_dir(Command::new("git").arg("init"));

if let Some(branch) = branch {
run_in_dir(Command::new("git").args(["commit", "-m", "initial", "--allow-empty"]));
run_in_dir(Command::new("git").args(["checkout", "-b", branch.trim()]));
}

run_in_dir(Command::new("git").args(["add", "--all"]));
run_in_dir(Command::new("git").args(["commit", "-m", "initial"]));

if let Some(tag) = tag {
run_in_dir(Command::new("git").args(["tag", tag.trim()]));
}

let orig_url = gix::Url::try_from(format!(
"https://example.com/{}",
Expand All @@ -86,7 +95,6 @@ fn generate_lock_file(path: &str) {
let mut config = Config::default().with_cache_dir(cache_dir.path().to_owned());

let _git_dir = set_up_git_repos(&mut config);
dbg!(_git_dir.into_path());

// Make an empty git repo as the index.
Command::new("git")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
source: package/tests/integration/main.rs
expression: lock_contents
---
{
"dependencies": {
"branch": {
"Git": {
"url": "https://example.com/branch-leaf",
"id": <GENERATED>,
"path": ""
}
},
"tag": {
"Git": {
"url": "https://example.com/tag-leaf",
"id": <GENERATED>,
"path": ""
}
}
},
"packages": [
{
"source": {
"Git": {
"url": "https://example.com/branch-leaf",
"id": <GENERATED>,
"path": ""
}
},
"dependencies": {}
},
{
"source": {
"Git": {
"url": "https://example.com/tag-leaf",
"id": <GENERATED>,
"path": ""
}
},
"dependencies": {}
}
]
}

0 comments on commit 2e928b2

Please sign in to comment.