mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-08 05:39:20 +00:00
git: add command for refreshing heads based on git refs
The user can now run `jj git refresh` e.g. after running `git fetch` in the underlying Git repo.
This commit is contained in:
parent
ff3b20c537
commit
3a67952215
1 changed files with 27 additions and 1 deletions
|
@ -59,7 +59,7 @@ use crate::styler::{ColorStyler, Styler};
|
|||
use crate::template_parser::TemplateParser;
|
||||
use crate::templater::Template;
|
||||
use crate::ui::Ui;
|
||||
use jj_lib::git::GitPushError;
|
||||
use jj_lib::git::{GitImportError, GitPushError};
|
||||
use jj_lib::index::{HexPrefix, PrefixResolution};
|
||||
use jj_lib::operation::Operation;
|
||||
use jj_lib::transaction::Transaction;
|
||||
|
@ -444,6 +444,10 @@ fn get_app<'a, 'b>() -> App<'a, 'b> {
|
|||
.index(2)
|
||||
.required(true),
|
||||
),
|
||||
)
|
||||
.subcommand(
|
||||
SubCommand::with_name("refresh")
|
||||
.about("update repo with changes made in underlying git repo"),
|
||||
);
|
||||
let bench_command = SubCommand::with_name("bench")
|
||||
.about("commands for benchmarking internal operations")
|
||||
|
@ -1983,6 +1987,26 @@ fn cmd_git_push(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn cmd_git_refresh(
|
||||
ui: &mut Ui,
|
||||
matches: &ArgMatches,
|
||||
_git_matches: &ArgMatches,
|
||||
_cmd_matches: &ArgMatches,
|
||||
) -> Result<(), CommandError> {
|
||||
let repo = get_repo(ui, &matches)?;
|
||||
let mut tx = repo.start_transaction("import git refs");
|
||||
git::import_refs(&mut tx).map_err(|err| match err {
|
||||
GitImportError::NotAGitRepo => CommandError::UserError(
|
||||
"git refresh can only be used in repos backed by a git repo".to_string(),
|
||||
),
|
||||
GitImportError::InternalGitError(err) => {
|
||||
CommandError::UserError(format!("import of Git refs failed: {:?}", err))
|
||||
}
|
||||
})?;
|
||||
tx.commit();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn cmd_git(
|
||||
ui: &mut Ui,
|
||||
matches: &ArgMatches,
|
||||
|
@ -1990,6 +2014,8 @@ fn cmd_git(
|
|||
) -> Result<(), CommandError> {
|
||||
if let Some(command_matches) = sub_matches.subcommand_matches("push") {
|
||||
cmd_git_push(ui, matches, sub_matches, command_matches)?;
|
||||
} else if let Some(command_matches) = sub_matches.subcommand_matches("refresh") {
|
||||
cmd_git_refresh(ui, matches, sub_matches, command_matches)?;
|
||||
} else {
|
||||
panic!("unhandled command: {:#?}", matches);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue