aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-02-26 11:47:14 -0500
committerShawn O. Pearce <spearce@spearce.org>2007-02-26 11:47:14 -0500
commit51bd9d7b8cf29e0e441531fb0a671cc7093f278b (patch)
tree3c8ce648ed02475ab80c4e69d93bbda597bc2e2c
parentfd234dfdb7ee1955922ded27ed18df59259193d9 (diff)
downloadgit-51bd9d7b8cf29e0e441531fb0a671cc7093f278b.tar.gz
git-51bd9d7b8cf29e0e441531fb0a671cc7093f278b.tar.xz
git-gui: Don't create empty (same tree as parent) commits.gitgui-0.6.2
Mark Levedahl noticed that git-gui will let you create an empty normal (non-merge) commit if the file state in the index is out of whack. The case Mark was looking at was with the new autoCRLF feature in git enabled and is actually somewhat difficult to create. I found a different way to create an empty commit: turn on the Trust File Modifications flag, touch a file, rescan, then move the file into the "Changes To Be Committed" list without looking at the file's diff. This makes git-gui think there are files staged for commit, yet the update-index call did nothing other than refresh the stat information for the affected file. In this case git-gui allowed the user to make a commit that did not actually change anything in the repository. Creating empty commits is usually a pointless operation; rarely does it record useful information. More often than not an empty commit is actually an indication that the user did not properly update their index prior to commit. We should help the user out by detecting this possible mistake and guiding them through it, rather than blindly recording it. After we get the new tree name back from write-tree we compare it to the parent commit's tree; if they are the same string and this is a normal (non-merge, non-amend) commit then something fishy is going on. The user is making an empty commit, but they most likely don't want to do that. We now pop an informational dialog and start a rescan, aborting the commit. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
-rwxr-xr-xgit-gui.sh18
1 files changed, 18 insertions, 0 deletions
diff --git a/git-gui.sh b/git-gui.sh
index 36155bb8e..743099c57 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -1267,6 +1267,24 @@ proc commit_committree {fd_wt curHEAD msg} {
return
}
+ # -- Verify this wasn't an empty change.
+ #
+ if {$commit_type eq {normal}} {
+ set old_tree [git rev-parse "$PARENT^{tree}"]
+ if {$tree_id eq $old_tree} {
+ info_popup {No changes to commit.
+
+No files were modified by this commit and it
+was not a merge commit.
+
+A rescan will be automatically started now.
+}
+ unlock_index
+ rescan {set ui_status_value {No changes to commit.}}
+ return
+ }
+ }
+
# -- Build the message.
#
set msg_p [gitdir COMMIT_EDITMSG]