-
-
Notifications
You must be signed in to change notification settings - Fork 575
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
Conversation
There was a problem hiding this 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!❤️
This does work, but it doesn't keep it's commit selection prior to the change, it just goes to the top. |
Fixed |
c6c10b3
to
d7676d4
Compare
81a8849
to
f84f6f4
Compare
Updated to master. |
superseded by #672 |
was too late, of course I meant to close #506 @WizardOhio24 for this to be reviewed it needs to be up to date |
There was a problem hiding this 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:
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 { |
There was a problem hiding this comment.
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)>, |
There was a problem hiding this comment.
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 = |
There was a problem hiding this comment.
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()?; |
There was a problem hiding this comment.
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), |
There was a problem hiding this comment.
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
/// 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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
File::create(&root.join(file_path))?.write_all(b"a")?; | ||
stage_add_file(repo_path, file_path).unwrap(); | ||
commit(repo_path, "commit1").unwrap(); |
There was a problem hiding this comment.
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<()> { |
There was a problem hiding this comment.
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
going back to draft in the meantime. change it back to review once you think its ready 👍 |
closing in favour of #1553 |
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