Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@rachartier
Copy link

Hello,

I've added code to delete a branch by its name, or one selected by branch from Y.
Tell me what you think, and if I need to improve or change something.

Thanks for this amazing project.

Copy link
Owner

@altsem altsem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi. Nice to see this addition!

I got some feedback. See if they make sense.
A few tests are needed too. I found the related ones here:

gitu/src/tests/mod.rs

Lines 260 to 288 in 947da1b

mod checkout {
use super::*;
#[test]
pub(crate) fn checkout_menu() {
let ctx = TestContext::setup_clone();
run(ctx.dir.path(), &["git", "branch", "other-branch"]);
snapshot!(ctx, "Yjb");
}
#[test]
pub(crate) fn switch_branch_selected() {
let ctx = TestContext::setup_clone();
run(ctx.dir.path(), &["git", "branch", "other-branch"]);
snapshot!(ctx, "Yjjbb<enter>");
}
#[test]
pub(crate) fn switch_branch_input() {
let ctx = TestContext::setup_clone();
run(ctx.dir.path(), &["git", "branch", "hi"]);
snapshot!(ctx, "Yjjbbhi<enter>");
}
#[test]
pub(crate) fn checkout_new_branch() {
snapshot!(TestContext::setup_clone(), "bcf<esc>bcx<enter>");
}
}

@rachartier
Copy link
Author

Does it seem better?

I've tried to implement all your suggestions. Thanks for the input!

Tell me what you think

Copy link
Owner

@altsem altsem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey. Looks pretty good. I did some testing and found some things still. Good job though. Let's make it great :)

@codecov
Copy link

codecov bot commented Apr 19, 2025

Codecov Report

Attention: Patch coverage is 80.72289% with 16 lines in your changes missing coverage. Please review.

Project coverage is 86.61%. Comparing base (5b0a23b) to head (a361099).
Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/ops/checkout.rs 75.00% 10 Missing ⚠️
src/error.rs 0.00% 6 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #350      +/-   ##
==========================================
- Coverage   86.63%   86.61%   -0.03%     
==========================================
  Files          66       66              
  Lines        6127     6237     +110     
==========================================
+ Hits         5308     5402      +94     
- Misses        819      835      +16     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rachartier
Copy link
Author

Thank you a lot for your prompt modifications. It made it a whole lot easier!

I've made a new version that you can review.

Copy link
Owner

@altsem altsem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks pretty good! I have only two requests:

Consistency with "Discard" action

I found some more code while testing it out. This already existing action doesn't support deleting unmerged branches like the new one. It feels fine to have both of them, two different entry-points. K is always at-the-cursor, bK would prompt for a branch.
But perhaps they should share the underlying implementation?
https://github.com/altsem/gitu/blob/master/src/ops/discard.rs#L46-L57

Found here:
https://github.com/altsem/gitu/blob/master/src/ops/discard.rs#L46-L57

The generated changelog is off

gitu on  rachartier/master:master ❯ git cliff --unreleased
# Changelog

All notable changes to this project will be documented in this file.

## [unreleased]

### 🚀 Features

- Expose selected branch in state
- *(checkout)* Prompt before deleting unmerged branch
- *(config)* Add 'x' as default keybindings for branch operations
- *(branch)* Add delete branch functionality

see https://github.com/altsem/gitu/blob/master/docs/dev-tooling.md

Some ideas:

feat(branch): Deleting (unmerged) branches via the branch menu
feat(discard): Support for deleteing unmerged branches

if is_unmerged {
let branch_to_delete = branch.to_string();

match state.confirm(term, "Branch is unmerged. Really delete?") {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
match state.confirm(term, "Branch is unmerged. Really delete?") {
match state.confirm(term, "Branch is unmerged. Really delete? (y or n)") {

Ugly, but...
Let's throw in a (y or n) to make it consistent with the other ones? I should've just taken the effort to bake it into state.confirm, perhaps later.

@altsem
Copy link
Owner

altsem commented May 20, 2025

This was picked up in #367, I'll close this.
Gj though, we laid out the ground for it.

@altsem altsem closed this May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants