Skip to content

Commit 7311dcf

Browse files
krlvischacon
authored andcommitted
Show marked commits in but status too
1 parent 5fa07a5 commit 7311dcf

File tree

15 files changed

+328
-209
lines changed

15 files changed

+328
-209
lines changed

crates/but/src/args.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub enum Subcommands {
4646
/// Value to set (if provided, sets the key to this value)
4747
value: Option<String>,
4848
},
49-
49+
5050
/// Show operation history (last 20 entries).
5151
Oplog {
5252
/// Start from this oplog SHA instead of the head

crates/but/src/branch/mod.rs

Lines changed: 54 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -71,27 +71,43 @@ pub(crate) fn create_branch(
7171
// Find the target stack and get its current head commit
7272
let stacks = crate::log::stacks(&ctx)?;
7373
let target_stack = stacks.iter().find(|s| {
74-
s.heads.iter().any(|head| head.name.to_string() == target_branch_name)
74+
s.heads
75+
.iter()
76+
.any(|head| head.name.to_string() == target_branch_name)
7577
});
76-
78+
7779
let target_stack = match target_stack {
7880
Some(s) => s,
79-
None => return Err(anyhow::anyhow!("No stack found for branch '{}'", target_branch_name)),
81+
None => {
82+
return Err(anyhow::anyhow!(
83+
"No stack found for branch '{}'",
84+
target_branch_name
85+
));
86+
}
8087
};
81-
82-
let target_stack_id = target_stack.id.ok_or_else(|| anyhow::anyhow!("Target stack has no ID"))?;
83-
88+
89+
let target_stack_id = target_stack
90+
.id
91+
.ok_or_else(|| anyhow::anyhow!("Target stack has no ID"))?;
92+
8493
// Get the stack details to find the head commit
8594
let target_stack_details = crate::log::stack_details(&ctx, target_stack_id)?;
8695
if target_stack_details.branch_details.is_empty() {
8796
return Err(anyhow::anyhow!("Target stack has no branch details"));
8897
}
89-
98+
9099
// Find the target branch in the stack details
91-
let target_branch_details = target_stack_details.branch_details.iter().find(|b|
92-
b.name == target_branch_name
93-
).ok_or_else(|| anyhow::anyhow!("Target branch '{}' not found in stack details", target_branch_name))?;
94-
100+
let target_branch_details = target_stack_details
101+
.branch_details
102+
.iter()
103+
.find(|b| b.name == target_branch_name)
104+
.ok_or_else(|| {
105+
anyhow::anyhow!(
106+
"Target branch '{}' not found in stack details",
107+
target_branch_name
108+
)
109+
})?;
110+
95111
// Get the head commit of the target branch
96112
let target_head_oid = if !target_branch_details.commits.is_empty() {
97113
// Use the last local commit
@@ -100,10 +116,13 @@ pub(crate) fn create_branch(
100116
// If no local commits, use the last upstream commit
101117
target_branch_details.upstream_commits.last().unwrap().id
102118
} else {
103-
return Err(anyhow::anyhow!("Target branch '{}' has no commits", target_branch_name));
119+
return Err(anyhow::anyhow!(
120+
"Target branch '{}' has no commits",
121+
target_branch_name
122+
));
104123
};
105-
106-
// Create a new virtual branch
124+
125+
// Create a new virtual branch
107126
let mut guard = project.exclusive_worktree_access();
108127
let create_request = BranchCreateRequest {
109128
name: Some(branch_name.to_string()),
@@ -112,12 +131,13 @@ pub(crate) fn create_branch(
112131
selected_for_changes: None,
113132
};
114133

115-
let new_stack_id = create_virtual_branch(&ctx, &create_request, guard.write_permission())?;
116-
134+
let new_stack_id =
135+
create_virtual_branch(&ctx, &create_request, guard.write_permission())?;
136+
117137
// Now set up the new branch to start from the target branch's head
118138
let vb_state = VirtualBranchesHandle::new(ctx.project().gb_dir());
119139
let mut new_stack = vb_state.get_stack(new_stack_id.id)?;
120-
140+
121141
// Set the head of the new stack to be the target branch's head
122142
// This creates the stacking relationship
123143
let gix_repo = ctx.repo().to_gix()?;
@@ -158,38 +178,35 @@ pub(crate) fn create_branch(
158178
Ok(())
159179
}
160180

161-
pub(crate) fn unapply_branch(
162-
repo_path: &Path,
163-
_json: bool,
164-
branch_id: &str,
165-
) -> anyhow::Result<()> {
181+
pub(crate) fn unapply_branch(repo_path: &Path, _json: bool, branch_id: &str) -> anyhow::Result<()> {
166182
let project = Project::from_path(repo_path)?;
167183
let mut ctx = CommandContext::open(&project, AppSettings::load_from_default_path_creating()?)?;
168-
184+
169185
// Try to resolve the branch ID
170186
let cli_ids = CliId::from_str(&mut ctx, branch_id)?;
171-
187+
172188
if cli_ids.is_empty() {
173189
return Err(anyhow::anyhow!(
174190
"Branch '{}' not found. Try using a branch CLI ID or full branch name.",
175191
branch_id
176192
));
177193
}
178-
194+
179195
if cli_ids.len() > 1 {
180-
let matches: Vec<String> = cli_ids.iter().map(|id| {
181-
match id {
196+
let matches: Vec<String> = cli_ids
197+
.iter()
198+
.map(|id| match id {
182199
CliId::Branch { name } => format!("{} (branch '{}')", id.to_string(), name),
183-
_ => format!("{} ({})", id.to_string(), id.kind())
184-
}
185-
}).collect();
200+
_ => format!("{} ({})", id.to_string(), id.kind()),
201+
})
202+
.collect();
186203
return Err(anyhow::anyhow!(
187204
"Branch '{}' is ambiguous. Matches: {}. Try using more characters or the full branch name.",
188205
branch_id,
189206
matches.join(", ")
190207
));
191208
}
192-
209+
193210
let cli_id = &cli_ids[0];
194211
let stack_id = match cli_id {
195212
CliId::Branch { .. } => {
@@ -204,7 +221,7 @@ pub(crate) fn unapply_branch(
204221
}
205222
})
206223
});
207-
224+
208225
match stack {
209226
Some(s) => s.id.ok_or_else(|| anyhow::anyhow!("Stack has no ID"))?,
210227
None => return Err(anyhow::anyhow!("No stack found for branch '{}'", branch_id)),
@@ -218,25 +235,25 @@ pub(crate) fn unapply_branch(
218235
));
219236
}
220237
};
221-
238+
222239
let branch_name = match cli_id {
223240
CliId::Branch { name } => name,
224241
_ => unreachable!(),
225242
};
226-
243+
227244
println!(
228245
"Unapplying branch '{}' ({})",
229246
branch_name.yellow().bold(),
230247
branch_id.blue().underline()
231248
);
232-
249+
233250
unapply_stack(&ctx, stack_id, Vec::new())?;
234-
251+
235252
println!(
236253
"{} Branch '{}' unapplied successfully!",
237254
"✓".green().bold(),
238255
branch_name.yellow().bold()
239256
);
240-
257+
241258
Ok(())
242259
}

crates/but/src/commit/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub(crate) fn commit(
115115
.find(|(id, _)| *id == target_stack_id)
116116
.unwrap()
117117
.1;
118-
118+
119119
// If a branch hint was provided, find that specific branch; otherwise use first branch
120120
let target_branch = if let Some(hint) = branch_hint {
121121
// First try exact name match
@@ -218,7 +218,7 @@ fn select_stack(
218218
}
219219
}
220220
}
221-
221+
222222
// If no exact match, try to parse as CLI ID
223223
match crate::id::CliId::from_str(ctx, hint) {
224224
Ok(cli_ids) => {
@@ -239,7 +239,7 @@ fn select_stack(
239239
// Ignore CLI ID parsing errors and continue with other methods
240240
}
241241
}
242-
242+
243243
anyhow::bail!("Branch '{}' not found", hint);
244244
}
245245

crates/but/src/config.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ pub struct AiProviderInfo {
4444
pub model: Option<String>,
4545
}
4646

47-
pub fn handle(current_dir: &Path, app_settings: &AppSettings, json: bool, key: Option<&str>, value: Option<&str>) -> Result<()> {
47+
pub fn handle(
48+
current_dir: &Path,
49+
app_settings: &AppSettings,
50+
json: bool,
51+
key: Option<&str>,
52+
value: Option<&str>,
53+
) -> Result<()> {
4854
match (key, value) {
4955
// Set configuration value
5056
(Some(key), Some(value)) => {
@@ -74,9 +80,9 @@ pub fn handle(current_dir: &Path, app_settings: &AppSettings, json: bool, key: O
7480
// Show all configuration (existing behavior)
7581
(None, None) => show(current_dir, app_settings, json),
7682
// Invalid: value without key
77-
(None, Some(_)) => {
78-
Err(anyhow::anyhow!("Cannot set a value without specifying a key"))
79-
}
83+
(None, Some(_)) => Err(anyhow::anyhow!(
84+
"Cannot set a value without specifying a key"
85+
)),
8086
}
8187
}
8288

@@ -257,19 +263,20 @@ fn print_ai_provider(name: &str, provider: &AiProviderInfo) {
257263
}
258264

259265
fn set_config_value(current_dir: &Path, key: &str, value: &str) -> Result<()> {
260-
let git_repo = git2::Repository::discover(current_dir)
261-
.context("Failed to find Git repository")?;
266+
let git_repo =
267+
git2::Repository::discover(current_dir).context("Failed to find Git repository")?;
262268
let config = Config::from(&git_repo);
263-
264-
config.set_local(key, value)
269+
270+
config
271+
.set_local(key, value)
265272
.with_context(|| format!("Failed to set {} = {}", key, value))
266273
}
267274

268275
fn get_config_value(current_dir: &Path, key: &str) -> Result<Option<String>> {
269-
let git_repo = git2::Repository::discover(current_dir)
270-
.context("Failed to find Git repository")?;
276+
let git_repo =
277+
git2::Repository::discover(current_dir).context("Failed to find Git repository")?;
271278
let config = Config::from(&git_repo);
272-
279+
273280
// For getting values, use the same logic as the existing code
274281
// which checks the full git config hierarchy (local, global, system)
275282
match key {

0 commit comments

Comments
 (0)