mirror of
https://github.com/nix-community/nurl.git
synced 2024-09-11 10:10:39 +03:00
add --submodules option to fetch submodules/subrepos
This commit is contained in:
parent
47957b277c
commit
f1f814eaff
@ -16,6 +16,10 @@ pub struct Opts {
|
||||
/// The revision or reference to be fetched
|
||||
pub rev: Option<String>,
|
||||
|
||||
/// Fetch submodules instead of using the fetcher's default
|
||||
#[arg(short = 'S', long, num_args=0..=1, require_equals = true, default_missing_value = "true")]
|
||||
pub submodules: Option<bool>,
|
||||
|
||||
/// Specify the fetcher function instead of inferring from the URL
|
||||
#[arg(short, long)]
|
||||
pub fetcher: Option<FetcherFunction>,
|
||||
|
@ -14,6 +14,7 @@ impl<'a> Fetcher<'a> for BuiltinsFetchGit {
|
||||
out: &mut impl Write,
|
||||
url: &'a Url,
|
||||
rev: Option<String>,
|
||||
submodules: Option<bool>,
|
||||
args: Vec<(String, String)>,
|
||||
args_str: Vec<(String, String)>,
|
||||
overwrites: FxHashMap<String, String>,
|
||||
@ -37,6 +38,12 @@ impl<'a> Fetcher<'a> for BuiltinsFetchGit {
|
||||
writeln!(out, r#"{indent} {rev_type} = "{rev}";"#)?;
|
||||
}
|
||||
|
||||
if let Some(submodules) = overwrites.remove("submodules") {
|
||||
writeln!(out, "{indent} submodules = {submodules};")?;
|
||||
} else if matches!(submodules, Some(true)) {
|
||||
writeln!(out, "{indent} submodules = true;")?;
|
||||
}
|
||||
|
||||
for (key, value) in args {
|
||||
let value = overwrites.remove(&key).unwrap_or(value);
|
||||
writeln!(out, "{indent} {key} = {value};")?;
|
||||
@ -63,6 +70,7 @@ impl<'a> Fetcher<'a> for BuiltinsFetchGit {
|
||||
_: &mut impl Write,
|
||||
_: &'a Url,
|
||||
_: Option<String>,
|
||||
_: Option<bool>,
|
||||
_: Vec<(String, String)>,
|
||||
_: Vec<(String, String)>,
|
||||
) -> Result<()> {
|
||||
@ -74,6 +82,7 @@ impl<'a> Fetcher<'a> for BuiltinsFetchGit {
|
||||
out: &mut impl Write,
|
||||
url: &'a Url,
|
||||
rev: Option<String>,
|
||||
submodules: Option<bool>,
|
||||
args: Vec<(String, String)>,
|
||||
args_str: Vec<(String, String)>,
|
||||
overwrites: Vec<(String, String)>,
|
||||
@ -87,6 +96,10 @@ impl<'a> Fetcher<'a> for BuiltinsFetchGit {
|
||||
rev_type: rev,
|
||||
});
|
||||
|
||||
if matches!(submodules, Some(true)) {
|
||||
fetcher_args["submodules"] = json!(true);
|
||||
}
|
||||
|
||||
for (key, value) in args {
|
||||
fetcher_args[key] = json!({
|
||||
"type": "nix",
|
||||
|
@ -8,6 +8,8 @@ impl_fetcher!(Fetchgit);
|
||||
impl<'a> SimpleFetcher<'a, 1> for Fetchgit {
|
||||
const KEYS: [&'static str; 1] = ["url"];
|
||||
const NAME: &'static str = "fetchgit";
|
||||
const SUBMODULES_DEFAULT: bool = true;
|
||||
const SUBMODULES_KEY: Option<&'static str> = Some("fetchSubmodules");
|
||||
|
||||
fn get_values(&self, url: &'a Url) -> Option<[&'a str; 1]> {
|
||||
Some([if matches!(self.0, GitScheme::Plus) {
|
||||
@ -23,13 +25,14 @@ impl<'a> Fetchgit {
|
||||
&'a self,
|
||||
values @ [url]: &[&str; 1],
|
||||
rev: &str,
|
||||
submodules: bool,
|
||||
args: &[(String, String)],
|
||||
args_str: &[(String, String)],
|
||||
) -> Result<String> {
|
||||
if args.is_empty() && args_str.is_empty() {
|
||||
git_prefetch(matches!(self.0, GitScheme::Yes), url, rev)
|
||||
git_prefetch(matches!(self.0, GitScheme::Yes), url, rev, !submodules)
|
||||
} else {
|
||||
self.fetch_fod(values, rev, args, args_str)
|
||||
self.fetch_fod(values, rev, submodules, args, args_str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
impl_fetcher,
|
||||
simple::{SimpleFetcher, SimpleUrlFetcher},
|
||||
prefetch::{git_prefetch, url_prefetch},
|
||||
simple::SimpleFetcher,
|
||||
};
|
||||
|
||||
pub struct FetchFromGitea<'a>(pub &'a str);
|
||||
@ -17,6 +18,7 @@ struct Commit {
|
||||
impl SimpleFetcher<'_, 2> for FetchFromGitea<'_> {
|
||||
const KEYS: [&'static str; 2] = ["owner", "repo"];
|
||||
const NAME: &'static str = "fetchFromGitea";
|
||||
const SUBMODULES_KEY: Option<&'static str> = Some("fetchSubmodules");
|
||||
|
||||
fn host(&self) -> Option<&str> {
|
||||
Some(self.0)
|
||||
@ -37,8 +39,31 @@ impl SimpleFetcher<'_, 2> for FetchFromGitea<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SimpleUrlFetcher<'a, 2> for FetchFromGitea<'a> {
|
||||
fn get_url(&self, [owner, repo]: &[&str; 2], rev: &str) -> String {
|
||||
format!("https://{}/{owner}/{repo}/archive/{rev}.tar.gz", self.0)
|
||||
impl FetchFromGitea<'_> {
|
||||
fn fetch(
|
||||
&self,
|
||||
values @ [owner, repo]: &[&str; 2],
|
||||
rev: &str,
|
||||
submodules: bool,
|
||||
args: &[(String, String)],
|
||||
args_str: &[(String, String)],
|
||||
) -> Result<String> {
|
||||
if args.is_empty() && args_str.is_empty() {
|
||||
if submodules {
|
||||
git_prefetch(
|
||||
true,
|
||||
&format!("git+https://{}/{owner}/{repo}", self.0),
|
||||
rev,
|
||||
true,
|
||||
)
|
||||
} else {
|
||||
url_prefetch(
|
||||
format!("https://{}/{owner}/{repo}/archive/{rev}.tar.gz", self.0),
|
||||
true,
|
||||
)
|
||||
}
|
||||
} else {
|
||||
self.fetch_fod(values, rev, submodules, args, args_str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use serde::Deserialize;
|
||||
|
||||
use crate::{
|
||||
impl_fetcher,
|
||||
simple::{SimpleFetcher, SimpleFlakeFetcher},
|
||||
simple::{SimpleFetcher, SimpleGitFetcher},
|
||||
};
|
||||
|
||||
pub struct FetchFromGitHub<'a>(pub Option<&'a str>);
|
||||
@ -18,6 +18,7 @@ impl SimpleFetcher<'_, 2> for FetchFromGitHub<'_> {
|
||||
const HOST_KEY: &'static str = "githubBase";
|
||||
const KEYS: [&'static str; 2] = ["owner", "repo"];
|
||||
const NAME: &'static str = "fetchFromGitHub";
|
||||
const SUBMODULES_KEY: Option<&'static str> = Some("fetchSubmodules");
|
||||
|
||||
fn host(&self) -> Option<&str> {
|
||||
self.0
|
||||
@ -36,7 +37,7 @@ impl SimpleFetcher<'_, 2> for FetchFromGitHub<'_> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SimpleFlakeFetcher<'a, 2> for FetchFromGitHub<'a> {
|
||||
impl<'a> SimpleGitFetcher<'a, 2> for FetchFromGitHub<'a> {
|
||||
fn get_flake_ref(&self, [owner, repo]: &[&str; 2], rev: &str) -> String {
|
||||
if let Some(host) = self.0 {
|
||||
format!("github:{owner}/{repo}/{rev}?host={host}")
|
||||
@ -44,4 +45,11 @@ impl<'a> SimpleFlakeFetcher<'a, 2> for FetchFromGitHub<'a> {
|
||||
format!("github:{owner}/{repo}/{rev}")
|
||||
}
|
||||
}
|
||||
|
||||
fn get_repo_url(&self, [owner, repo]: &[&str; 2]) -> String {
|
||||
format!(
|
||||
"git+https://{}/{owner}/{repo}",
|
||||
self.0.unwrap_or("github.com"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ use std::fmt::Write;
|
||||
|
||||
use crate::{
|
||||
impl_fetcher,
|
||||
simple::{SimpleFetcher, SimpleFlakeFetcher},
|
||||
simple::{SimpleFetcher, SimpleGitFetcher},
|
||||
Url,
|
||||
};
|
||||
|
||||
@ -33,6 +33,7 @@ struct Commit {
|
||||
impl<'a> SimpleFetcher<'a, 2> for FetchFromGitLab<'a> {
|
||||
const KEYS: [&'static str; 2] = ["owner", "repo"];
|
||||
const NAME: &'static str = "fetchFromGitLab";
|
||||
const SUBMODULES_KEY: Option<&'static str> = Some("fetchSubmodules");
|
||||
|
||||
fn host(&self) -> Option<&str> {
|
||||
self.host
|
||||
@ -84,7 +85,7 @@ impl<'a> SimpleFetcher<'a, 2> for FetchFromGitLab<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SimpleFlakeFetcher<'a, 2> for FetchFromGitLab<'a> {
|
||||
impl<'a> SimpleGitFetcher<'a, 2> for FetchFromGitLab<'a> {
|
||||
fn get_flake_ref(&self, [owner, repo]: &[&str; 2], rev: &str) -> String {
|
||||
let mut flake_ref = String::from("gitlab:");
|
||||
if let Some(group) = self.group.get() {
|
||||
@ -102,4 +103,18 @@ impl<'a> SimpleFlakeFetcher<'a, 2> for FetchFromGitLab<'a> {
|
||||
}
|
||||
flake_ref
|
||||
}
|
||||
|
||||
fn get_repo_url(&self, [owner, repo]: &[&str; 2]) -> String {
|
||||
let mut flake_ref = String::from("git+https://");
|
||||
flake_ref.push_str(self.host.unwrap_or("gitlab.com"));
|
||||
flake_ref.push('/');
|
||||
if let Some(group) = self.group.get() {
|
||||
flake_ref.push_str(group);
|
||||
flake_ref.push('/');
|
||||
}
|
||||
flake_ref.push_str(owner);
|
||||
flake_ref.push('/');
|
||||
flake_ref.push_str(repo);
|
||||
flake_ref
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ impl<'a> SimpleFetcher<'a, 1> for Fetchhg {
|
||||
const HASH_KEY: &'static str = "sha256";
|
||||
const KEYS: [&'static str; 1] = ["url"];
|
||||
const NAME: &'static str = "fetchhg";
|
||||
const SUBMODULES_KEY: Option<&'static str> = Some("fetchSubrepos");
|
||||
|
||||
fn get_values(&self, url: &'a Url) -> Option<[&'a str; 1]> {
|
||||
Some([if self.0 {
|
||||
@ -22,10 +23,11 @@ impl<'a> SimpleFetcher<'a, 1> for Fetchhg {
|
||||
}
|
||||
|
||||
impl SimpleFlakeFetcher<'_, 1> for Fetchhg {
|
||||
fn get_flake_ref(&self, [url]: &[&str; 1], rev: &str) -> String {
|
||||
fn get_flake_ref(&self, [url]: &[&str; 1], rev: &str, submodules: bool) -> String {
|
||||
format!(
|
||||
"hg+{url}?{}={rev}",
|
||||
"hg+{url}?{}={rev}{}",
|
||||
if rev.len() == 40 { "rev" } else { "ref" },
|
||||
if submodules { "&submodules=1" } else { "" },
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,7 @@ pub trait Fetcher<'a> {
|
||||
out: &mut impl Write,
|
||||
url: &'a Url,
|
||||
rev: Option<String>,
|
||||
submodules: Option<bool>,
|
||||
args: Vec<(String, String)>,
|
||||
args_str: Vec<(String, String)>,
|
||||
overwrites: FxHashMap<String, String>,
|
||||
@ -53,6 +54,7 @@ pub trait Fetcher<'a> {
|
||||
out: &mut impl Write,
|
||||
url: &'a Url,
|
||||
rev: Option<String>,
|
||||
submodules: Option<bool>,
|
||||
args: Vec<(String, String)>,
|
||||
args_str: Vec<(String, String)>,
|
||||
) -> Result<()>;
|
||||
@ -62,6 +64,7 @@ pub trait Fetcher<'a> {
|
||||
out: &mut impl Write,
|
||||
url: &'a Url,
|
||||
rev: Option<String>,
|
||||
submodules: Option<bool>,
|
||||
args: Vec<(String, String)>,
|
||||
args_str: Vec<(String, String)>,
|
||||
overwrites: Vec<(String, String)>,
|
||||
@ -98,6 +101,7 @@ macro_rules! impl_fetcher {
|
||||
out: &mut impl ::std::io::Write,
|
||||
url: &'a $crate::Url,
|
||||
rev: Option<String>,
|
||||
submodules: Option<bool>,
|
||||
args: Vec<(String, String)>,
|
||||
args_str: Vec<(String, String)>,
|
||||
overwrites: ::rustc_hash::FxHashMap<String, String>,
|
||||
@ -114,9 +118,10 @@ macro_rules! impl_fetcher {
|
||||
None => self.fetch_rev(values)?,
|
||||
};
|
||||
|
||||
let hash = self.fetch(values, &rev, &args, &args_str)?;
|
||||
let submodules = self.resolve_submodules(submodules);
|
||||
let hash = self.fetch(values, &rev, submodules, &args, &args_str)?;
|
||||
|
||||
self.write_nix(out, values, rev, hash, args, args_str, overwrites, indent)
|
||||
self.write_nix(out, values, rev, hash, submodules, args, args_str, overwrites, indent)
|
||||
}
|
||||
|
||||
fn fetch_hash(
|
||||
@ -124,6 +129,7 @@ macro_rules! impl_fetcher {
|
||||
out: &mut impl ::std::io::Write,
|
||||
url: &'a $crate::Url,
|
||||
rev: Option<String>,
|
||||
submodules: Option<bool>,
|
||||
args: Vec<(String, String)>,
|
||||
args_str: Vec<(String, String)>,
|
||||
) -> ::anyhow::Result<()> {
|
||||
@ -138,7 +144,8 @@ macro_rules! impl_fetcher {
|
||||
None => self.fetch_rev(values)?,
|
||||
};
|
||||
|
||||
let hash = self.fetch(values, &rev, &args, &args_str)?;
|
||||
let submodules = self.resolve_submodules(submodules);
|
||||
let hash = self.fetch(values, &rev, submodules, &args, &args_str)?;
|
||||
write!(out, "{}", hash)?;
|
||||
|
||||
Ok(())
|
||||
@ -149,6 +156,7 @@ macro_rules! impl_fetcher {
|
||||
out: &mut impl ::std::io::Write,
|
||||
url: &'a $crate::Url,
|
||||
rev: Option<String>,
|
||||
submodules: Option<bool>,
|
||||
args: Vec<(String, String)>,
|
||||
args_str: Vec<(String, String)>,
|
||||
overwrites: Vec<(String, String)>,
|
||||
@ -165,13 +173,15 @@ macro_rules! impl_fetcher {
|
||||
None => self.fetch_rev(values)?,
|
||||
};
|
||||
|
||||
let hash = self.fetch(values, &rev, &args, &args_str)?;
|
||||
let submodules = self.resolve_submodules(submodules);
|
||||
let hash = self.fetch(values, &rev, submodules, &args, &args_str)?;
|
||||
|
||||
self.write_json(
|
||||
out,
|
||||
values,
|
||||
rev,
|
||||
hash,
|
||||
submodules,
|
||||
args,
|
||||
args_str,
|
||||
overwrites,
|
||||
|
@ -1,6 +1,6 @@
|
||||
use crate::{
|
||||
impl_fetcher,
|
||||
simple::{SimpleFetcher, SimpleFlakeFetcher},
|
||||
simple::{SimpleFetcher, SimpleGitFetcher},
|
||||
};
|
||||
|
||||
pub struct FetchFromSourcehut<'a>(pub Option<&'a str>);
|
||||
@ -9,13 +9,14 @@ impl_fetcher!(FetchFromSourcehut<'a>);
|
||||
impl<'a> SimpleFetcher<'a, 2> for FetchFromSourcehut<'a> {
|
||||
const KEYS: [&'static str; 2] = ["owner", "repo"];
|
||||
const NAME: &'static str = "fetchFromSourcehut";
|
||||
const SUBMODULES_KEY: Option<&'static str> = Some("fetchSubmodules");
|
||||
|
||||
fn host(&self) -> Option<&str> {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> SimpleFlakeFetcher<'a, 2> for FetchFromSourcehut<'a> {
|
||||
impl<'a> SimpleGitFetcher<'a, 2> for FetchFromSourcehut<'a> {
|
||||
fn get_flake_ref(&self, [owner, repo]: &[&str; 2], rev: &str) -> String {
|
||||
if let Some(host) = self.0 {
|
||||
format!("sourcehut:{owner}/{repo}/{rev}?host={host}")
|
||||
@ -23,4 +24,11 @@ impl<'a> SimpleFlakeFetcher<'a, 2> for FetchFromSourcehut<'a> {
|
||||
format!("sourcehut:{owner}/{repo}/{rev}")
|
||||
}
|
||||
}
|
||||
|
||||
fn get_repo_url(&self, [owner, repo]: &[&str; 2]) -> String {
|
||||
format!(
|
||||
"git+https://{}/{owner}/{repo}",
|
||||
self.0.unwrap_or("git.sr.ht"),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -229,12 +229,13 @@ fn main() -> Result<()> {
|
||||
let args = opts.args.into_iter().tuples().collect();
|
||||
let args_str = opts.args_str.into_iter().tuples().collect();
|
||||
if opts.hash {
|
||||
fetcher.fetch_hash(out, &url, opts.rev, args, args_str)
|
||||
fetcher.fetch_hash(out, &url, opts.rev, opts.submodules, args, args_str)
|
||||
} else if opts.json {
|
||||
fetcher.fetch_json(
|
||||
out,
|
||||
&url,
|
||||
opts.rev,
|
||||
opts.submodules,
|
||||
args,
|
||||
args_str,
|
||||
opts.overwrites.into_iter().tuples().collect(),
|
||||
@ -253,6 +254,7 @@ fn main() -> Result<()> {
|
||||
out,
|
||||
&url,
|
||||
opts.rev,
|
||||
opts.submodules,
|
||||
args,
|
||||
args_str,
|
||||
overwrites,
|
||||
|
@ -52,20 +52,21 @@ pub fn flake_prefetch(flake_ref: String) -> Result<String> {
|
||||
}
|
||||
|
||||
// work around for https://github.com/NixOS/nix/issues/5291
|
||||
pub fn git_prefetch(git_scheme: bool, url: &str, rev: &str) -> Result<String> {
|
||||
pub fn git_prefetch(git_scheme: bool, url: &str, rev: &str, submodules: bool) -> Result<String> {
|
||||
let prefix = if git_scheme { "" } else { "git+" };
|
||||
let submodules = if submodules { "&submodules=1" } else { "" };
|
||||
|
||||
if rev.len() == 40 {
|
||||
flake_prefetch(format!("{prefix}{url}?rev={rev}&submodules=1"))
|
||||
flake_prefetch(format!("{prefix}{url}?rev={rev}{submodules}"))
|
||||
} else {
|
||||
if !rev.starts_with("refs/") {
|
||||
if let hash @ Ok(_) =
|
||||
flake_prefetch(format!("{prefix}{url}?ref=refs/tags/{rev}&submodules=1"))
|
||||
flake_prefetch(format!("{prefix}{url}?ref=refs/tags/{rev}{submodules}"))
|
||||
{
|
||||
return hash;
|
||||
}
|
||||
}
|
||||
flake_prefetch(format!("{prefix}{url}?ref={rev}&submodules=1"))
|
||||
flake_prefetch(format!("{prefix}{url}?ref={rev}{submodules}"))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::Url;
|
||||
use crate::{prefetch::git_prefetch, Url};
|
||||
use anyhow::{bail, Result};
|
||||
use itertools::Itertools;
|
||||
use rustc_hash::FxHashMap;
|
||||
@ -14,6 +14,8 @@ pub trait SimpleFetcher<'a, const N: usize> {
|
||||
const KEYS: [&'static str; N];
|
||||
const NAME: &'static str;
|
||||
const REV_KEY: &'static str = "rev";
|
||||
const SUBMODULES_DEFAULT: bool = false;
|
||||
const SUBMODULES_KEY: Option<&'static str> = None;
|
||||
|
||||
fn host(&self) -> Option<&str> {
|
||||
None
|
||||
@ -36,6 +38,10 @@ pub trait SimpleFetcher<'a, const N: usize> {
|
||||
Some(xs)
|
||||
}
|
||||
|
||||
fn resolve_submodules(&self, submodules: Option<bool>) -> bool {
|
||||
submodules.map_or(false, |submodules| submodules ^ Self::SUBMODULES_DEFAULT)
|
||||
}
|
||||
|
||||
fn fetch_rev(&self, _: &[&str; N]) -> Result<String> {
|
||||
bail!(
|
||||
"{} does not support fetching the latest revision",
|
||||
@ -47,6 +53,7 @@ pub trait SimpleFetcher<'a, const N: usize> {
|
||||
&self,
|
||||
values: &[&str; N],
|
||||
rev: &str,
|
||||
submodules: bool,
|
||||
args: &[(String, String)],
|
||||
args_str: &[(String, String)],
|
||||
) -> Result<String> {
|
||||
@ -71,6 +78,12 @@ pub trait SimpleFetcher<'a, const N: usize> {
|
||||
Self::HASH_KEY,
|
||||
)?;
|
||||
|
||||
if submodules {
|
||||
if let Some(key) = Self::SUBMODULES_KEY {
|
||||
write!(expr, "{key}={};", !Self::SUBMODULES_DEFAULT)?;
|
||||
}
|
||||
}
|
||||
|
||||
for (key, value) in args {
|
||||
write!(expr, "{key}={value};")?;
|
||||
}
|
||||
@ -89,6 +102,7 @@ pub trait SimpleFetcher<'a, const N: usize> {
|
||||
values: &[&str; N],
|
||||
rev: String,
|
||||
hash: String,
|
||||
submodules: bool,
|
||||
args: Vec<(String, String)>,
|
||||
args_str: Vec<(String, String)>,
|
||||
overwrites: FxHashMap<String, String>,
|
||||
@ -129,6 +143,14 @@ pub trait SimpleFetcher<'a, const N: usize> {
|
||||
writeln!(out, r#"{indent} {} = "{hash}";"#, Self::HASH_KEY)?;
|
||||
}
|
||||
|
||||
if let Some(key) = Self::SUBMODULES_KEY {
|
||||
if let Some(submodules) = overwrites.remove(key) {
|
||||
writeln!(out, "{indent} {key} = {submodules};")?;
|
||||
} else if submodules {
|
||||
writeln!(out, "{indent} {key} = {};", !Self::SUBMODULES_DEFAULT)?;
|
||||
}
|
||||
}
|
||||
|
||||
for (key, value) in args {
|
||||
let value = overwrites.remove(&key).unwrap_or(value);
|
||||
writeln!(out, "{indent} {key} = {value};")?;
|
||||
@ -156,6 +178,7 @@ pub trait SimpleFetcher<'a, const N: usize> {
|
||||
values: &[&str; N],
|
||||
rev: String,
|
||||
hash: String,
|
||||
submodules: bool,
|
||||
args: Vec<(String, String)>,
|
||||
args_str: Vec<(String, String)>,
|
||||
overwrites: Vec<(String, String)>,
|
||||
@ -174,6 +197,12 @@ pub trait SimpleFetcher<'a, const N: usize> {
|
||||
fetcher_args["group"] = json!(group);
|
||||
}
|
||||
|
||||
if submodules {
|
||||
if let Some(key) = Self::SUBMODULES_KEY {
|
||||
fetcher_args[key] = json!(!Self::SUBMODULES_DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
for (key, value) in args {
|
||||
fetcher_args[key] = json!({
|
||||
"type": "nix",
|
||||
@ -211,27 +240,59 @@ pub trait SimpleFodFetcher<'a, const N: usize>: SimpleFetcher<'a, N> {
|
||||
&self,
|
||||
values: &[&str; N],
|
||||
rev: &str,
|
||||
submodules: bool,
|
||||
args: &[(String, String)],
|
||||
args_str: &[(String, String)],
|
||||
) -> Result<String> {
|
||||
self.fetch_fod(values, rev, args, args_str)
|
||||
self.fetch_fod(values, rev, submodules, args, args_str)
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SimpleFlakeFetcher<'a, const N: usize>: SimpleFetcher<'a, N> {
|
||||
fn get_flake_ref(&self, values: &[&str; N], rev: &str) -> String;
|
||||
fn get_flake_ref(&self, values: &[&str; N], rev: &str, submodules: bool) -> String;
|
||||
|
||||
fn fetch(
|
||||
&self,
|
||||
values: &[&str; N],
|
||||
rev: &str,
|
||||
submodules: bool,
|
||||
args: &[(String, String)],
|
||||
args_str: &[(String, String)],
|
||||
) -> Result<String> {
|
||||
if args.is_empty() && args_str.is_empty() {
|
||||
flake_prefetch(self.get_flake_ref(values, rev))
|
||||
flake_prefetch(self.get_flake_ref(values, rev, submodules))
|
||||
} else {
|
||||
self.fetch_fod(values, rev, args, args_str)
|
||||
self.fetch_fod(values, rev, submodules, args, args_str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait SimpleGitFetcher<'a, const N: usize>: SimpleFetcher<'a, N> {
|
||||
fn get_flake_ref(&self, values: &[&str; N], rev: &str) -> String;
|
||||
|
||||
fn get_repo_url(&self, values: &[&str; N]) -> String;
|
||||
|
||||
fn fetch(
|
||||
&self,
|
||||
values: &[&str; N],
|
||||
rev: &str,
|
||||
submodules: bool,
|
||||
args: &[(String, String)],
|
||||
args_str: &[(String, String)],
|
||||
) -> Result<String> {
|
||||
if args.is_empty() && args_str.is_empty() {
|
||||
if submodules {
|
||||
git_prefetch(
|
||||
true,
|
||||
&self.get_repo_url(values),
|
||||
rev,
|
||||
!Self::SUBMODULES_DEFAULT,
|
||||
)
|
||||
} else {
|
||||
flake_prefetch(self.get_flake_ref(values, rev))
|
||||
}
|
||||
} else {
|
||||
self.fetch_fod(values, rev, submodules, args, args_str)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -245,13 +306,14 @@ pub trait SimpleUrlFetcher<'a, const N: usize>: SimpleFetcher<'a, N> {
|
||||
&self,
|
||||
values: &[&str; N],
|
||||
rev: &str,
|
||||
submodules: bool,
|
||||
args: &[(String, String)],
|
||||
args_str: &[(String, String)],
|
||||
) -> Result<String> {
|
||||
if args.is_empty() && args_str.is_empty() {
|
||||
url_prefetch(self.get_url(values, rev), Self::UNPACK)
|
||||
} else {
|
||||
self.fetch_fod(values, rev, args, args_str)
|
||||
self.fetch_fod(values, rev, submodules, args, args_str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
5
tests/cmd/submodules/builtin_git.stdout
Normal file
5
tests/cmd/submodules/builtin_git.stdout
Normal file
@ -0,0 +1,5 @@
|
||||
builtins.fetchGit {
|
||||
url = "https://github.com/Koihik/LuaFormatter";
|
||||
ref = "refs/tags/1.3.0";
|
||||
submodules = true;
|
||||
}
|
7
tests/cmd/submodules/builtin_git.toml
Normal file
7
tests/cmd/submodules/builtin_git.toml
Normal file
@ -0,0 +1,7 @@
|
||||
args = [
|
||||
"https://github.com/Koihik/LuaFormatter",
|
||||
"refs/tags/1.3.0",
|
||||
"--submodules",
|
||||
"--fetcher",
|
||||
"builtins.fetchGit",
|
||||
]
|
6
tests/cmd/submodules/false.stdout
Normal file
6
tests/cmd/submodules/false.stdout
Normal file
@ -0,0 +1,6 @@
|
||||
fetchgit {
|
||||
url = "https://github.com/Koihik/LuaFormatter";
|
||||
rev = "1.3.0";
|
||||
hash = "sha256-UrADnTFH8y1rqA2LytSK9HkIQdxOIrY4CwqfL139Oag=";
|
||||
fetchSubmodules = false;
|
||||
}
|
7
tests/cmd/submodules/false.toml
Normal file
7
tests/cmd/submodules/false.toml
Normal file
@ -0,0 +1,7 @@
|
||||
args = [
|
||||
"https://github.com/Koihik/LuaFormatter",
|
||||
"1.3.0",
|
||||
"--submodules=false",
|
||||
"--fetcher",
|
||||
"fetchgit",
|
||||
]
|
5
tests/cmd/submodules/git.stdout
Normal file
5
tests/cmd/submodules/git.stdout
Normal file
@ -0,0 +1,5 @@
|
||||
fetchgit {
|
||||
url = "https://github.com/Koihik/LuaFormatter";
|
||||
rev = "1.3.0";
|
||||
hash = "sha256-O42sNIFDi2Dv6KWkBynrR60RABCAitSVTp42W6w0tcg=";
|
||||
}
|
7
tests/cmd/submodules/git.toml
Normal file
7
tests/cmd/submodules/git.toml
Normal file
@ -0,0 +1,7 @@
|
||||
args = [
|
||||
"https://github.com/Koihik/LuaFormatter",
|
||||
"1.3.0",
|
||||
"--submodules",
|
||||
"--fetcher",
|
||||
"fetchgit",
|
||||
]
|
8
tests/cmd/submodules/gitea.stdout
Normal file
8
tests/cmd/submodules/gitea.stdout
Normal file
@ -0,0 +1,8 @@
|
||||
fetchFromGitea {
|
||||
domain = "repo.palemoon.org";
|
||||
owner = "MoonchildProductions";
|
||||
repo = "Pale-Moon";
|
||||
rev = "31.0.0_Release";
|
||||
hash = "sha256-fIQAQCtjA/9Otft3e9Z4xWgE09sqsdArYQtZqmEgfTc=";
|
||||
fetchSubmodules = true;
|
||||
}
|
7
tests/cmd/submodules/gitea.toml
Normal file
7
tests/cmd/submodules/gitea.toml
Normal file
@ -0,0 +1,7 @@
|
||||
args = [
|
||||
"https://repo.palemoon.org/MoonchildProductions/Pale-Moon",
|
||||
"31.0.0_Release",
|
||||
"--submodules",
|
||||
"--fetcher",
|
||||
"fetchFromGitea",
|
||||
]
|
1
tests/cmd/submodules/github.toml
Normal file
1
tests/cmd/submodules/github.toml
Normal file
@ -0,0 +1 @@
|
||||
args = ["https://github.com/Koihik/LuaFormatter", "1.3.0", "--submodules"]
|
8
tests/cmd/submodules/gitlab.stdout
Normal file
8
tests/cmd/submodules/gitlab.stdout
Normal file
@ -0,0 +1,8 @@
|
||||
fetchFromGitLab {
|
||||
group = "librewolf-community";
|
||||
owner = "browser";
|
||||
repo = "source";
|
||||
rev = "100.0-1";
|
||||
hash = "sha256-ijqyZAEKyL7V/NFtI3ErHcSnj7VbBFvgCgK9NJren/U=";
|
||||
fetchSubmodules = true;
|
||||
}
|
5
tests/cmd/submodules/gitlab.toml
Normal file
5
tests/cmd/submodules/gitlab.toml
Normal file
@ -0,0 +1,5 @@
|
||||
args = [
|
||||
"https://gitlab.com/librewolf-community/browser/source",
|
||||
"100.0-1",
|
||||
"--submodules",
|
||||
]
|
6
tests/cmd/submodules/hg.stdout
Normal file
6
tests/cmd/submodules/hg.stdout
Normal file
@ -0,0 +1,6 @@
|
||||
fetchhg {
|
||||
url = "http://www.octave.org/hg/octave";
|
||||
rev = "release-7-1-0";
|
||||
sha256 = "sha256-zNpgpPPGAoIpSIRx39wJpEyLbxjJBsnFjUy47hGiZLs=";
|
||||
fetchSubrepos = true;
|
||||
}
|
7
tests/cmd/submodules/hg.toml
Normal file
7
tests/cmd/submodules/hg.toml
Normal file
@ -0,0 +1,7 @@
|
||||
args = [
|
||||
"http://www.octave.org/hg/octave",
|
||||
"release-7-1-0",
|
||||
"--submodules",
|
||||
"--fetcher",
|
||||
"fetchhg",
|
||||
]
|
1
tests/cmd/submodules/json.stdout
Normal file
1
tests/cmd/submodules/json.stdout
Normal file
@ -0,0 +1 @@
|
||||
{"args":{"fetchSubmodules":true,"hash":"sha256-O42sNIFDi2Dv6KWkBynrR60RABCAitSVTp42W6w0tcg=","owner":"Koihik","repo":"LuaFormatter","rev":"1.3.0"},"fetcher":"fetchFromGitHub"}
|
6
tests/cmd/submodules/json.toml
Normal file
6
tests/cmd/submodules/json.toml
Normal file
@ -0,0 +1,6 @@
|
||||
args = [
|
||||
"https://github.com/Koihik/LuaFormatter",
|
||||
"1.3.0",
|
||||
"--submodules",
|
||||
"--json",
|
||||
]
|
7
tests/cmd/submodules/sourcehut.stdout
Normal file
7
tests/cmd/submodules/sourcehut.stdout
Normal file
@ -0,0 +1,7 @@
|
||||
fetchFromSourcehut {
|
||||
owner = "~cnx";
|
||||
repo = "blackshades";
|
||||
rev = "2.4.0";
|
||||
hash = "sha256-owsP50zYFV1Z+c0bSUaHmnvH+BywfJSp7oSk3ys/+GM=";
|
||||
fetchSubmodules = true;
|
||||
}
|
1
tests/cmd/submodules/sourcehut.toml
Normal file
1
tests/cmd/submodules/sourcehut.toml
Normal file
@ -0,0 +1 @@
|
||||
args = ["https://git.sr.ht/~cnx/blackshades", "2.4.0", "--submodules"]
|
7
tests/cmd/submodules/true.stdout
Normal file
7
tests/cmd/submodules/true.stdout
Normal file
@ -0,0 +1,7 @@
|
||||
fetchFromGitHub {
|
||||
owner = "Koihik";
|
||||
repo = "LuaFormatter";
|
||||
rev = "1.3.0";
|
||||
hash = "sha256-O42sNIFDi2Dv6KWkBynrR60RABCAitSVTp42W6w0tcg=";
|
||||
fetchSubmodules = true;
|
||||
}
|
1
tests/cmd/submodules/true.toml
Normal file
1
tests/cmd/submodules/true.toml
Normal file
@ -0,0 +1 @@
|
||||
args = ["https://github.com/Koihik/LuaFormatter", "1.3.0", "--submodules=true"]
|
5
tests/cmd/submodules/unsupported.stdout
Normal file
5
tests/cmd/submodules/unsupported.stdout
Normal file
@ -0,0 +1,5 @@
|
||||
fetchCrate {
|
||||
pname = "nurl";
|
||||
version = "0.3.0";
|
||||
hash = "sha256-B6T4DEhE2Jq3YSL+b//27gRkQlvqhynSMBCGdYD5Gog=";
|
||||
}
|
1
tests/cmd/submodules/unsupported.toml
Normal file
1
tests/cmd/submodules/unsupported.toml
Normal file
@ -0,0 +1 @@
|
||||
args = ["https://crates.io/crates/nurl", "0.3.0", "--submodules"]
|
Loading…
Reference in New Issue
Block a user