ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: on init, import git refs prior to importing HEAD

The "::HEAD" set is usually smaller than "::git_refs". If these sets were
imported in that order, "HEAD..git_refs" commits would be indexed on top of
the "::HEAD" commits. It's not a problem, but undesirable.
This commit is contained in:
Yuya Nishihara 2024-01-25 20:26:36 +09:00
parent 23a1ddb6ad
commit 9faa4670d5
3 changed files with 6 additions and 9 deletions

View file

@ -878,7 +878,7 @@ impl WorkspaceCommandHelper {
///
/// This function does not import the Git HEAD.
#[instrument(skip_all)]
fn import_git_refs(&mut self, ui: &mut Ui) -> Result<(), CommandError> {
pub fn import_git_refs(&mut self, ui: &mut Ui) -> Result<(), CommandError> {
let git_settings = self.settings.git_settings();
let mut tx = self.start_transaction();
// Automated import shouldn't fail because of reserved remote name.

View file

@ -25,7 +25,6 @@ use tracing::instrument;
use super::git;
use crate::cli_util::{user_error, user_error_with_hint, CommandError, CommandHelper};
use crate::git_util::print_git_import_stats;
use crate::ui::Ui;
/// Create a new repo in the given directory
@ -70,22 +69,19 @@ pub(crate) fn cmd_init(
Workspace::init_external_git(command.settings(), &wc_path, &git_store_path)?;
let mut workspace_command = command.for_loaded_repo(ui, workspace, repo)?;
git::maybe_add_gitignore(&workspace_command)?;
// Import refs first so all the reachable commits are indexed in
// chronological order.
workspace_command.import_git_refs(ui)?;
workspace_command.maybe_snapshot(ui)?;
if !workspace_command.working_copy_shared_with_git() {
let mut tx = workspace_command.start_transaction();
jj_lib::git::import_head(tx.mut_repo())?;
let stats = jj_lib::git::import_some_refs(
tx.mut_repo(),
&command.settings().git_settings(),
|ref_name| !jj_lib::git::is_reserved_git_remote_ref(ref_name),
)?;
print_git_import_stats(ui, &stats)?;
if let Some(git_head_id) = tx.mut_repo().view().git_head().as_normal().cloned() {
let git_head_commit = tx.mut_repo().store().get_commit(&git_head_id)?;
tx.check_out(&git_head_commit)?;
}
if tx.mut_repo().has_changes() {
tx.finish(ui, "import git refs")?;
tx.finish(ui, "import git head")?;
}
}
print_trackable_remote_branches(ui, workspace_command.repo().view())?;

View file

@ -109,6 +109,7 @@ fn test_init_git_external(bare: bool) {
insta::allow_duplicates! {
insta::assert_snapshot!(stdout, @"");
insta::assert_snapshot!(stderr, @r###"
Done importing changes from the underlying Git repo.
Working copy now at: sqpuoqvx f6950fc1 (empty) (no description set)
Parent commit : mwrttmos 8d698d4a my-branch | My commit message
Added 1 files, modified 0 files, removed 0 files