-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: Add branch tracking to branches.md.
This tries to explain Jujutsu's branch tracking for a newcomer. It is based on it's design doc in `docs/design/tracking-branches.md`.
- Loading branch information
Showing
13 changed files
with
197 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,18 +20,22 @@ use crate::common::TestEnvironment; | |
|
||
pub mod common; | ||
|
||
fn init_git_repo(git_repo_path: &Path, bare: bool) { | ||
init_git_repo_with_opts(git_repo_path, git2::RepositoryInitOptions::new().bare(bare)); | ||
fn init_git_repo(git_repo_path: &Path, bare: bool) -> git2::Repository { | ||
init_git_repo_with_opts(git_repo_path, git2::RepositoryInitOptions::new().bare(bare)) | ||
} | ||
|
||
fn init_git_repo_with_opts(git_repo_path: &Path, opts: &git2::RepositoryInitOptions) { | ||
fn init_git_repo_with_opts( | ||
git_repo_path: &Path, | ||
opts: &git2::RepositoryInitOptions, | ||
) -> git2::Repository { | ||
let git_repo = git2::Repository::init_opts(git_repo_path, opts).unwrap(); | ||
let git_blob_oid = git_repo.blob(b"some content").unwrap(); | ||
let mut git_tree_builder = git_repo.treebuilder(None).unwrap(); | ||
git_tree_builder | ||
.insert("some-file", git_blob_oid, 0o100644) | ||
.unwrap(); | ||
let git_tree_id = git_tree_builder.write().unwrap(); | ||
drop(git_tree_builder); | ||
let git_tree = git_repo.find_tree(git_tree_id).unwrap(); | ||
let git_signature = git2::Signature::new( | ||
"Git User", | ||
|
@@ -49,13 +53,21 @@ fn init_git_repo_with_opts(git_repo_path: &Path, opts: &git2::RepositoryInitOpti | |
&[], | ||
) | ||
.unwrap(); | ||
drop(git_tree); | ||
git_repo.set_head("refs/heads/my-branch").unwrap(); | ||
git_repo | ||
} | ||
|
||
fn get_branch_output(test_env: &TestEnvironment, repo_path: &Path) -> String { | ||
test_env.jj_cmd_success(repo_path, &["branch", "list", "--all"]) | ||
} | ||
|
||
fn read_git_target(workspace_root: &Path) -> String { | ||
let mut path = workspace_root.to_path_buf(); | ||
path.extend([".jj", "repo", "store", "git_target"]); | ||
std::fs::read_to_string(path).unwrap() | ||
} | ||
|
||
#[test] | ||
fn test_init_git_internal() { | ||
let test_env = TestEnvironment::default(); | ||
|
@@ -75,9 +87,7 @@ fn test_init_git_internal() { | |
assert!(repo_path.is_dir()); | ||
assert!(store_path.is_dir()); | ||
assert!(store_path.join("git").is_dir()); | ||
assert!(store_path.join("git_target").is_file()); | ||
let git_target_file_contents = std::fs::read_to_string(store_path.join("git_target")).unwrap(); | ||
assert_eq!(git_target_file_contents, "git"); | ||
assert_eq!(read_git_target(&workspace_root), "git"); | ||
} | ||
|
||
#[test_case(false; "full")] | ||
|
@@ -115,9 +125,7 @@ fn test_init_git_external(bare: bool) { | |
assert!(jj_path.join("working_copy").is_dir()); | ||
assert!(repo_path.is_dir()); | ||
assert!(store_path.is_dir()); | ||
let unix_git_target_file_contents = std::fs::read_to_string(store_path.join("git_target")) | ||
.unwrap() | ||
.replace('\\', "/"); | ||
let unix_git_target_file_contents = read_git_target(&workspace_root).replace('\\', "/"); | ||
if bare { | ||
assert!(unix_git_target_file_contents.ends_with("/git-repo")); | ||
} else { | ||
|
@@ -183,8 +191,7 @@ fn test_init_git_colocated() { | |
assert!(jj_path.join("working_copy").is_dir()); | ||
assert!(repo_path.is_dir()); | ||
assert!(store_path.is_dir()); | ||
let git_target_file_contents = std::fs::read_to_string(store_path.join("git_target")).unwrap(); | ||
assert!(git_target_file_contents | ||
assert!(read_git_target(&workspace_root) | ||
.replace('\\', "/") | ||
.ends_with("../../../.git")); | ||
|
||
|
@@ -223,6 +230,7 @@ fn test_init_git_colocated_gitlink() { | |
Done importing changes from the underlying Git repo. | ||
Initialized repo in "." | ||
"###); | ||
insta::assert_snapshot!(read_git_target(&workspace_root), @"../../../.git"); | ||
|
||
// Check that the Git repo's HEAD got checked out | ||
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]); | ||
|
@@ -258,6 +266,46 @@ fn test_init_git_colocated_symlink_directory() { | |
Done importing changes from the underlying Git repo. | ||
Initialized repo in "." | ||
"###); | ||
insta::assert_snapshot!(read_git_target(&workspace_root), @"../../../.git"); | ||
|
||
// Check that the Git repo's HEAD got checked out | ||
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]); | ||
insta::assert_snapshot!(stdout, @r###" | ||
◉ mwrttmos [email protected] 1970-01-01 01:02:03.000 +01:00 my-branch HEAD@git 8d698d4a | ||
│ My commit message | ||
~ | ||
"###); | ||
|
||
// Check that the Git repo's HEAD moves | ||
test_env.jj_cmd_ok(&workspace_root, &["new"]); | ||
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]); | ||
insta::assert_snapshot!(stdout, @r###" | ||
◉ sqpuoqvx [email protected] 2001-02-03 04:05:07.000 +07:00 HEAD@git f61b77cd | ||
│ (no description set) | ||
~ | ||
"###); | ||
} | ||
|
||
#[cfg(unix)] | ||
#[test] | ||
fn test_init_git_colocated_symlink_directory_without_bare_config() { | ||
let test_env = TestEnvironment::default(); | ||
// <workspace_root>/.git -> <git_repo_path> | ||
let git_repo_path = test_env.env_root().join("git-repo.git"); | ||
let workspace_root = test_env.env_root().join("repo"); | ||
// Set up git repo without core.bare set (as the "repo" tool would do.) | ||
// The core.bare config is deduced from the directory name. | ||
let git_repo = init_git_repo(&workspace_root, false); | ||
git_repo.config().unwrap().remove("core.bare").unwrap(); | ||
std::fs::rename(workspace_root.join(".git"), &git_repo_path).unwrap(); | ||
std::os::unix::fs::symlink(&git_repo_path, workspace_root.join(".git")).unwrap(); | ||
let (stdout, stderr) = test_env.jj_cmd_ok(&workspace_root, &["init", "--git-repo", "."]); | ||
insta::assert_snapshot!(stdout, @""); | ||
insta::assert_snapshot!(stderr, @r###" | ||
Done importing changes from the underlying Git repo. | ||
Initialized repo in "." | ||
"###); | ||
insta::assert_snapshot!(read_git_target(&workspace_root), @"../../../.git"); | ||
|
||
// Check that the Git repo's HEAD got checked out | ||
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]); | ||
|
@@ -298,6 +346,7 @@ fn test_init_git_colocated_symlink_gitlink() { | |
Done importing changes from the underlying Git repo. | ||
Initialized repo in "." | ||
"###); | ||
insta::assert_snapshot!(read_git_target(&workspace_root), @"../../../.git"); | ||
|
||
// Check that the Git repo's HEAD got checked out | ||
let stdout = test_env.jj_cmd_success(&workspace_root, &["log", "-r", "@-"]); | ||
|
Oops, something went wrong.