Skip to content

Commit 093adc2

Browse files
authored
Merge pull request #7346 from Byron/fix-commit-changes
Use one commit only for obtaining changes for Commit
2 parents f135ba6 + 79b40b2 commit 093adc2

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

apps/desktop/src/lib/worktree/worktreeService.svelte.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function injectEndpoints(api: ClientState['backendApi']) {
4444
* entity entity adapter to create the necessary selectors.
4545
*/
4646
getChanges: build.query<EntityState<TreeChange, string>, { projectId: string }>({
47-
query: ({ projectId }) => ({ command: 'worktree_changes', params: { projectId } }),
47+
query: ({ projectId }) => ({ command: 'changes_in_worktree', params: { projectId } }),
4848
/** Invalidating tags causes data to be refreshed. */
4949
providesTags: [ReduxTag.WorktreeChanges],
5050
/**

crates/but-core/src/diff/ui.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::ui::{TreeChange, WorktreeChanges};
2+
use gix::prelude::ObjectIdExt;
23
use std::path::PathBuf;
34

45
/// See [`super::worktree_changes()`].
@@ -10,10 +11,16 @@ pub fn worktree_changes_by_worktree_dir(worktree_dir: PathBuf) -> anyhow::Result
1011
/// See [`super::commit_changes()`].
1112
pub fn commit_changes_by_worktree_dir(
1213
worktree_dir: PathBuf,
13-
old_commit_id: Option<gix::ObjectId>,
14-
new_commit_id: gix::ObjectId,
14+
commit_id: gix::ObjectId,
1515
) -> anyhow::Result<Vec<TreeChange>> {
1616
let repo = gix::open(worktree_dir)?;
17-
super::commit_changes(&repo, old_commit_id, new_commit_id)
17+
let parent_id = commit_id
18+
.attach(&repo)
19+
.object()?
20+
.into_commit()
21+
.parent_ids()
22+
.map(|id| id.detach())
23+
.next();
24+
super::commit_changes(&repo, parent_id, commit_id)
1825
.map(|c| c.into_iter().map(Into::into).collect())
1926
}

crates/but-core/tests/core/diff/ui.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,6 @@ fn commit_to_commit() -> anyhow::Result<()> {
376376
let actual =
377377
serde_json::to_string_pretty(&but_core::diff::ui::commit_changes_by_worktree_dir(
378378
worktree_dir,
379-
Some(repo.rev_parse_single("@~1")?.into()),
380379
repo.rev_parse_single("@")?.into(),
381380
)?)?;
382381
insta::assert_snapshot!(actual, @r#"

crates/gitbutler-tauri/src/diff.rs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,14 @@ pub fn tree_change_diffs(
2424

2525
#[tauri::command(async)]
2626
#[instrument(skip(projects), err(Debug))]
27-
pub fn commit_changes(
27+
pub fn changes_in_commit(
2828
projects: tauri::State<'_, gitbutler_project::Controller>,
2929
project_id: ProjectId,
30-
old_commit_id: Option<HexHash>,
31-
new_commit_id: HexHash,
30+
commit_id: HexHash,
3231
) -> anyhow::Result<Vec<TreeChange>, Error> {
3332
let project = projects.get(project_id)?;
34-
but_core::diff::ui::commit_changes_by_worktree_dir(
35-
project.path,
36-
old_commit_id.map(Into::into),
37-
new_commit_id.into(),
38-
)
39-
.map_err(Into::into)
33+
but_core::diff::ui::commit_changes_by_worktree_dir(project.path, commit_id.into())
34+
.map_err(Into::into)
4035
}
4136

4237
/// This UI-version of [`but_core::diff::worktree_changes()`] simplifies the `git status` information for display in
@@ -50,7 +45,7 @@ pub fn commit_changes(
5045
/// All ignored status changes are also provided so they can be displayed separately.
5146
#[tauri::command(async)]
5247
#[instrument(skip(projects), err(Debug))]
53-
pub fn worktree_changes(
48+
pub fn changes_in_worktree(
5449
projects: tauri::State<'_, gitbutler_project::Controller>,
5550
project_id: ProjectId,
5651
) -> anyhow::Result<WorktreeChanges, Error> {

crates/gitbutler-tauri/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,8 @@ fn main() {
271271
workspace::hunk_dependencies_for_workspace_changes,
272272
workspace::create_commit_from_worktree_changes,
273273
workspace::amend_commit_from_worktree_changes,
274-
diff::worktree_changes,
275-
diff::commit_changes,
274+
diff::changes_in_worktree,
275+
diff::changes_in_commit,
276276
diff::tree_change_diffs,
277277
// `env_vars` is only supposed to be avaialble in debug mode, not in production.
278278
#[cfg(debug_assertions)]

0 commit comments

Comments
 (0)