From 371b264dbf49ceb60b84ed6e6053eadc41597333 Mon Sep 17 00:00:00 2001 From: Essien Ita Essien <34972+essiene@users.noreply.github.com> Date: Sat, 2 Nov 2024 11:04:02 +0000 Subject: [PATCH] git sync: Setup scaffolding * First commit that just sets up scaffolding. * `jj git sync` is hidden as it's not yet ready. Issue: #1039 --- cli/src/commands/git/mod.rs | 6 +++ cli/src/commands/git/sync.rs | 79 ++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 cli/src/commands/git/sync.rs diff --git a/cli/src/commands/git/mod.rs b/cli/src/commands/git/mod.rs index 3aa6105ec14..f43a3e11bff 100644 --- a/cli/src/commands/git/mod.rs +++ b/cli/src/commands/git/mod.rs @@ -20,6 +20,7 @@ pub mod init; pub mod push; pub mod remote; pub mod submodule; +pub mod sync; use clap::Subcommand; @@ -39,6 +40,8 @@ use self::remote::cmd_git_remote; use self::remote::RemoteCommand; use self::submodule::cmd_git_submodule; use self::submodule::GitSubmoduleCommand; +use self::sync::cmd_git_sync; +use self::sync::GitSyncArgs; use crate::cli_util::CommandHelper; use crate::cli_util::WorkspaceCommandHelper; use crate::command_error::user_error_with_message; @@ -61,6 +64,8 @@ pub enum GitCommand { Remote(RemoteCommand), #[command(subcommand, hide = true)] Submodule(GitSubmoduleCommand), + #[command(hide = true)] + Sync(GitSyncArgs), } pub fn cmd_git( @@ -77,6 +82,7 @@ pub fn cmd_git( GitCommand::Push(args) => cmd_git_push(ui, command, args), GitCommand::Remote(args) => cmd_git_remote(ui, command, args), GitCommand::Submodule(args) => cmd_git_submodule(ui, command, args), + GitCommand::Sync(args) => cmd_git_sync(ui, command, args), } } diff --git a/cli/src/commands/git/sync.rs b/cli/src/commands/git/sync.rs new file mode 100644 index 00000000000..5e9eb8bf174 --- /dev/null +++ b/cli/src/commands/git/sync.rs @@ -0,0 +1,79 @@ +// Copyright 2020-2023 The Jujutsu Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use clap_complete::ArgValueCandidates; +use jj_lib::str_util::StringPattern; + +use crate::cli_util::CommandHelper; +use crate::command_error::CommandError; +use crate::complete; +use crate::ui::Ui; + +/// Sync the local `jj` repo to Git remote branch(es). +/// +/// The sync command will first fetch from the Git remote, then +/// rebase all local changes onto the appropriate updated +/// heads that were fetched. +/// +/// Newly emptied commits are discarded. +/// +/// Changes that are made empty by the rebase are dropped. +#[derive(clap::Args, Clone, Debug)] +pub struct GitSyncArgs { + /// Rebase only the specified branches. + /// + /// Note that this value affects only the rebase behaviour, as + /// the fetch behaviour always fetches all branches. + /// + /// By default, the specified name matches exactly. Use `glob:` prefix to + /// expand `*` as a glob. The other wildcard characters aren't supported. + #[arg(long, short, + alias="bookmark", + default_value = "glob:*", + value_parser = StringPattern::parse, + add = ArgValueCandidates::new(complete::bookmarks), + )] + pub branch: Vec, + /// Fetch from all remotes + /// + /// By default, the fetch will only use remotes configured in the + /// `git.fetch` section of the config. + /// + /// When specified, --all-remotes causes the fetch to use all remotes known + /// to the underlying git repo. + #[arg(long, default_value = "false")] + pub all_remotes: bool, +} + +pub fn cmd_git_sync( + ui: &mut Ui, + command: &CommandHelper, + _args: &GitSyncArgs, +) -> Result<(), CommandError> { + let _workspace_command = command.workspace_helper(ui)?; + + let guard = tracing::debug_span!("git.sync.pre-fetch").entered(); + drop(guard); + + let guard = tracing::debug_span!("git.sync.fetch").entered(); + drop(guard); + + let guard = tracing::debug_span!("git.sync.post-fetch").entered(); + drop(guard); + + let guard = tracing::debug_span!("git.sync.rebase").entered(); + drop(guard); + + Ok(()) +}