Skip to content

Commit e60e0d8

Browse files
committed
commit engine: get the write lock passed when committing
1 parent 69d50ff commit e60e0d8

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

crates/but-cli/src/command/commit.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ pub fn commit(
3535
};
3636
let changes = to_whole_file_diffspec(but_core::diff::worktree_changes(&repo)?.changes);
3737
if let Some(project) = project.as_ref() {
38+
let mut guard = project.exclusive_worktree_access();
3839
debug_print(
3940
but_workspace::commit_engine::create_commit_and_update_refs_with_project(
4041
&repo,
@@ -44,6 +45,7 @@ pub fn commit(
4445
None,
4546
changes,
4647
0, /* context-lines */
48+
guard.write_permission(),
4749
)?,
4850
)?;
4951
} else {

crates/but-workspace/src/commit_engine/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use but_core::RepositoryExt;
66
use but_core::unified_diff::DiffHunk;
77
use but_rebase::RebaseOutput;
88
use but_rebase::commit::CommitterMode;
9+
use gitbutler_project::access::WorktreeWritePermission;
910
use gitbutler_stack::{StackId, VirtualBranchesHandle, VirtualBranchesState};
1011
use gix::prelude::ObjectIdExt as _;
1112
use gix::refs::transaction::PreviousValue;
@@ -473,6 +474,7 @@ pub fn create_commit_and_update_refs(
473474
/// if present. Alternatively it uses the current `HEAD` as only reference point.
474475
/// Note that virtual branches will be updated and written back after this call, which will obtain
475476
/// an exclusive workspace lock as well.
477+
#[allow(clippy::too_many_arguments)]
476478
pub fn create_commit_and_update_refs_with_project(
477479
repo: &gix::Repository,
478480
project: &gitbutler_project::Project,
@@ -481,8 +483,8 @@ pub fn create_commit_and_update_refs_with_project(
481483
move_source: Option<MoveSourceCommit>,
482484
changes: Vec<DiffSpec>,
483485
context_lines: u32,
486+
_perm: &mut WorktreeWritePermission,
484487
) -> anyhow::Result<CreateCommitOutcome> {
485-
let _guard = project.exclusive_worktree_access();
486488
let vbh = VirtualBranchesHandle::new(project.gb_dir());
487489
let mut vb = vbh.read_file()?;
488490
let frame = match maybe_stackid {

crates/gitbutler-branch-actions/src/actions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ fn amend_with_commit_engine(
326326
commit_oid: git2::Oid,
327327
worktree_changes: Vec<DiffSpec>,
328328
) -> Result<git2::Oid> {
329-
// let changes: Vec<DiffSpec> = ownership.claims.iter().map(claim_to_diffspec).collect();
329+
let mut guard = ctx.project().exclusive_worktree_access();
330330

331331
let vb_state = ctx.project().virtual_branches();
332332
let stack = vb_state.get_stack(stack_id)?;
@@ -344,6 +344,7 @@ fn amend_with_commit_engine(
344344
None,
345345
worktree_changes,
346346
3, // for the old API this is hardcoded
347+
guard.write_permission(),
347348
)?;
348349
let new_commit = outcome.new_commit.ok_or(anyhow::anyhow!(
349350
"Failed to amend with commit engine. Rejected specs: {:?}",

crates/gitbutler-tauri/src/workspace.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ pub fn create_commit_from_worktree_changes(
120120
}
121121
}
122122
};
123+
let guard = project.exclusive_worktree_access();
123124
Ok(commit_engine::create_commit_and_update_refs_with_project(
124125
&repo,
125126
&project,
@@ -136,6 +137,7 @@ pub fn create_commit_from_worktree_changes(
136137
None,
137138
worktree_changes.into_iter().map(Into::into).collect(),
138139
settings.get()?.context_lines,
140+
guard,
139141
)?
140142
.into())
141143
}
@@ -156,6 +158,7 @@ pub fn amend_commit_from_worktree_changes(
156158
worktree_changes: Vec<commit_engine::ui::DiffSpec>,
157159
) -> Result<commit_engine::ui::CreateCommitOutcome, Error> {
158160
let project = projects.get(project_id)?;
161+
let mut guard = project.exclusive_worktree_access();
159162
let repo = but_core::open_repo_for_merging(&project.worktree_path())?;
160163
Ok(commit_engine::create_commit_and_update_refs_with_project(
161164
&repo,
@@ -165,6 +168,7 @@ pub fn amend_commit_from_worktree_changes(
165168
None,
166169
worktree_changes.into_iter().map(Into::into).collect(),
167170
settings.get()?.context_lines,
171+
guard.write_permission(),
168172
)?
169173
.into())
170174
}

0 commit comments

Comments
 (0)