forked from mirrors/jj
cli: add jj git remote add
command
The user currently has to edit `.jj/git/config` (or run `git --git-dir=.jj/git config`) to manage remotes in the underlying Git repo. That's not very discoverable (and we may change the path some day), so let's provide a command for it.
This commit is contained in:
parent
d8c0282873
commit
e4f7795fd3
1 changed files with 58 additions and 1 deletions
|
@ -1066,6 +1066,26 @@ https://github.com/martinvonz/jj/blob/main/docs/git-comparison.md.\
|
|||
",
|
||||
)
|
||||
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
|
||||
.subcommand(
|
||||
SubCommand::with_name("remote")
|
||||
.about("Manage Git remotes")
|
||||
.subcommand(
|
||||
SubCommand::with_name("add")
|
||||
.about("Add a Git remote")
|
||||
.arg(
|
||||
Arg::with_name("remote")
|
||||
.index(1)
|
||||
.required(true)
|
||||
.help("The remote's name"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("url")
|
||||
.index(2)
|
||||
.required(true)
|
||||
.help("The remote's URL"),
|
||||
),
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("fetch")
|
||||
.about("Fetch from a Git remote")
|
||||
|
@ -3316,6 +3336,41 @@ fn get_git_repo(store: &Store) -> Result<git2::Repository, CommandError> {
|
|||
}
|
||||
}
|
||||
|
||||
fn cmd_git_remote(
|
||||
ui: &mut Ui,
|
||||
command: &CommandHelper,
|
||||
_git_matches: &ArgMatches,
|
||||
remote_matches: &ArgMatches,
|
||||
) -> Result<(), CommandError> {
|
||||
if let Some(command_matches) = remote_matches.subcommand_matches("add") {
|
||||
cmd_git_remote_add(ui, command, remote_matches, remote_matches, command_matches)?;
|
||||
} else {
|
||||
panic!("unhandled command: {:#?}", command.root_matches());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cmd_git_remote_add(
|
||||
ui: &mut Ui,
|
||||
command: &CommandHelper,
|
||||
_git_matches: &ArgMatches,
|
||||
_remote_matches: &ArgMatches,
|
||||
cmd_matches: &ArgMatches,
|
||||
) -> Result<(), CommandError> {
|
||||
let repo_command = command.repo_helper(ui)?;
|
||||
let repo = repo_command.repo();
|
||||
let git_repo = get_git_repo(repo.store())?;
|
||||
let remote_name = cmd_matches.value_of("remote").unwrap();
|
||||
let url = cmd_matches.value_of("url").unwrap();
|
||||
if git_repo.find_remote(remote_name).is_ok() {
|
||||
return Err(CommandError::UserError("Remote already exists".to_string()));
|
||||
}
|
||||
git_repo
|
||||
.remote(remote_name, url)
|
||||
.map_err(|err| CommandError::UserError(err.to_string()))?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cmd_git_fetch(
|
||||
ui: &mut Ui,
|
||||
command: &CommandHelper,
|
||||
|
@ -3526,7 +3581,9 @@ fn cmd_git(
|
|||
command: &CommandHelper,
|
||||
sub_matches: &ArgMatches,
|
||||
) -> Result<(), CommandError> {
|
||||
if let Some(command_matches) = sub_matches.subcommand_matches("fetch") {
|
||||
if let Some(command_matches) = sub_matches.subcommand_matches("remote") {
|
||||
cmd_git_remote(ui, command, sub_matches, command_matches)?;
|
||||
} else if let Some(command_matches) = sub_matches.subcommand_matches("fetch") {
|
||||
cmd_git_fetch(ui, command, sub_matches, command_matches)?;
|
||||
} else if let Some(command_matches) = sub_matches.subcommand_matches("clone") {
|
||||
cmd_git_clone(ui, command, sub_matches, command_matches)?;
|
||||
|
|
Loading…
Reference in a new issue