Skip to content

Commit

Permalink
docs: Add branch tracking to branches.md.
Browse files Browse the repository at this point in the history
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
PhilipMetzger committed Dec 6, 2023
2 parents 30ab252 + c31b0f7 commit 9134bff
Show file tree
Hide file tree
Showing 13 changed files with 197 additions and 60 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install poetry
Expand All @@ -84,7 +84,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install poetry
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- run: "git fetch origin gh-pages --depth=1"
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install poetry
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/nix-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ jobs:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
with:
fetch-depth: 0
- uses: DeterminateSystems/nix-installer-action@07b8bcba1b22d847db7ee507180c33e115499665
- uses: DeterminateSystems/magic-nix-cache-action@a04e6275a6bea232cd04fc6f3cbf20d4cb02a3e1
- uses: DeterminateSystems/nix-installer-action@cd46bde16ab981b0a7b2dce0574509104543276e
- uses: DeterminateSystems/magic-nix-cache-action@1402a2dd8f56a6a6306c015089c5086f5e1ca3ef
- run: nix build --print-build-logs --show-trace
2 changes: 1 addition & 1 deletion .github/workflows/nix-update-flake.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Nix
uses: DeterminateSystems/nix-installer-action@07b8bcba1b22d847db7ee507180c33e115499665
uses: DeterminateSystems/nix-installer-action@cd46bde16ab981b0a7b2dce0574509104543276e
- name: Update flake.lock
uses: DeterminateSystems/update-flake-lock@da2fd6f2563fe3e4f2af8be73b864088564e263d
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ jobs:
sudo apt-get update
sudo apt-get install -y --no-install-recommends xz-utils liblz4-tool musl-tools
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install poetry
Expand Down Expand Up @@ -114,7 +114,7 @@ jobs:
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
- run: "git fetch origin gh-pages --depth=1"
- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: 3.11
- name: Install poetry
Expand Down
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Breaking changes

### New features

### Fixed bugs


## [0.12.0] - 2023-12-05

### Breaking changes

* The `remote_branches()` revset no longer includes branches exported to the Git
repository (so called Git-tracking branches.)

Expand Down Expand Up @@ -45,6 +54,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
with the actual file content.
[#2654](https://github.com/martinvonz/jj/issues/2654)

### Contributors

Thanks to the people who made this release happen!

* Antoine Cezar (@AntoineCezar)
* Anton Bulakh (@necauqua)
* Austin Seipp (@thoughtpolice)
* Benjamin Saunders (@Ralith)
* Carlos Precioso (@cprecioso)
* Chris Krycho (@chriskrycho)
* Ilya Grigoriev (@ilyagr)
* Jason R. Coombs (@jaraco)
* Jesse Somerville (@jessesomerville)
* Łukasz Kurowski (@crackcomm)
* Martin von Zweigbergk (@martinvonz)
* mlcui (@mlcui-google)
* Philip Metzger (@PhilipMetzger)
* Waleed Khan (@arxanas)
* Yuya Nishihara (@yuja)


## [0.11.0] - 2023-11-01

Expand Down
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resolver = "2"
members = ["cli", "lib", "lib/testutils", "lib/gen-protos"]

[workspace.package]
version = "0.11.0"
version = "0.12.0"
license = "Apache-2.0"
rust-version = "1.71" # NOTE: remember to update CI, contributing.md, changelog.md, and flake.nix
edition = "2021"
Expand All @@ -26,7 +26,7 @@ blake2 = "0.10.6"
byteorder = "1.5.0"
bytes = "1.5.0"
cargo_metadata = "0.17.0"
clap = { version = "4.4.10", features = ["derive", "deprecated", "wrap_help"] }
clap = { version = "4.4.11", features = ["derive", "deprecated", "wrap_help"] }
clap_complete = "4.4.4"
clap_mangen = "0.2.10"
chrono = { version = "0.4.31", default-features = false, features = [
Expand Down Expand Up @@ -103,7 +103,7 @@ zstd = "0.12.4"
# put all inter-workspace libraries, i.e. those that use 'path = ...' here in
# their own (alphabetically sorted) block

jj-lib = { path = "lib", version = "0.11.0" }
jj-lib = { path = "lib", version = "0.12.0" }
testutils = { path = "lib/testutils" }

[profile.release]
Expand Down
15 changes: 7 additions & 8 deletions cli/src/cli_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1671,19 +1671,18 @@ fn is_colocated_git_workspace(workspace: &Workspace, repo: &ReadonlyRepo) -> boo
let Some(git_backend) = repo.store().backend_impl().downcast_ref::<GitBackend>() else {
return false;
};
let Some(git_workdir) = git_backend
.git_workdir()
.and_then(|path| path.canonicalize().ok())
else {
let Some(git_workdir) = git_backend.git_workdir() else {
return false; // Bare repository
};
// Colocated workspace should have ".git" directory, file, or symlink. Since the
// backend is loaded from the canonical path, its working directory should also
// be resolved from the canonical ".git" path.
if git_workdir == workspace.workspace_root() {
return true;
}
// Colocated workspace should have ".git" directory, file, or symlink. Compare
// its parent as the git_workdir might be resolved from the real ".git" path.
let Ok(dot_git_path) = workspace.workspace_root().join(".git").canonicalize() else {
return false;
};
Some(git_workdir.as_ref()) == dot_git_path.parent()
git_workdir.canonicalize().ok().as_deref() == dot_git_path.parent()
}

pub fn start_repo_transaction(
Expand Down
71 changes: 60 additions & 11 deletions cli/tests/test_init_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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();
Expand All @@ -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")]
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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"));

Expand Down Expand Up @@ -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", "@-"]);
Expand Down Expand Up @@ -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", "@-"]);
Expand Down Expand Up @@ -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", "@-"]);
Expand Down
Loading

0 comments on commit 9134bff

Please sign in to comment.