Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support reword in log tab & refactor external editor calls #312

Closed
wants to merge 54 commits into from

Conversation

WizardOhio24
Copy link
Contributor

No more do we have to go though an interactive rebase in which the exact commit reference must be known, where we then must choose 'reword' on the correct commit.

This PR provides the reword functionality on the log(commit list) tab, simply press 'r' on the commit, type in the new message and press enter to change it.

This does not do an interactive rebase in git2rs, rather a slightly more complex rebase operation which achieves the same thing (there is no such thing as an interactive rebase in git2rs/libgit2)
This does not work on the first commit because it has no parent.

Linked to #32

Copy link
Owner

@extrawurst extrawurst left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this!❤️

asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
src/components/reword.rs Outdated Show resolved Hide resolved
@WizardOhio24
Copy link
Contributor Author

This does work, but it doesn't keep it's commit selection prior to the change, it just goes to the top.

@WizardOhio24 WizardOhio24 changed the title WIP: Support reword in log tab Support reword in log tab Oct 10, 2020
@WizardOhio24
Copy link
Contributor Author

Fixed

asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
src/components/reword.rs Show resolved Hide resolved
@WizardOhio24 WizardOhio24 force-pushed the reword branch 2 times, most recently from c6c10b3 to d7676d4 Compare October 26, 2020 22:53
asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
asyncgit/src/sync/rebase.rs Outdated Show resolved Hide resolved
asyncgit/src/sync/rebase.rs Show resolved Hide resolved
src/app.rs Outdated Show resolved Hide resolved
src/app.rs Show resolved Hide resolved
@WizardOhio24 WizardOhio24 changed the title Support reword in log tab & refactor external editor Support reword in log tab & refactor external editor calls Feb 6, 2021
@extrawurst extrawurst force-pushed the master branch 2 times, most recently from 81a8849 to f84f6f4 Compare March 3, 2021 21:27
@WizardOhio24
Copy link
Contributor Author

Updated to master.

@extrawurst
Copy link
Owner

superseded by #672

@extrawurst extrawurst closed this May 17, 2021
@WizardOhio24
Copy link
Contributor Author

This has nothing to do with #672? This is about rewording commits in the log tab, nothing to do with searching.
Perhaps you meant to close #506? (Feel free, it has been superceded).

@extrawurst
Copy link
Owner

extrawurst commented May 18, 2021

was too late, of course I meant to close #506

@WizardOhio24 for this to be reviewed it needs to be up to date

@extrawurst extrawurst reopened this May 18, 2021
Copy link
Owner

@extrawurst extrawurst left a comment

Choose a reason for hiding this comment

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

I worked through all of this again and it cannot be merged:

Screenshot 2021-05-27 at 22 19 53

this happens right when I simply open the commit popup, go to external editor and close it again. this is currently broken.

most of the external editor stuff can be most like reverted anyway if you use the Mode in the commit popup. actually the entire reword-popup can now be handled inside CommitComponent, this would be much easier I think

/// the main app type
/// Used to determine where the user should
/// be put when the external editor is closed
pub enum EditorSource {
Copy link
Owner

Choose a reason for hiding this comment

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

should be put into the externaleditor.rs

@@ -64,10 +72,10 @@ pub struct App {
theme: SharedTheme,
key_config: SharedKeyConfig,
input: Input,
external_editor: Option<(Option<String>, EditorSource)>,
Copy link
Owner

Choose a reason for hiding this comment

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

this should be a struct instead of tuple to help express the intent of this. something like OpenEditorState

@@ -528,14 +553,23 @@ impl App {
.insert(NeedsUpdate::ALL | NeedsUpdate::COMMANDS);
}
InternalEvent::Update(u) => flags.insert(u),
InternalEvent::OpenCommit => self.commit.show()?,
InternalEvent::OpenCommit => {
self.external_editor =
Copy link
Owner

Choose a reason for hiding this comment

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

I am not sure why we have to do this now?
doesn't this trigger show_editor now every time we just open the regular commit popup?

@@ -187,3 +193,34 @@ impl Component for ExternalEditorComponent {
Ok(())
}
}

pub fn show_editor(with_text: Option<&String>) -> Result<String> {
let temp_file = NamedTempFile::new()?;
Copy link
Owner

Choose a reason for hiding this comment

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

by now we intentionally use a specific filename to edit commit msgs in so that vim knows how to highlight it, we should keep doing this (see COMMIT_EDITMSG)

@@ -69,7 +72,7 @@ pub enum InternalEvent {
///
SelectBranch,
///
OpenExternalEditor(Option<String>),
OpenExternalEditor(Option<String>, EditorSource),
Copy link
Owner

Choose a reason for hiding this comment

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

use a struct like mentioned above

Comment on lines +45 to +47
/// While this function is most commonly associated with doing a
/// reword opperation in an interactive rebase, that is not how it
/// is implemented in git2rs
Copy link
Owner

Choose a reason for hiding this comment

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

what does that mean? what does it imply?

let sig = signature_allow_undefined_name(&repo)?;

let parent_commit_oid = if let Ok(parent_commit) =
repo.find_commit(commit_oid)?.parent(0)
Copy link
Owner

Choose a reason for hiding this comment

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

what if the commit is a merge commit with multiple parents? please add a unittest for that case

};

// If we are on a branch
if let Ok(Some(branch)) = get_cur_branch(&repo) {
Copy link
Owner

Choose a reason for hiding this comment

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

lets map this into the Err we want and ? it here to early out if not on a branch, this makes the rest indent one less and easier to read

Comment on lines +136 to +138
File::create(&root.join(file_path))?.write_all(b"a")?;
stage_add_file(repo_path, file_path).unwrap();
commit(repo_path, "commit1").unwrap();
Copy link
Owner

Choose a reason for hiding this comment

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

the new write_commit_file makes creating/writing/committing test files more convenient/easier to read now

use std::{fs::File, io::Write, path::Path};

#[test]
fn test_reword() -> Result<()> {
Copy link
Owner

Choose a reason for hiding this comment

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

we currently only test the happy path, what if the rename does not go through and the rebase has to be rolled back. we need a test for that aswell

@extrawurst
Copy link
Owner

going back to draft in the meantime. change it back to review once you think its ready 👍

@extrawurst extrawurst marked this pull request as draft May 27, 2021 20:42
@extrawurst extrawurst mentioned this pull request Feb 18, 2023
@extrawurst
Copy link
Owner

closing in favour of #1553

@extrawurst extrawurst closed this Feb 18, 2023
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