From bbf4ba41183e6388eb624e977a19974407a5dcca Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 4 Mar 2022 17:51:02 -0800 Subject: [PATCH] cli: on `jj init --git-repo`, point to Git repo's `.git/` When using an internal Git repo (`jj init --git`), we make `.jj/repo/store/git_target` point directly to the repo (which is bare in that case). It makes sense to do the same when using an external Git repo (`jj init --git-repo`), so the contents of `.jj/repo/store/git_target` doesn't depend on whether the user included the `.git/` on the CLI. --- src/commands.rs | 5 ++++- tests/test_init_command.rs | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index d3b062826..5a7268bde 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1733,7 +1733,10 @@ fn cmd_init(ui: &mut Ui, command: &CommandHelper, args: &ArgMatches) -> Result<( } if let Some(git_store_str) = args.value_of("git-repo") { - let git_store_path = ui.cwd().join(git_store_str); + let mut git_store_path = ui.cwd().join(git_store_str); + if !git_store_path.ends_with(".git") { + git_store_path = git_store_path.join(".git"); + } let (workspace, repo) = Workspace::init_external_git(ui.settings(), wc_path.clone(), git_store_path)?; let git_repo = repo.store().git_repo().unwrap(); diff --git a/tests/test_init_command.rs b/tests/test_init_command.rs index 2f781bff0..521fb99f0 100644 --- a/tests/test_init_command.rs +++ b/tests/test_init_command.rs @@ -75,7 +75,7 @@ fn test_init_git_external() { let git_target_file_contents = std::fs::read_to_string(store_path.join("git_target")).unwrap(); assert!(git_target_file_contents .replace('\\', "/") - .ends_with("/git-repo")); + .ends_with("/git-repo/.git")); } #[test]