Debian Codegraph @

cli/src/commands/git/export.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 jj_lib::git;
16
17 use crate::cli_util::CommandHelper;
18 use crate::command_error::CommandError;
19 use crate::command_error::cli_error;
20 use crate::git_util::print_git_export_stats;
21 use crate::ui::Ui;
22
23 /// Update the underlying Git repo with changes made in the repo
24 ///
25 /// By default, this command does nothing in colocated workspaces because the
26 /// export happens automatically. Use `--ignore-working-copy` to forcibly export
27 /// changes.
28 #[derive(clap::Args, Clone, Debug)]
29 pub struct GitExportArgs {}
30
31 pub async fn cmd_git_export(
32 ui: &mut Ui,
33 command: &CommandHelper,
34 _args: &GitExportArgs,
35 ) -> Result<(), CommandError> {
36 if command.global_args().no_integrate_operation {
37 // Exported refs shouldn't be left unintegrated.
38 return Err(cli_error("--no-integrate-operation is not respected"));
39 }
40 let mut workspace_command = command.workspace_helper(ui).await?;
41 if command.is_working_copy_writable() && workspace_command.working_copy_shared_with_git() {
42 // Git refs are imported during the snapshot, so there are no ref
43 // changes to export.
44 writeln!(ui.status(), "No export needed in colocated workspaces.")?;
45 return Ok(());
46 }
47
48 let mut tx = workspace_command.start_transaction();
49 let stats = git::export_refs(tx.repo_mut())?;
50 tx.finish(ui, "export git refs").await?;
51 print_git_export_stats(ui, &stats)?;
52 Ok(())
53 }