2020-12-12 11:00:42 +03:00
|
|
|
// Copyright 2020 Google LLC
|
|
|
|
//
|
|
|
|
// 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.
|
|
|
|
|
2021-11-26 10:18:43 +03:00
|
|
|
use jujutsu_lib::op_store::{BranchTarget, RefTarget, WorkspaceId};
|
2021-05-15 19:16:31 +03:00
|
|
|
use jujutsu_lib::testutils;
|
|
|
|
use jujutsu_lib::testutils::CommitGraphBuilder;
|
2021-08-02 07:47:34 +03:00
|
|
|
use maplit::{btreemap, hashset};
|
2020-12-12 11:00:42 +03:00
|
|
|
use test_case::test_case;
|
|
|
|
|
2021-09-12 09:52:38 +03:00
|
|
|
#[test_case(false ; "local backend")]
|
|
|
|
#[test_case(true ; "git backend")]
|
2020-12-12 11:00:42 +03:00
|
|
|
fn test_heads_empty(use_git: bool) {
|
|
|
|
let settings = testutils::user_settings();
|
2022-02-06 00:29:55 +03:00
|
|
|
let test_repo = testutils::init_repo(&settings, use_git);
|
|
|
|
let repo = &test_repo.repo;
|
2020-12-12 11:00:42 +03:00
|
|
|
|
2021-11-17 23:29:08 +03:00
|
|
|
assert_eq!(
|
|
|
|
*repo.view().heads(),
|
2022-02-06 00:29:55 +03:00
|
|
|
hashset! {repo.store().root_commit_id().clone()}
|
2021-11-17 23:29:08 +03:00
|
|
|
);
|
2021-04-19 08:52:31 +03:00
|
|
|
assert_eq!(
|
|
|
|
*repo.view().public_heads(),
|
|
|
|
hashset! {repo.store().root_commit_id().clone()}
|
|
|
|
);
|
2020-12-12 11:00:42 +03:00
|
|
|
}
|
|
|
|
|
2021-09-12 09:52:38 +03:00
|
|
|
#[test_case(false ; "local backend")]
|
|
|
|
#[test_case(true ; "git backend")]
|
2020-12-12 11:00:42 +03:00
|
|
|
fn test_heads_fork(use_git: bool) {
|
|
|
|
let settings = testutils::user_settings();
|
2022-02-06 00:29:55 +03:00
|
|
|
let test_repo = testutils::init_repo(&settings, use_git);
|
|
|
|
let repo = &test_repo.repo;
|
2020-12-12 11:00:42 +03:00
|
|
|
let mut tx = repo.start_transaction("test");
|
|
|
|
|
2021-05-01 07:41:27 +03:00
|
|
|
let mut graph_builder = CommitGraphBuilder::new(&settings, tx.mut_repo());
|
|
|
|
let initial = graph_builder.initial_commit();
|
|
|
|
let child1 = graph_builder.commit_with_parents(&[&initial]);
|
|
|
|
let child2 = graph_builder.commit_with_parents(&[&initial]);
|
2021-07-31 00:35:08 +03:00
|
|
|
let repo = tx.commit();
|
2020-12-12 11:00:42 +03:00
|
|
|
|
2021-01-16 23:15:06 +03:00
|
|
|
assert_eq!(
|
2021-07-31 00:35:08 +03:00
|
|
|
*repo.view().heads(),
|
2021-01-16 23:15:06 +03:00
|
|
|
hashset! {
|
|
|
|
child1.id().clone(),
|
|
|
|
child2.id().clone(),
|
|
|
|
}
|
|
|
|
);
|
2020-12-12 11:00:42 +03:00
|
|
|
}
|
|
|
|
|
2021-09-12 09:52:38 +03:00
|
|
|
#[test_case(false ; "local backend")]
|
|
|
|
#[test_case(true ; "git backend")]
|
2020-12-12 11:00:42 +03:00
|
|
|
fn test_heads_merge(use_git: bool) {
|
|
|
|
let settings = testutils::user_settings();
|
2022-02-06 00:29:55 +03:00
|
|
|
let test_repo = testutils::init_repo(&settings, use_git);
|
|
|
|
let repo = &test_repo.repo;
|
2020-12-12 11:00:42 +03:00
|
|
|
let mut tx = repo.start_transaction("test");
|
|
|
|
|
2021-05-01 07:41:27 +03:00
|
|
|
let mut graph_builder = CommitGraphBuilder::new(&settings, tx.mut_repo());
|
|
|
|
let initial = graph_builder.initial_commit();
|
|
|
|
let child1 = graph_builder.commit_with_parents(&[&initial]);
|
|
|
|
let child2 = graph_builder.commit_with_parents(&[&initial]);
|
|
|
|
let merge = graph_builder.commit_with_parents(&[&child1, &child2]);
|
2021-07-31 00:35:08 +03:00
|
|
|
let repo = tx.commit();
|
2020-12-12 11:00:42 +03:00
|
|
|
|
2022-02-06 00:29:55 +03:00
|
|
|
assert_eq!(*repo.view().heads(), hashset! {merge.id().clone()});
|
2020-12-12 11:00:42 +03:00
|
|
|
}
|
2021-08-02 07:47:34 +03:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_merge_views_heads() {
|
|
|
|
// Tests merging of the view's heads (by performing concurrent operations).
|
|
|
|
let settings = testutils::user_settings();
|
2022-02-06 00:29:55 +03:00
|
|
|
let test_repo = testutils::init_repo(&settings, false);
|
|
|
|
let repo = &test_repo.repo;
|
2021-08-02 07:47:34 +03:00
|
|
|
|
|
|
|
let mut tx = repo.start_transaction("test");
|
|
|
|
let mut_repo = tx.mut_repo();
|
2021-11-21 10:46:54 +03:00
|
|
|
let head_unchanged = testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
|
|
|
let head_remove_tx1 = testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
|
|
|
let head_remove_tx2 = testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
2021-08-02 07:47:34 +03:00
|
|
|
let public_head_unchanged =
|
2021-11-21 10:46:54 +03:00
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
2021-08-02 07:47:34 +03:00
|
|
|
mut_repo.add_public_head(&public_head_unchanged);
|
|
|
|
let public_head_remove_tx1 =
|
2021-11-21 10:46:54 +03:00
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
2021-08-02 07:47:34 +03:00
|
|
|
mut_repo.add_public_head(&public_head_remove_tx1);
|
|
|
|
let public_head_remove_tx2 =
|
2021-11-21 10:46:54 +03:00
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
2021-08-02 07:47:34 +03:00
|
|
|
mut_repo.add_public_head(&public_head_remove_tx2);
|
|
|
|
let repo = tx.commit();
|
|
|
|
|
|
|
|
let mut tx1 = repo.start_transaction("test");
|
2021-09-25 19:25:42 +03:00
|
|
|
tx1.mut_repo().remove_head(head_remove_tx1.id());
|
|
|
|
tx1.mut_repo()
|
|
|
|
.remove_public_head(public_head_remove_tx1.id());
|
2021-08-02 07:47:34 +03:00
|
|
|
let head_add_tx1 =
|
|
|
|
testutils::create_random_commit(&settings, &repo).write_to_repo(tx1.mut_repo());
|
|
|
|
let public_head_add_tx1 =
|
|
|
|
testutils::create_random_commit(&settings, &repo).write_to_repo(tx1.mut_repo());
|
|
|
|
tx1.mut_repo().add_public_head(&public_head_add_tx1);
|
|
|
|
tx1.commit();
|
|
|
|
|
|
|
|
let mut tx2 = repo.start_transaction("test");
|
2021-09-25 19:25:42 +03:00
|
|
|
tx2.mut_repo().remove_head(head_remove_tx2.id());
|
|
|
|
tx2.mut_repo()
|
|
|
|
.remove_public_head(public_head_remove_tx2.id());
|
2021-08-02 07:47:34 +03:00
|
|
|
let head_add_tx2 =
|
|
|
|
testutils::create_random_commit(&settings, &repo).write_to_repo(tx2.mut_repo());
|
|
|
|
let public_head_add_tx2 =
|
|
|
|
testutils::create_random_commit(&settings, &repo).write_to_repo(tx2.mut_repo());
|
|
|
|
tx2.mut_repo().add_public_head(&public_head_add_tx2);
|
|
|
|
tx2.commit();
|
|
|
|
|
|
|
|
let repo = repo.reload();
|
|
|
|
|
|
|
|
let expected_heads = hashset! {
|
|
|
|
head_unchanged.id().clone(),
|
|
|
|
head_add_tx1.id().clone(),
|
|
|
|
head_add_tx2.id().clone(),
|
|
|
|
public_head_unchanged.id().clone(),
|
|
|
|
public_head_remove_tx1.id().clone(),
|
|
|
|
public_head_remove_tx2.id().clone(),
|
|
|
|
public_head_add_tx1.id().clone(),
|
|
|
|
public_head_add_tx2.id().clone(),
|
|
|
|
};
|
|
|
|
assert_eq!(repo.view().heads(), &expected_heads);
|
|
|
|
|
|
|
|
let expected_public_heads = hashset! {
|
|
|
|
public_head_unchanged.id().clone(),
|
|
|
|
public_head_add_tx1.id().clone(),
|
|
|
|
public_head_add_tx2.id().clone(),
|
|
|
|
};
|
|
|
|
assert_eq!(repo.view().public_heads(), &expected_public_heads);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_merge_views_checkout() {
|
|
|
|
// Tests merging of the view's checkout (by performing concurrent operations).
|
|
|
|
let settings = testutils::user_settings();
|
2022-02-06 00:29:55 +03:00
|
|
|
let test_repo = testutils::init_repo(&settings, false);
|
|
|
|
let repo = &test_repo.repo;
|
2021-08-02 07:47:34 +03:00
|
|
|
|
2021-11-26 10:12:00 +03:00
|
|
|
// Workspace 1 gets updated in both transactions.
|
|
|
|
// Workspace 2 gets updated only in tx1.
|
|
|
|
// Workspace 3 gets updated only in tx2.
|
|
|
|
// Workspace 4 gets deleted in tx1 and modified in tx2.
|
|
|
|
// Workspace 5 gets deleted in tx2 and modified in tx1.
|
|
|
|
// Workspace 6 gets added in tx1.
|
|
|
|
// Workspace 7 gets added in tx2.
|
|
|
|
let mut initial_tx = repo.start_transaction("test");
|
|
|
|
let commit1 =
|
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(initial_tx.mut_repo());
|
|
|
|
let commit2 =
|
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(initial_tx.mut_repo());
|
|
|
|
let commit3 =
|
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(initial_tx.mut_repo());
|
|
|
|
let ws1_id = WorkspaceId::new("ws1".to_string());
|
|
|
|
let ws2_id = WorkspaceId::new("ws2".to_string());
|
|
|
|
let ws3_id = WorkspaceId::new("ws3".to_string());
|
|
|
|
let ws4_id = WorkspaceId::new("ws4".to_string());
|
|
|
|
let ws5_id = WorkspaceId::new("ws5".to_string());
|
|
|
|
let ws6_id = WorkspaceId::new("ws6".to_string());
|
|
|
|
let ws7_id = WorkspaceId::new("ws7".to_string());
|
|
|
|
initial_tx
|
|
|
|
.mut_repo()
|
|
|
|
.set_checkout(ws1_id.clone(), commit1.id().clone());
|
|
|
|
initial_tx
|
|
|
|
.mut_repo()
|
|
|
|
.set_checkout(ws2_id.clone(), commit1.id().clone());
|
|
|
|
initial_tx
|
|
|
|
.mut_repo()
|
|
|
|
.set_checkout(ws3_id.clone(), commit1.id().clone());
|
|
|
|
initial_tx
|
|
|
|
.mut_repo()
|
|
|
|
.set_checkout(ws4_id.clone(), commit1.id().clone());
|
|
|
|
initial_tx
|
|
|
|
.mut_repo()
|
|
|
|
.set_checkout(ws5_id.clone(), commit1.id().clone());
|
|
|
|
let repo = initial_tx.commit();
|
|
|
|
|
2021-08-02 07:47:34 +03:00
|
|
|
let mut tx1 = repo.start_transaction("test");
|
2021-11-26 10:18:43 +03:00
|
|
|
tx1.mut_repo()
|
2021-11-26 10:12:00 +03:00
|
|
|
.set_checkout(ws1_id.clone(), commit2.id().clone());
|
|
|
|
tx1.mut_repo()
|
|
|
|
.set_checkout(ws2_id.clone(), commit2.id().clone());
|
|
|
|
tx1.mut_repo().remove_checkout(&ws4_id);
|
|
|
|
tx1.mut_repo()
|
|
|
|
.set_checkout(ws5_id.clone(), commit2.id().clone());
|
|
|
|
tx1.mut_repo()
|
|
|
|
.set_checkout(ws6_id.clone(), commit2.id().clone());
|
2021-08-02 07:47:34 +03:00
|
|
|
tx1.commit();
|
|
|
|
|
|
|
|
let mut tx2 = repo.start_transaction("test");
|
2021-11-26 10:18:43 +03:00
|
|
|
tx2.mut_repo()
|
2021-11-26 10:12:00 +03:00
|
|
|
.set_checkout(ws1_id.clone(), commit3.id().clone());
|
|
|
|
tx2.mut_repo()
|
|
|
|
.set_checkout(ws3_id.clone(), commit3.id().clone());
|
|
|
|
tx2.mut_repo()
|
|
|
|
.set_checkout(ws4_id.clone(), commit3.id().clone());
|
|
|
|
tx2.mut_repo().remove_checkout(&ws5_id);
|
|
|
|
tx2.mut_repo()
|
|
|
|
.set_checkout(ws7_id.clone(), commit3.id().clone());
|
2021-08-02 07:47:34 +03:00
|
|
|
tx2.commit();
|
|
|
|
|
|
|
|
let repo = repo.reload();
|
|
|
|
|
|
|
|
// We currently arbitrarily pick the first transaction's checkout (first by
|
|
|
|
// transaction end time).
|
2021-11-26 10:12:00 +03:00
|
|
|
assert_eq!(repo.view().get_checkout(&ws1_id), Some(commit2.id()));
|
|
|
|
assert_eq!(repo.view().get_checkout(&ws2_id), Some(commit2.id()));
|
|
|
|
assert_eq!(repo.view().get_checkout(&ws3_id), Some(commit3.id()));
|
|
|
|
assert_eq!(repo.view().get_checkout(&ws4_id), None);
|
|
|
|
assert_eq!(repo.view().get_checkout(&ws5_id), None);
|
|
|
|
assert_eq!(repo.view().get_checkout(&ws6_id), Some(commit2.id()));
|
|
|
|
assert_eq!(repo.view().get_checkout(&ws7_id), Some(commit3.id()));
|
2021-08-02 07:47:34 +03:00
|
|
|
}
|
|
|
|
|
view: add support for ref-based branches and tags to model
I've finally decided to copy Git's branching model (issue #21), except
that I'm letting the name identify the branch across
remotes. Actually, now that I think about, that makes them more like
Mercurial's "bookmarks". Each branch will record the commit it points
to locally, as well as the commits it points to on each remote (as far
as the repo knows, of course). Those records are effectively the same
thing as Git's "remote-tracking branches"; the difference is that we
consider them the same branch. Consequently, when you pull a new
branch from a remote, we'll create that branch locally.
For example, if you pull branch "main" from a remote called "origin",
that will result in a local branch called "main", and also a record of
the position on the remote, which we'll show as "main@origin" in the
CLI (not part of this commit). If you then update the branch locally
and also pull a new target for it from "origin", the local "main"
branch will be divergent. I plan to make it so that pushing "main"
will update the remote's "main" iff it was currently at "main@origin"
(i.e. like using Git's `git push --force-with-lease`).
This commit adds a place to store information about branches in the
view model. The existing git_refs field will be used as input for the
branch information. For example, we can use it to tell if
"refs/heads/main" has changed and how it has changed. We will then use
that ref diff to update our own record of the "main" branch. That will
come later. In order to let git_refs take a back seat, I've also added
tags (like Git's lightweight tags) to the model in this commit.
I haven't ruled out *also* having some more persistent type of
branches (like Mercurials branches or topics).
2021-07-15 11:31:48 +03:00
|
|
|
#[test]
|
|
|
|
fn test_merge_views_branches() {
|
|
|
|
// Tests merging of branches (by performing concurrent operations). See
|
|
|
|
// test_refs.rs for tests of merging of individual ref targets.
|
|
|
|
let settings = testutils::user_settings();
|
2022-02-06 00:29:55 +03:00
|
|
|
let test_repo = testutils::init_repo(&settings, false);
|
|
|
|
let repo = &test_repo.repo;
|
view: add support for ref-based branches and tags to model
I've finally decided to copy Git's branching model (issue #21), except
that I'm letting the name identify the branch across
remotes. Actually, now that I think about, that makes them more like
Mercurial's "bookmarks". Each branch will record the commit it points
to locally, as well as the commits it points to on each remote (as far
as the repo knows, of course). Those records are effectively the same
thing as Git's "remote-tracking branches"; the difference is that we
consider them the same branch. Consequently, when you pull a new
branch from a remote, we'll create that branch locally.
For example, if you pull branch "main" from a remote called "origin",
that will result in a local branch called "main", and also a record of
the position on the remote, which we'll show as "main@origin" in the
CLI (not part of this commit). If you then update the branch locally
and also pull a new target for it from "origin", the local "main"
branch will be divergent. I plan to make it so that pushing "main"
will update the remote's "main" iff it was currently at "main@origin"
(i.e. like using Git's `git push --force-with-lease`).
This commit adds a place to store information about branches in the
view model. The existing git_refs field will be used as input for the
branch information. For example, we can use it to tell if
"refs/heads/main" has changed and how it has changed. We will then use
that ref diff to update our own record of the "main" branch. That will
come later. In order to let git_refs take a back seat, I've also added
tags (like Git's lightweight tags) to the model in this commit.
I haven't ruled out *also* having some more persistent type of
branches (like Mercurials branches or topics).
2021-07-15 11:31:48 +03:00
|
|
|
|
|
|
|
let mut tx = repo.start_transaction("test");
|
|
|
|
let mut_repo = tx.mut_repo();
|
|
|
|
let main_branch_local_tx0 =
|
2021-11-21 10:46:54 +03:00
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
view: add support for ref-based branches and tags to model
I've finally decided to copy Git's branching model (issue #21), except
that I'm letting the name identify the branch across
remotes. Actually, now that I think about, that makes them more like
Mercurial's "bookmarks". Each branch will record the commit it points
to locally, as well as the commits it points to on each remote (as far
as the repo knows, of course). Those records are effectively the same
thing as Git's "remote-tracking branches"; the difference is that we
consider them the same branch. Consequently, when you pull a new
branch from a remote, we'll create that branch locally.
For example, if you pull branch "main" from a remote called "origin",
that will result in a local branch called "main", and also a record of
the position on the remote, which we'll show as "main@origin" in the
CLI (not part of this commit). If you then update the branch locally
and also pull a new target for it from "origin", the local "main"
branch will be divergent. I plan to make it so that pushing "main"
will update the remote's "main" iff it was currently at "main@origin"
(i.e. like using Git's `git push --force-with-lease`).
This commit adds a place to store information about branches in the
view model. The existing git_refs field will be used as input for the
branch information. For example, we can use it to tell if
"refs/heads/main" has changed and how it has changed. We will then use
that ref diff to update our own record of the "main" branch. That will
come later. In order to let git_refs take a back seat, I've also added
tags (like Git's lightweight tags) to the model in this commit.
I haven't ruled out *also* having some more persistent type of
branches (like Mercurials branches or topics).
2021-07-15 11:31:48 +03:00
|
|
|
let main_branch_origin_tx0 =
|
2021-11-21 10:46:54 +03:00
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
2021-10-03 09:03:36 +03:00
|
|
|
let main_branch_origin_tx1 =
|
2021-11-21 10:46:54 +03:00
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
view: add support for ref-based branches and tags to model
I've finally decided to copy Git's branching model (issue #21), except
that I'm letting the name identify the branch across
remotes. Actually, now that I think about, that makes them more like
Mercurial's "bookmarks". Each branch will record the commit it points
to locally, as well as the commits it points to on each remote (as far
as the repo knows, of course). Those records are effectively the same
thing as Git's "remote-tracking branches"; the difference is that we
consider them the same branch. Consequently, when you pull a new
branch from a remote, we'll create that branch locally.
For example, if you pull branch "main" from a remote called "origin",
that will result in a local branch called "main", and also a record of
the position on the remote, which we'll show as "main@origin" in the
CLI (not part of this commit). If you then update the branch locally
and also pull a new target for it from "origin", the local "main"
branch will be divergent. I plan to make it so that pushing "main"
will update the remote's "main" iff it was currently at "main@origin"
(i.e. like using Git's `git push --force-with-lease`).
This commit adds a place to store information about branches in the
view model. The existing git_refs field will be used as input for the
branch information. For example, we can use it to tell if
"refs/heads/main" has changed and how it has changed. We will then use
that ref diff to update our own record of the "main" branch. That will
come later. In order to let git_refs take a back seat, I've also added
tags (like Git's lightweight tags) to the model in this commit.
I haven't ruled out *also* having some more persistent type of
branches (like Mercurials branches or topics).
2021-07-15 11:31:48 +03:00
|
|
|
let main_branch_alternate_tx0 =
|
2021-11-21 10:46:54 +03:00
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
view: add support for ref-based branches and tags to model
I've finally decided to copy Git's branching model (issue #21), except
that I'm letting the name identify the branch across
remotes. Actually, now that I think about, that makes them more like
Mercurial's "bookmarks". Each branch will record the commit it points
to locally, as well as the commits it points to on each remote (as far
as the repo knows, of course). Those records are effectively the same
thing as Git's "remote-tracking branches"; the difference is that we
consider them the same branch. Consequently, when you pull a new
branch from a remote, we'll create that branch locally.
For example, if you pull branch "main" from a remote called "origin",
that will result in a local branch called "main", and also a record of
the position on the remote, which we'll show as "main@origin" in the
CLI (not part of this commit). If you then update the branch locally
and also pull a new target for it from "origin", the local "main"
branch will be divergent. I plan to make it so that pushing "main"
will update the remote's "main" iff it was currently at "main@origin"
(i.e. like using Git's `git push --force-with-lease`).
This commit adds a place to store information about branches in the
view model. The existing git_refs field will be used as input for the
branch information. For example, we can use it to tell if
"refs/heads/main" has changed and how it has changed. We will then use
that ref diff to update our own record of the "main" branch. That will
come later. In order to let git_refs take a back seat, I've also added
tags (like Git's lightweight tags) to the model in this commit.
I haven't ruled out *also* having some more persistent type of
branches (like Mercurials branches or topics).
2021-07-15 11:31:48 +03:00
|
|
|
mut_repo.set_local_branch(
|
|
|
|
"main".to_string(),
|
|
|
|
RefTarget::Normal(main_branch_local_tx0.id().clone()),
|
|
|
|
);
|
|
|
|
mut_repo.set_remote_branch(
|
|
|
|
"main".to_string(),
|
|
|
|
"origin".to_string(),
|
|
|
|
RefTarget::Normal(main_branch_origin_tx0.id().clone()),
|
|
|
|
);
|
|
|
|
mut_repo.set_remote_branch(
|
|
|
|
"main".to_string(),
|
|
|
|
"alternate".to_string(),
|
|
|
|
RefTarget::Normal(main_branch_alternate_tx0.id().clone()),
|
|
|
|
);
|
|
|
|
let feature_branch_local_tx0 =
|
2021-11-21 10:46:54 +03:00
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
view: add support for ref-based branches and tags to model
I've finally decided to copy Git's branching model (issue #21), except
that I'm letting the name identify the branch across
remotes. Actually, now that I think about, that makes them more like
Mercurial's "bookmarks". Each branch will record the commit it points
to locally, as well as the commits it points to on each remote (as far
as the repo knows, of course). Those records are effectively the same
thing as Git's "remote-tracking branches"; the difference is that we
consider them the same branch. Consequently, when you pull a new
branch from a remote, we'll create that branch locally.
For example, if you pull branch "main" from a remote called "origin",
that will result in a local branch called "main", and also a record of
the position on the remote, which we'll show as "main@origin" in the
CLI (not part of this commit). If you then update the branch locally
and also pull a new target for it from "origin", the local "main"
branch will be divergent. I plan to make it so that pushing "main"
will update the remote's "main" iff it was currently at "main@origin"
(i.e. like using Git's `git push --force-with-lease`).
This commit adds a place to store information about branches in the
view model. The existing git_refs field will be used as input for the
branch information. For example, we can use it to tell if
"refs/heads/main" has changed and how it has changed. We will then use
that ref diff to update our own record of the "main" branch. That will
come later. In order to let git_refs take a back seat, I've also added
tags (like Git's lightweight tags) to the model in this commit.
I haven't ruled out *also* having some more persistent type of
branches (like Mercurials branches or topics).
2021-07-15 11:31:48 +03:00
|
|
|
mut_repo.set_git_ref(
|
|
|
|
"feature".to_string(),
|
|
|
|
RefTarget::Normal(feature_branch_local_tx0.id().clone()),
|
|
|
|
);
|
|
|
|
let repo = tx.commit();
|
|
|
|
|
|
|
|
let mut tx1 = repo.start_transaction("test");
|
|
|
|
let main_branch_local_tx1 =
|
|
|
|
testutils::create_random_commit(&settings, &repo).write_to_repo(tx1.mut_repo());
|
|
|
|
tx1.mut_repo().set_local_branch(
|
|
|
|
"main".to_string(),
|
|
|
|
RefTarget::Normal(main_branch_local_tx1.id().clone()),
|
|
|
|
);
|
|
|
|
tx1.mut_repo().set_remote_branch(
|
|
|
|
"main".to_string(),
|
|
|
|
"origin".to_string(),
|
|
|
|
RefTarget::Normal(main_branch_origin_tx1.id().clone()),
|
|
|
|
);
|
|
|
|
let feature_branch_tx1 =
|
|
|
|
testutils::create_random_commit(&settings, &repo).write_to_repo(tx1.mut_repo());
|
|
|
|
tx1.mut_repo().set_local_branch(
|
|
|
|
"feature".to_string(),
|
|
|
|
RefTarget::Normal(feature_branch_tx1.id().clone()),
|
|
|
|
);
|
|
|
|
tx1.commit();
|
|
|
|
|
|
|
|
let mut tx2 = repo.start_transaction("test");
|
|
|
|
let main_branch_local_tx2 =
|
|
|
|
testutils::create_random_commit(&settings, &repo).write_to_repo(tx2.mut_repo());
|
|
|
|
tx2.mut_repo().set_local_branch(
|
|
|
|
"main".to_string(),
|
|
|
|
RefTarget::Normal(main_branch_local_tx2.id().clone()),
|
|
|
|
);
|
|
|
|
tx2.mut_repo().set_remote_branch(
|
|
|
|
"main".to_string(),
|
|
|
|
"origin".to_string(),
|
|
|
|
RefTarget::Normal(main_branch_origin_tx1.id().clone()),
|
|
|
|
);
|
|
|
|
tx2.commit();
|
|
|
|
|
|
|
|
let repo = repo.reload();
|
|
|
|
let expected_main_branch = BranchTarget {
|
|
|
|
local_target: Some(RefTarget::Conflict {
|
|
|
|
removes: vec![main_branch_local_tx0.id().clone()],
|
|
|
|
adds: vec![
|
|
|
|
main_branch_local_tx1.id().clone(),
|
|
|
|
main_branch_local_tx2.id().clone(),
|
|
|
|
],
|
|
|
|
}),
|
|
|
|
remote_targets: btreemap! {
|
|
|
|
"origin".to_string() => RefTarget::Normal(main_branch_origin_tx1.id().clone()),
|
|
|
|
"alternate".to_string() => RefTarget::Normal(main_branch_alternate_tx0.id().clone()),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
let expected_feature_branch = BranchTarget {
|
|
|
|
local_target: Some(RefTarget::Normal(feature_branch_tx1.id().clone())),
|
|
|
|
remote_targets: btreemap! {},
|
|
|
|
};
|
|
|
|
assert_eq!(
|
|
|
|
repo.view().branches(),
|
|
|
|
&btreemap! {
|
|
|
|
"main".to_string() => expected_main_branch,
|
|
|
|
"feature".to_string() => expected_feature_branch,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_merge_views_tags() {
|
|
|
|
// Tests merging of tags (by performing concurrent operations). See
|
|
|
|
// test_refs.rs for tests of merging of individual ref targets.
|
|
|
|
let settings = testutils::user_settings();
|
2022-02-06 00:29:55 +03:00
|
|
|
let test_repo = testutils::init_repo(&settings, false);
|
|
|
|
let repo = &test_repo.repo;
|
view: add support for ref-based branches and tags to model
I've finally decided to copy Git's branching model (issue #21), except
that I'm letting the name identify the branch across
remotes. Actually, now that I think about, that makes them more like
Mercurial's "bookmarks". Each branch will record the commit it points
to locally, as well as the commits it points to on each remote (as far
as the repo knows, of course). Those records are effectively the same
thing as Git's "remote-tracking branches"; the difference is that we
consider them the same branch. Consequently, when you pull a new
branch from a remote, we'll create that branch locally.
For example, if you pull branch "main" from a remote called "origin",
that will result in a local branch called "main", and also a record of
the position on the remote, which we'll show as "main@origin" in the
CLI (not part of this commit). If you then update the branch locally
and also pull a new target for it from "origin", the local "main"
branch will be divergent. I plan to make it so that pushing "main"
will update the remote's "main" iff it was currently at "main@origin"
(i.e. like using Git's `git push --force-with-lease`).
This commit adds a place to store information about branches in the
view model. The existing git_refs field will be used as input for the
branch information. For example, we can use it to tell if
"refs/heads/main" has changed and how it has changed. We will then use
that ref diff to update our own record of the "main" branch. That will
come later. In order to let git_refs take a back seat, I've also added
tags (like Git's lightweight tags) to the model in this commit.
I haven't ruled out *also* having some more persistent type of
branches (like Mercurials branches or topics).
2021-07-15 11:31:48 +03:00
|
|
|
|
|
|
|
let mut tx = repo.start_transaction("test");
|
|
|
|
let mut_repo = tx.mut_repo();
|
2021-11-21 10:46:54 +03:00
|
|
|
let v1_tx0 = testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
view: add support for ref-based branches and tags to model
I've finally decided to copy Git's branching model (issue #21), except
that I'm letting the name identify the branch across
remotes. Actually, now that I think about, that makes them more like
Mercurial's "bookmarks". Each branch will record the commit it points
to locally, as well as the commits it points to on each remote (as far
as the repo knows, of course). Those records are effectively the same
thing as Git's "remote-tracking branches"; the difference is that we
consider them the same branch. Consequently, when you pull a new
branch from a remote, we'll create that branch locally.
For example, if you pull branch "main" from a remote called "origin",
that will result in a local branch called "main", and also a record of
the position on the remote, which we'll show as "main@origin" in the
CLI (not part of this commit). If you then update the branch locally
and also pull a new target for it from "origin", the local "main"
branch will be divergent. I plan to make it so that pushing "main"
will update the remote's "main" iff it was currently at "main@origin"
(i.e. like using Git's `git push --force-with-lease`).
This commit adds a place to store information about branches in the
view model. The existing git_refs field will be used as input for the
branch information. For example, we can use it to tell if
"refs/heads/main" has changed and how it has changed. We will then use
that ref diff to update our own record of the "main" branch. That will
come later. In order to let git_refs take a back seat, I've also added
tags (like Git's lightweight tags) to the model in this commit.
I haven't ruled out *also* having some more persistent type of
branches (like Mercurials branches or topics).
2021-07-15 11:31:48 +03:00
|
|
|
mut_repo.set_tag("v1.0".to_string(), RefTarget::Normal(v1_tx0.id().clone()));
|
2021-11-21 10:46:54 +03:00
|
|
|
let v2_tx0 = testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
view: add support for ref-based branches and tags to model
I've finally decided to copy Git's branching model (issue #21), except
that I'm letting the name identify the branch across
remotes. Actually, now that I think about, that makes them more like
Mercurial's "bookmarks". Each branch will record the commit it points
to locally, as well as the commits it points to on each remote (as far
as the repo knows, of course). Those records are effectively the same
thing as Git's "remote-tracking branches"; the difference is that we
consider them the same branch. Consequently, when you pull a new
branch from a remote, we'll create that branch locally.
For example, if you pull branch "main" from a remote called "origin",
that will result in a local branch called "main", and also a record of
the position on the remote, which we'll show as "main@origin" in the
CLI (not part of this commit). If you then update the branch locally
and also pull a new target for it from "origin", the local "main"
branch will be divergent. I plan to make it so that pushing "main"
will update the remote's "main" iff it was currently at "main@origin"
(i.e. like using Git's `git push --force-with-lease`).
This commit adds a place to store information about branches in the
view model. The existing git_refs field will be used as input for the
branch information. For example, we can use it to tell if
"refs/heads/main" has changed and how it has changed. We will then use
that ref diff to update our own record of the "main" branch. That will
come later. In order to let git_refs take a back seat, I've also added
tags (like Git's lightweight tags) to the model in this commit.
I haven't ruled out *also* having some more persistent type of
branches (like Mercurials branches or topics).
2021-07-15 11:31:48 +03:00
|
|
|
mut_repo.set_tag("v2.0".to_string(), RefTarget::Normal(v2_tx0.id().clone()));
|
|
|
|
let repo = tx.commit();
|
|
|
|
|
|
|
|
let mut tx1 = repo.start_transaction("test");
|
|
|
|
let v1_tx1 = testutils::create_random_commit(&settings, &repo).write_to_repo(tx1.mut_repo());
|
|
|
|
tx1.mut_repo()
|
|
|
|
.set_tag("v1.0".to_string(), RefTarget::Normal(v1_tx1.id().clone()));
|
|
|
|
let v2_tx1 = testutils::create_random_commit(&settings, &repo).write_to_repo(tx1.mut_repo());
|
|
|
|
tx1.mut_repo()
|
|
|
|
.set_tag("v2.0".to_string(), RefTarget::Normal(v2_tx1.id().clone()));
|
|
|
|
tx1.commit();
|
|
|
|
|
|
|
|
let mut tx2 = repo.start_transaction("test");
|
|
|
|
let v1_tx2 = testutils::create_random_commit(&settings, &repo).write_to_repo(tx2.mut_repo());
|
|
|
|
tx2.mut_repo()
|
|
|
|
.set_tag("v1.0".to_string(), RefTarget::Normal(v1_tx2.id().clone()));
|
|
|
|
tx2.commit();
|
|
|
|
|
|
|
|
let repo = repo.reload();
|
|
|
|
let expected_v1 = RefTarget::Conflict {
|
|
|
|
removes: vec![v1_tx0.id().clone()],
|
|
|
|
adds: vec![v1_tx1.id().clone(), v1_tx2.id().clone()],
|
|
|
|
};
|
|
|
|
let expected_v2 = RefTarget::Normal(v2_tx1.id().clone());
|
|
|
|
assert_eq!(
|
|
|
|
repo.view().tags(),
|
|
|
|
&btreemap! {
|
|
|
|
"v1.0".to_string() => expected_v1,
|
|
|
|
"v2.0".to_string() => expected_v2,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-08-02 07:47:34 +03:00
|
|
|
#[test]
|
|
|
|
fn test_merge_views_git_refs() {
|
|
|
|
// Tests merging of git refs (by performing concurrent operations). See
|
|
|
|
// test_refs.rs for tests of merging of individual ref targets.
|
|
|
|
let settings = testutils::user_settings();
|
2022-02-06 00:29:55 +03:00
|
|
|
let test_repo = testutils::init_repo(&settings, false);
|
|
|
|
let repo = &test_repo.repo;
|
2021-08-02 07:47:34 +03:00
|
|
|
|
|
|
|
let mut tx = repo.start_transaction("test");
|
|
|
|
let mut_repo = tx.mut_repo();
|
2021-11-21 10:46:54 +03:00
|
|
|
let main_branch_tx0 = testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
2021-08-02 07:47:34 +03:00
|
|
|
mut_repo.set_git_ref(
|
|
|
|
"refs/heads/main".to_string(),
|
|
|
|
RefTarget::Normal(main_branch_tx0.id().clone()),
|
|
|
|
);
|
|
|
|
let feature_branch_tx0 =
|
2021-11-21 10:46:54 +03:00
|
|
|
testutils::create_random_commit(&settings, repo).write_to_repo(mut_repo);
|
2021-08-02 07:47:34 +03:00
|
|
|
mut_repo.set_git_ref(
|
|
|
|
"refs/heads/feature".to_string(),
|
|
|
|
RefTarget::Normal(feature_branch_tx0.id().clone()),
|
|
|
|
);
|
|
|
|
let repo = tx.commit();
|
|
|
|
|
|
|
|
let mut tx1 = repo.start_transaction("test");
|
|
|
|
let main_branch_tx1 =
|
|
|
|
testutils::create_random_commit(&settings, &repo).write_to_repo(tx1.mut_repo());
|
|
|
|
tx1.mut_repo().set_git_ref(
|
|
|
|
"refs/heads/main".to_string(),
|
|
|
|
RefTarget::Normal(main_branch_tx1.id().clone()),
|
|
|
|
);
|
|
|
|
let feature_branch_tx1 =
|
|
|
|
testutils::create_random_commit(&settings, &repo).write_to_repo(tx1.mut_repo());
|
|
|
|
tx1.mut_repo().set_git_ref(
|
|
|
|
"refs/heads/feature".to_string(),
|
|
|
|
RefTarget::Normal(feature_branch_tx1.id().clone()),
|
|
|
|
);
|
|
|
|
tx1.commit();
|
|
|
|
|
|
|
|
let mut tx2 = repo.start_transaction("test");
|
|
|
|
let main_branch_tx2 =
|
|
|
|
testutils::create_random_commit(&settings, &repo).write_to_repo(tx2.mut_repo());
|
|
|
|
tx2.mut_repo().set_git_ref(
|
|
|
|
"refs/heads/main".to_string(),
|
|
|
|
RefTarget::Normal(main_branch_tx2.id().clone()),
|
|
|
|
);
|
|
|
|
tx2.commit();
|
|
|
|
|
|
|
|
let repo = repo.reload();
|
|
|
|
let expected_main_branch = RefTarget::Conflict {
|
|
|
|
removes: vec![main_branch_tx0.id().clone()],
|
|
|
|
adds: vec![main_branch_tx1.id().clone(), main_branch_tx2.id().clone()],
|
|
|
|
};
|
|
|
|
let expected_feature_branch = RefTarget::Normal(feature_branch_tx1.id().clone());
|
|
|
|
assert_eq!(
|
|
|
|
repo.view().git_refs(),
|
|
|
|
&btreemap! {
|
|
|
|
"refs/heads/main".to_string() => expected_main_branch,
|
|
|
|
"refs/heads/feature".to_string() => expected_feature_branch,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|