gitui icon indicating copy to clipboard operation
gitui copied to clipboard

Not able to commit with predefined (template) commit message

Open magical-heyrovsky opened this issue 1 year ago • 3 comments

Describe the bug

The recording below demonstrates the problem.

I have a commit message template in a gitconfig like this:

[commit]                                                                           
    template = ~/.config/git/custom-template

and gitui can also read it. So far everything as expected. When I try to commit something (c) it opens up the text area with my predefined commit message. But I am not able to immediately commit () because the option is greyed out. I need to remove or add a character in order to be able to commit.

To Reproduce Steps to reproduce the behavior:

  1. Try to commit a change (c).
  2. See the predefined commit message in the text area.
  3. Try to commit ().
  4. It doesn't work because the option is greyed out.

Expected behavior

  1. Try to commit a change (c).
  2. See the predefined commit message in the text area.
  3. Try to commit ().
  4. Changes are commited.

Screenshots

Screencast.webm

Context (please complete the following information):

  • OS/Distro + Version: Ubuntu 23.04
  • GitUI Version 0.24.3
  • Rust version: not installed

magical-heyrovsky avatar Oct 14 '23 20:10 magical-heyrovsky

I believe this might have been an intended behavior, with intention that git templates serve as templates.

// impl CommitComponent
fn can_commit(&self) -> bool {
	!self.is_empty() && self.is_changed()
}

fn is_changed(&self) -> bool {
	Some(self.input.get_text().trim())
		!= self.commit_template.as_ref().map(|s| s.trim())
}

Not sure whether it should stay this way or allow no changes if commit_template is not None. If latter, should be a pretty easy fix.

remique avatar Nov 28 '23 14:11 remique

Interesting, I didn't even think of this. I have multiple commit templates, some of which are used for private/automated projects where the message inside the template is not meant to be changed (something like "No commit message"). Funny thing is that I actually started to add these templates as a workaround, because gitui does not support empty commit messages.

magical-heyrovsky avatar Nov 28 '23 16:11 magical-heyrovsky

i guess its fair to commit the template unchanged. shell will allow the same i assume

extrawurst avatar Nov 28 '23 18:11 extrawurst

... shell will allow the same i assume

I wanted to tackle this issue, so I tested the behavior of the git CLI. It does not allow the commit with the template message, outputting "Aborting commit; you did not edit the message." (source)

Nevertheless, I went ahead and created a PR. If the intent is still to match the behavior of the git CLI, it can be rejected

Krismix1 avatar Feb 18 '24 17:02 Krismix1

no lets stay consistent with the shell then. @magical-heyrovsky if the CLI allows empty commit messages then feel free to open an issue to fix gitui be compatible

extrawurst avatar Feb 19 '24 09:02 extrawurst

So lets summarize:

  • git does not allow to commit with a unedited template message
  • git does does allow to commit with with an empty commit message but only when using --allow-empty

I will close this issue. I no longer believe that my initially proposed behavior would make much sense in GitUI. Shortly after I created this issue, I discovered the "reuse previous commit message" feature and have been using it ever since.

magical-heyrovsky avatar Feb 19 '24 11:02 magical-heyrovsky