altsem / gitu

A TUI Git client inspired by Magit
MIT License
1.7k stars 88 forks source link

feat: stash status, save, pop, apply and drop #73

Closed golden-expiriensu closed 4 months ago

golden-expiriensu commented 4 months ago

Almost everything is working as expected, but unfortunately I have no idea so far how to

golden-expiriensu commented 4 months ago

Resolves https://github.com/altsem/gitu/issues/37 btw

altsem commented 4 months ago

Yea, TargetOp was a mess, I've been trying to make this interface better. And now it's gone. Apologize for the conflicts :man_facepalming:. I'll have a look and see if I can help :+1:

altsem commented 4 months ago

This is how it looks like in master right now:

pub(crate) type Action = Rc<dyn FnMut(&mut State, &mut Term) -> Res<()>>;

pub(crate) trait OpTrait: Display {
    /// Get the implementation (which may or may not exist) of the Op given some TargetData.
    /// This indirection allows Gitu to show a contextual menu of applicable actions.
    fn get_action(&self, target: Option<&TargetData>) -> Option<Action>;

    /// This indicates whether the Op is meant to read and
    /// act on TargetData. Those are listed differently in the help menu.
    fn is_target_op(&self) -> bool {
        false
    }
}

image

Starting to feel the complexity vs the gains of doing this is kind of not worth it.

Perhaps should be changed back to just be a trigger function, and nothing more.

pub(crate) trait OpTrait: Display {
    fn trigger(&self, target: Option<&TargetData>);
}

This means you would lose the contextual "target" column (here ret Show is listed with the other ops): image

For now, you could emulate this by just doing:


    fn get_action(&self, _target: Option<&TargetData>) -> Option<Action> {
        Some(Rc::new(|state: &mut State, _term: &mut Term| {
            ...
            Ok(())
        }))
    }
golden-expiriensu commented 4 months ago

I am doing a rebase right now and actually new updates are looking pretty good so far, so its okay, no worries

golden-expiriensu commented 4 months ago

@altsem Sorry for stash_push_action_prompt_update arguments, I wanted to accept iterator over static strings, but lost to lifetimes :(

altsem commented 4 months ago

Very cool! Having a look :)

golden-expiriensu commented 4 months ago

golden-expiriensu#1

Ooh, thank you very much! I actually managed to solve this issue with stash_push_action<const N: usize>(args: [&'static str; N]). So pick which variant you would like to keep in the repo and I will update code accordingly

codecov[bot] commented 4 months ago

Codecov Report

Attention: Patch coverage is 15.19608% with 173 lines in your changes are missing coverage. Please review.

Project coverage is 78.75%. Comparing base (8069c38) to head (f850cdc).

Files Patch % Lines
src/ops/stash.rs 0.00% 123 Missing :warning:
src/items.rs 35.00% 26 Missing :warning:
src/screen/status.rs 50.00% 16 Missing :warning:
src/ops/mod.rs 12.50% 7 Missing :warning:
src/ops/show.rs 0.00% 1 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #73 +/- ## ========================================== - Coverage 83.49% 78.75% -4.74% ========================================== Files 36 37 +1 Lines 2738 2942 +204 ========================================== + Hits 2286 2317 +31 - Misses 452 625 +173 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

altsem commented 4 months ago

Looks good so far! Just some tests missing. Let me know if you need help with this, I wouldn't mind writing them either @golden-expiriensu.

Then when you feel it's ready, let me know and I'll have a final look / test things out manually too.

Haven't settled on a strict commit format, I'll update the PR name just in case I forget. The "feat: " prefix will result in a changelog entry.

golden-expiriensu commented 4 months ago

Hey @altsem, I added tests for stash functionality, the PR is ready for the final review, let me know if I missed something P.S. Btw, the tooling and test setup is awesome, I had a great time writing it

codecov-commenter commented 4 months ago

Codecov Report

Attention: Patch coverage is 97.90698% with 9 lines in your changes are missing coverage. Please review.

Project coverage is 85.86%. Comparing base (2f8846b) to head (75d2af0).

Files Patch % Lines
src/items.rs 87.50% 5 Missing :warning:
src/ops/stash.rs 97.56% 3 Missing :warning:
src/ops/show.rs 0.00% 1 Missing :warning:

:exclamation: Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## master #73 +/- ## ========================================== + Coverage 84.01% 85.86% +1.84% ========================================== Files 36 37 +1 Lines 2802 3232 +430 ========================================== + Hits 2354 2775 +421 - Misses 448 457 +9 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

altsem commented 4 months ago

@golden-expiriensu awesome :)

Tested it out quickly, there's an issue with StashWorktree though. I had a pre-commit hook causing the commit to fail, and rest to mess up my state.

I saw there's this option --keep-index:

git stash push --keep-index --include-untracked

~Does this solve it all?~ Right, --keep-index includes the index in the stash actually..

golden-expiriensu commented 4 months ago

Oooh indeed, I completely forgot about hooks. I will try to find workarounds for that

altsem commented 4 months ago

Another note @golden-expiriensu. Perhaps it is possible to do the commit-dance with the stash instead?

It'd be more robust if the reset was not relative. Could do something like:

let previous_commit_hash = *get the head*?;
let result = *do things*;
git reset --soft *previous_commit_hash*?;
result? // Bubble the result afterwards, just in case something fails
golden-expiriensu commented 4 months ago

@altsem of course we can! I don' t know why I decided to use commits instead of stashes in the first place

golden-expiriensu commented 4 months ago

@altsem done, it now uses stash as a temporary storage of index when stashing working tree, PTAL

altsem commented 4 months ago

I read the code and had another go at testing it. Pretty happy with the result! Found some interesting differences between cli git and magit. It seems stashing things with magit will "remember" which things are staged and not.

Gj! I'll merge this! :rocket: