Skip to content

Commit 26fbee1

Browse files
Byronndom91
authored andcommitted
UI passes the name of the stack segment ref-name when creating new commits.
1 parent 16b83c2 commit 26fbee1

File tree

8 files changed

+28
-6
lines changed

8 files changed

+28
-6
lines changed

Cargo.lock

Lines changed: 1 addition & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

apps/desktop/src/components/v3/NewCommit.svelte

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
stackId,
7070
parentId,
7171
message: message,
72+
stackSegmentShortName: "top",
7273
worktreeChanges: selection.map((item) =>
7374
item.type === 'full'
7475
? {

apps/desktop/src/lib/stacks/stackService.svelte.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ type CreateCommitRequest = {
1414
stackId: string;
1515
message: string;
1616
parentId: string;
17+
stackSegmentShortName: string,
1718
worktreeChanges: {
1819
previousPathBytes?: number[];
1920
pathBytes: number[];

crates/but-cli/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ testing = ["dep:gitbutler-commit"]
1818
gitbutler-command-context.workspace = true
1919
gitbutler-project.workspace = true
2020
but-settings.workspace = true
21-
gitbutler-stack.workspace = true
2221
but-core.workspace = true
23-
gitbutler-oxidize.workspace = true
2422
but-workspace.workspace = true
2523
but-hunk-dependency.workspace = true
2624

crates/but-cli/src/args.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ pub enum Subcommands {
3131
/// The message of the new commit.
3232
#[clap(long, short = 'm')]
3333
message: Option<String>,
34+
/// The name of the reference that the commit should be in.
35+
///
36+
/// If there is ambiguity, this is what makes it ambiguous.
37+
#[clap(long, short = 's')]
38+
stack_segment_ref: Option<String>,
3439
/// Amend to the current or given commit.
3540
#[clap(long)]
3641
amend: bool,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub fn commit(
1010
message: Option<&str>,
1111
amend: bool,
1212
parent_revspec: Option<&str>,
13+
stack_segment_ref: Option<&str>,
1314
) -> anyhow::Result<()> {
1415
if message.is_none() && !amend {
1516
bail!("Need a message when creating a new commit");
@@ -31,6 +32,7 @@ pub fn commit(
3132
but_workspace::commit_engine::Destination::NewCommit {
3233
parent_commit_id: Some(parent_id),
3334
message: message.unwrap_or_default().to_owned(),
35+
stack_segment_ref: stack_segment_ref.map(|rn| rn.try_into()).transpose()?,
3436
}
3537
},
3638
None,

crates/but-cli/src/main.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ fn main() -> Result<()> {
2020
message,
2121
amend,
2222
parent,
23+
stack_segment_ref,
2324
} => {
2425
let (repo, project) = repo_and_maybe_project(&args, RepositoryOpenMode::Merge)?;
25-
command::commit(repo, project, message.as_deref(), *amend, parent.as_deref())
26+
command::commit(
27+
repo,
28+
project,
29+
message.as_deref(),
30+
*amend,
31+
parent.as_deref(),
32+
stack_segment_ref.as_deref(),
33+
)
2634
}
2735
args::Subcommands::HunkDependency => command::diff::locks(&args.current_dir),
2836
args::Subcommands::Status { unified_diff } => {

crates/gitbutler-tauri/src/workspace.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,11 @@ pub fn hunk_dependencies_for_workspace_changes(
8787
/// All `changes` are meant to be relative to the worktree.
8888
/// Note that submodules *must* be provided as diffspec without hunks, as attempting to generate
8989
/// hunks would fail.
90+
/// `stack_segment_short_name` is the short name of the reference that the UI knows is present in a given segment.
91+
/// It is needed to insert the new commit into the right bucket.
9092
#[tauri::command(async)]
9193
#[instrument(skip(projects, settings), err(Debug))]
94+
#[allow(clippy::too_many_arguments)]
9295
pub fn create_commit_from_worktree_changes(
9396
projects: State<'_, projects::Controller>,
9497
settings: State<'_, AppSettingsWithDiskSync>,
@@ -97,6 +100,7 @@ pub fn create_commit_from_worktree_changes(
97100
parent_id: Option<HexHash>,
98101
worktree_changes: Vec<commit_engine::ui::DiffSpec>,
99102
message: String,
103+
stack_segment_short_name: String,
100104
) -> Result<commit_engine::ui::CreateCommitOutcome, Error> {
101105
let project = projects.get(project_id)?;
102106
let repo = but_core::open_repo_for_merging(&project.worktree_path())?;
@@ -106,6 +110,11 @@ pub fn create_commit_from_worktree_changes(
106110
commit_engine::Destination::NewCommit {
107111
parent_commit_id: parent_id.map(Into::into),
108112
message,
113+
stack_segment_ref: Some(
114+
format!("refs/heads/{stack_segment_short_name}")
115+
.try_into()
116+
.map_err(anyhow::Error::from)?,
117+
),
109118
},
110119
None,
111120
worktree_changes.into_iter().map(Into::into).collect(),

0 commit comments

Comments
 (0)