Skip to content

Commit

Permalink
git: on initial export, export all branches
Browse files Browse the repository at this point in the history
As I said in the previous patch, I don't know why I made the initial
export to Git a no-op. Exporting everything makes more sense to
(current-)me. It will make it slightly easier to skip exporting
conflicted branches (#463).
  • Loading branch information
martinvonz committed Nov 3, 2022
1 parent 5ef67ca commit 3c9b41b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
19 changes: 11 additions & 8 deletions lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,14 +245,17 @@ pub fn export_refs(
upgrade_old_export_state(repo);

let last_export_path = repo.repo_path().join("git_export_view");
if let Ok(last_export_file) = OpenOptions::new().read(true).open(&last_export_path) {
let mut protocol = TCompactInputProtocol::new(&last_export_file);
let thrift_view = simple_op_store_model::View::read_from_in_protocol(&mut protocol)
.map_err(|err| GitExportError::ReadStateError(err.to_string()))?;
let last_export_store_view = simple_op_store::view_from_thrift(&thrift_view);
let last_export_view = View::new(last_export_store_view);
export_changes(&last_export_view, repo.view(), git_repo)?;
}
let last_export_store_view =
if let Ok(last_export_file) = OpenOptions::new().read(true).open(&last_export_path) {
let mut protocol = TCompactInputProtocol::new(&last_export_file);
let thrift_view = simple_op_store_model::View::read_from_in_protocol(&mut protocol)
.map_err(|err| GitExportError::ReadStateError(err.to_string()))?;
simple_op_store::view_from_thrift(&thrift_view)
} else {
crate::op_store::View::default()
};
let last_export_view = View::new(last_export_store_view);
export_changes(&last_export_view, repo.view(), git_repo)?;
if let Ok(mut last_export_file) = OpenOptions::new()
.write(true)
.create(true)
Expand Down
7 changes: 4 additions & 3 deletions lib/tests/test_git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,8 +403,9 @@ fn test_import_refs_detached_head() {
}

#[test]
fn test_export_refs_initial() {
// The first export doesn't do anything
fn test_export_refs_no_detach() {
// When exporting the branch that's current checked out, don't detach HEAD if
// the target already matches
let mut test_data = GitRepoData::create();
let git_repo = test_data.git_repo;
let commit1 = empty_git_commit(&git_repo, "refs/heads/main", &[]);
Expand All @@ -416,7 +417,7 @@ fn test_export_refs_initial() {
.unwrap();
test_data.repo = tx.commit();

// The first export shouldn't do anything
// Do an initial export to make sure `main` is considered
assert_eq!(git::export_refs(&test_data.repo, &git_repo), Ok(()));
assert_eq!(git_repo.head().unwrap().name(), Some("refs/heads/main"));
assert_eq!(
Expand Down

0 comments on commit 3c9b41b

Please sign in to comment.