Skip to content

Commit

Permalink
git sync: Setup scaffolding
Browse files Browse the repository at this point in the history
* First commit that just sets up scaffolding.
* `jj git sync` is hidden as it's not yet ready.


Issue: #1039
  • Loading branch information
essiene committed Nov 19, 2024
1 parent b826c8c commit 5cf013a
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cli/src/commands/git/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub mod init;
pub mod push;
pub mod remote;
pub mod submodule;
pub mod sync;

use clap::Subcommand;

Expand All @@ -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;
Expand All @@ -61,6 +64,8 @@ pub enum GitCommand {
Remote(RemoteCommand),
#[command(subcommand, hide = true)]
Submodule(GitSubmoduleCommand),
#[command(hide = true)]
Sync(GitSyncArgs),
}

pub fn cmd_git(
Expand All @@ -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),
}
}

Expand Down
48 changes: 48 additions & 0 deletions cli/src/commands/git/sync.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
use crate::cli_util::CommandHelper;
use crate::ui::Ui;
/// Sync the local JJ repo to specified 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.
///
/// 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)]
pub branch: Vec<StringPattern>,
/// 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 mut 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(())
}

0 comments on commit 5cf013a

Please sign in to comment.