mirror of
https://github.com/martinvonz/jj.git
synced 2024-12-23 20:43:56 +00:00
3418c8ff73
Add a new git.auto-local-branch config option. When set to false, a remote-tracking branch imported from Git will not automatically create a local branch target. This is implemented by a new GitSettings struct that passes Git-related settings from UserSettings. This behavior is particularly useful in a co-located jj and Git repo, because a Git remote might have branches that are not of everyday interest to the user, so it does not make sense to export them as local branches in Git. E.g. https://github.com/gitster/git, the maintainer's fork of Git, has 379 branches, most of which are topic branches kept around for historical reasons, and Git developers wouldn't be expected to have local branches for each remote-tracking branch.
103 lines
3.6 KiB
Rust
103 lines
3.6 KiB
Rust
// Copyright 2022 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 std::path::Path;
|
|
|
|
use crate::common::{get_stderr_string, TestEnvironment};
|
|
|
|
pub mod common;
|
|
|
|
#[test]
|
|
fn test_git_export_conflicting_git_refs() {
|
|
let test_env = TestEnvironment::default();
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main"]);
|
|
test_env.jj_cmd_success(&repo_path, &["branch", "create", "main/sub"]);
|
|
let assert = test_env
|
|
.jj_cmd(&repo_path, &["git", "export"])
|
|
.assert()
|
|
.success()
|
|
.stdout("");
|
|
insta::assert_snapshot!(get_stderr_string(&assert), @r###"
|
|
Failed to export some branches:
|
|
main/sub
|
|
Hint: Git doesn't allow a branch name that looks like a parent directory of
|
|
another (e.g. `foo` and `foo/bar`). Try to rename the branches that failed to
|
|
export or their "parent" branches.
|
|
"###);
|
|
}
|
|
|
|
#[test]
|
|
fn test_git_import_remote_only_branch() {
|
|
let test_env = TestEnvironment::default();
|
|
test_env.jj_cmd_success(test_env.env_root(), &["init", "repo", "--git"]);
|
|
let repo_path = test_env.env_root().join("repo");
|
|
|
|
// Create non-empty git repo to add as a remote
|
|
let git_repo_path = test_env.env_root().join("git-repo");
|
|
let git_repo = git2::Repository::init(git_repo_path).unwrap();
|
|
let signature =
|
|
git2::Signature::new("Some One", "some.one@example.com", &git2::Time::new(0, 0)).unwrap();
|
|
let mut tree_builder = git_repo.treebuilder(None).unwrap();
|
|
let file_oid = git_repo.blob(b"content").unwrap();
|
|
tree_builder
|
|
.insert("file", file_oid, git2::FileMode::Blob.into())
|
|
.unwrap();
|
|
let tree_oid = tree_builder.write().unwrap();
|
|
let tree = git_repo.find_tree(tree_oid).unwrap();
|
|
test_env.jj_cmd_success(
|
|
&repo_path,
|
|
&["git", "remote", "add", "origin", "../git-repo"],
|
|
);
|
|
|
|
// Import using default config
|
|
git_repo
|
|
.commit(
|
|
Some("refs/heads/feature1"),
|
|
&signature,
|
|
&signature,
|
|
"message",
|
|
&tree,
|
|
&[],
|
|
)
|
|
.unwrap();
|
|
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
|
|
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
|
|
feature1: 9f01a0e04879 message
|
|
"###);
|
|
|
|
// Import using git.auto_local_branch = false
|
|
git_repo
|
|
.commit(
|
|
Some("refs/heads/feature2"),
|
|
&signature,
|
|
&signature,
|
|
"message",
|
|
&tree,
|
|
&[],
|
|
)
|
|
.unwrap();
|
|
test_env.add_config("git.auto-local-branch = false");
|
|
test_env.jj_cmd_success(&repo_path, &["git", "fetch", "--remote=origin"]);
|
|
insta::assert_snapshot!(get_branch_output(&test_env, &repo_path), @r###"
|
|
feature1: 9f01a0e04879 message
|
|
feature2 (deleted)
|
|
@origin: 9f01a0e04879 message
|
|
"###);
|
|
}
|
|
|
|
fn get_branch_output(test_env: &TestEnvironment, repo_path: &Path) -> String {
|
|
test_env.jj_cmd_success(repo_path, &["branch", "list"])
|
|
}
|