@@ -248,6 +248,7 @@ def test_repos_find_remote_user_empty(
|
|||||||
@pytest.mark.parametrize("force_ssh", [True, False])
|
@pytest.mark.parametrize("force_ssh", [True, False])
|
||||||
@pytest.mark.parametrize("use_alternate_endpoint", [True, False])
|
@pytest.mark.parametrize("use_alternate_endpoint", [True, False])
|
||||||
@pytest.mark.parametrize("use_config", [True, False])
|
@pytest.mark.parametrize("use_config", [True, False])
|
||||||
|
@pytest.mark.parametrize("override_remote_name", [True, False])
|
||||||
def test_repos_find_remote_user(
|
def test_repos_find_remote_user(
|
||||||
provider,
|
provider,
|
||||||
configtype,
|
configtype,
|
||||||
@@ -258,6 +259,7 @@ def test_repos_find_remote_user(
|
|||||||
force_ssh,
|
force_ssh,
|
||||||
use_alternate_endpoint,
|
use_alternate_endpoint,
|
||||||
use_config,
|
use_config,
|
||||||
|
override_remote_name,
|
||||||
):
|
):
|
||||||
if use_config:
|
if use_config:
|
||||||
with tempfile.NamedTemporaryFile() as config:
|
with tempfile.NamedTemporaryFile() as config:
|
||||||
@@ -274,6 +276,8 @@ def test_repos_find_remote_user(
|
|||||||
cfg += f"worktree = {str(worktree).lower()}\n"
|
cfg += f"worktree = {str(worktree).lower()}\n"
|
||||||
if force_ssh:
|
if force_ssh:
|
||||||
cfg += f"force_ssh = true\n"
|
cfg += f"force_ssh = true\n"
|
||||||
|
if override_remote_name:
|
||||||
|
cfg += f'remote_name = "otherremote"\n'
|
||||||
if use_owner:
|
if use_owner:
|
||||||
cfg += """
|
cfg += """
|
||||||
[filters]
|
[filters]
|
||||||
@@ -310,6 +314,8 @@ def test_repos_find_remote_user(
|
|||||||
args += ["--user", "myuser1"]
|
args += ["--user", "myuser1"]
|
||||||
if force_ssh:
|
if force_ssh:
|
||||||
args += ["--force-ssh"]
|
args += ["--force-ssh"]
|
||||||
|
if override_remote_name:
|
||||||
|
args += ["--remote-name", "otherremote"]
|
||||||
if not worktree_default:
|
if not worktree_default:
|
||||||
args += ["--worktree", str(worktree).lower()]
|
args += ["--worktree", str(worktree).lower()]
|
||||||
if use_alternate_endpoint:
|
if use_alternate_endpoint:
|
||||||
@@ -350,6 +356,9 @@ def test_repos_find_remote_user(
|
|||||||
assert repo["worktree_setup"] is (not worktree_default and worktree)
|
assert repo["worktree_setup"] is (not worktree_default and worktree)
|
||||||
assert isinstance(repo["remotes"], list)
|
assert isinstance(repo["remotes"], list)
|
||||||
assert len(repo["remotes"]) == 1
|
assert len(repo["remotes"]) == 1
|
||||||
|
if override_remote_name:
|
||||||
|
assert repo["remotes"][0]["name"] == "otherremote"
|
||||||
|
else:
|
||||||
assert repo["remotes"][0]["name"] == provider
|
assert repo["remotes"][0]["name"] == provider
|
||||||
if force_ssh or i == 1:
|
if force_ssh or i == 1:
|
||||||
assert (
|
assert (
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ pub struct ConfigProvider {
|
|||||||
|
|
||||||
pub worktree: Option<bool>,
|
pub worktree: Option<bool>,
|
||||||
pub init_worktree: Option<bool>,
|
pub init_worktree: Option<bool>,
|
||||||
|
|
||||||
|
pub remote_name: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
@@ -192,6 +194,7 @@ impl Config {
|
|||||||
.get_repos(
|
.get_repos(
|
||||||
config.worktree.unwrap_or(false),
|
config.worktree.unwrap_or(false),
|
||||||
config.force_ssh.unwrap_or(false),
|
config.force_ssh.unwrap_or(false),
|
||||||
|
config.remote_name,
|
||||||
)?
|
)?
|
||||||
}
|
}
|
||||||
RemoteProvider::Gitlab => {
|
RemoteProvider::Gitlab => {
|
||||||
@@ -205,6 +208,7 @@ impl Config {
|
|||||||
.get_repos(
|
.get_repos(
|
||||||
config.worktree.unwrap_or(false),
|
config.worktree.unwrap_or(false),
|
||||||
config.force_ssh.unwrap_or(false),
|
config.force_ssh.unwrap_or(false),
|
||||||
|
config.remote_name,
|
||||||
)?
|
)?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -103,6 +103,9 @@ pub struct FindRemoteArgs {
|
|||||||
#[clap(arg_enum, short, long, help = "Remote provider to use")]
|
#[clap(arg_enum, short, long, help = "Remote provider to use")]
|
||||||
pub provider: RemoteProvider,
|
pub provider: RemoteProvider,
|
||||||
|
|
||||||
|
#[clap(short, long, help = "Name of the remote to use")]
|
||||||
|
pub remote_name: Option<String>,
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
multiple_occurrences = true,
|
multiple_occurrences = true,
|
||||||
name = "user",
|
name = "user",
|
||||||
@@ -189,6 +192,9 @@ pub struct SyncRemoteArgs {
|
|||||||
#[clap(arg_enum, short, long, help = "Remote provider to use")]
|
#[clap(arg_enum, short, long, help = "Remote provider to use")]
|
||||||
pub provider: RemoteProvider,
|
pub provider: RemoteProvider,
|
||||||
|
|
||||||
|
#[clap(short, long, help = "Name of the remote to use")]
|
||||||
|
pub remote_name: Option<String>,
|
||||||
|
|
||||||
#[clap(
|
#[clap(
|
||||||
multiple_occurrences = true,
|
multiple_occurrences = true,
|
||||||
name = "user",
|
name = "user",
|
||||||
|
|||||||
@@ -64,7 +64,11 @@ fn main() {
|
|||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.get_repos(worktree, args.force_ssh)
|
.get_repos(
|
||||||
|
worktree,
|
||||||
|
args.force_ssh,
|
||||||
|
args.remote_name,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
cmd::RemoteProvider::Gitlab => {
|
cmd::RemoteProvider::Gitlab => {
|
||||||
match provider::Gitlab::new(filter, token, args.api_url) {
|
match provider::Gitlab::new(filter, token, args.api_url) {
|
||||||
@@ -74,7 +78,11 @@ fn main() {
|
|||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.get_repos(worktree, args.force_ssh)
|
.get_repos(
|
||||||
|
worktree,
|
||||||
|
args.force_ssh,
|
||||||
|
args.remote_name,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -280,6 +288,7 @@ fn main() {
|
|||||||
.get_repos(
|
.get_repos(
|
||||||
config.worktree.unwrap_or(false),
|
config.worktree.unwrap_or(false),
|
||||||
config.force_ssh.unwrap_or(false),
|
config.force_ssh.unwrap_or(false),
|
||||||
|
config.remote_name,
|
||||||
) {
|
) {
|
||||||
Ok(provider) => provider,
|
Ok(provider) => provider,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
@@ -299,6 +308,7 @@ fn main() {
|
|||||||
.get_repos(
|
.get_repos(
|
||||||
config.worktree.unwrap_or(false),
|
config.worktree.unwrap_or(false),
|
||||||
config.force_ssh.unwrap_or(false),
|
config.force_ssh.unwrap_or(false),
|
||||||
|
config.remote_name,
|
||||||
) {
|
) {
|
||||||
Ok(provider) => provider,
|
Ok(provider) => provider,
|
||||||
Err(error) => {
|
Err(error) => {
|
||||||
@@ -382,7 +392,11 @@ fn main() {
|
|||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.get_repos(worktree, args.force_ssh)
|
.get_repos(
|
||||||
|
worktree,
|
||||||
|
args.force_ssh,
|
||||||
|
args.remote_name,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
cmd::RemoteProvider::Gitlab => {
|
cmd::RemoteProvider::Gitlab => {
|
||||||
match provider::Gitlab::new(filter, token, args.api_url) {
|
match provider::Gitlab::new(filter, token, args.api_url) {
|
||||||
@@ -392,7 +406,11 @@ fn main() {
|
|||||||
process::exit(1);
|
process::exit(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.get_repos(worktree, args.force_ssh)
|
.get_repos(
|
||||||
|
worktree,
|
||||||
|
args.force_ssh,
|
||||||
|
args.remote_name,
|
||||||
|
)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -213,6 +213,7 @@ pub trait Provider {
|
|||||||
&self,
|
&self,
|
||||||
worktree_setup: bool,
|
worktree_setup: bool,
|
||||||
force_ssh: bool,
|
force_ssh: bool,
|
||||||
|
remote_name: Option<String>,
|
||||||
) -> Result<HashMap<Option<String>, Vec<repo::Repo>>, String> {
|
) -> Result<HashMap<Option<String>, Vec<repo::Repo>>, String> {
|
||||||
let mut repos = vec![];
|
let mut repos = vec![];
|
||||||
|
|
||||||
@@ -292,10 +293,12 @@ pub trait Provider {
|
|||||||
|
|
||||||
let mut ret: HashMap<Option<String>, Vec<repo::Repo>> = HashMap::new();
|
let mut ret: HashMap<Option<String>, Vec<repo::Repo>> = HashMap::new();
|
||||||
|
|
||||||
|
let remote_name = remote_name.unwrap_or_else(|| self.name().to_string());
|
||||||
|
|
||||||
for repo in repos {
|
for repo in repos {
|
||||||
let namespace = repo.namespace();
|
let namespace = repo.namespace();
|
||||||
|
|
||||||
let mut repo = repo.into_repo_config(self.name(), worktree_setup, force_ssh);
|
let mut repo = repo.into_repo_config(&remote_name, worktree_setup, force_ssh);
|
||||||
|
|
||||||
// Namespace is already part of the hashmap key. I'm not too happy
|
// Namespace is already part of the hashmap key. I'm not too happy
|
||||||
// about the data exchange format here.
|
// about the data exchange format here.
|
||||||
|
|||||||
Reference in New Issue
Block a user