Debian Codegraph @

cli/src/commands/git/remote/remove.rs

raw
1 // Copyright 2020-2023 The Jujutsu Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 use clap_complete::ArgValueCandidates;
16 use jj_lib::git;
17 use jj_lib::ref_name::RemoteNameBuf;
18
19 use super::super::remove_remote_from_repo_config;
20 use crate::cli_util::CommandHelper;
21 use crate::command_error::CommandError;
22 use crate::complete;
23 use crate::ui::Ui;
24
25 /// Remove a Git remote and forget its bookmarks
26 #[derive(clap::Args, Clone, Debug)]
27 pub struct GitRemoteRemoveArgs {
28 /// The remote's name
29 #[arg(add = ArgValueCandidates::new(complete::git_remotes))]
30 remote: RemoteNameBuf,
31 }
32
33 pub async fn cmd_git_remote_remove(
34 ui: &mut Ui,
35 command: &CommandHelper,
36 args: &GitRemoteRemoveArgs,
37 ) -> Result<(), CommandError> {
38 let mut workspace_command = command.workspace_helper(ui).await?;
39 let mut tx = workspace_command.start_transaction();
40 git::remove_remote(tx.repo_mut(), &args.remote)?;
41 remove_remote_from_repo_config(ui, command.raw_config(), &args.remote)?;
42 if tx.repo().has_changes() {
43 tx.finish(ui, format!("remove git remote {}", args.remote.as_symbol()))
44 .await?;
45 } else {
46 // Do not print "Nothing changed." for the remote named "git".
47 }
48 Ok(())
49 }