git-gui: warn when trying to commit on a detached head

The commandline is already warning when checking out a detached head. Since the only thing thats potentially dangerous is to create commits on a detached head lets warn in case the user is about to do that. Signed-off-by: Heiko Voigt <hvoigt@hvoigt.net> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>

Heiko Voigt committed Feb 15, 2011 at 19:43 UTC e34789cc8ba45d5491c007274b41849d3b0b84b7
2 files changed +16
git-gui.sh
+1
@@ -854,6 +854,7 @@ set default_config(gui.fontdiff) [font configure font_diff]
854 # TODO: this option should be added to the git-config documentation
855 set default_config(gui.maxfilesdisplayed) 5000
856 set default_config(gui.usettk) 1
857 +set default_config(gui.warndetachedcommit) 1
858 set font_descs {
859 {fontui font_ui {mc "Main Font"}}
860 {fontdiff font_diff {mc "Diff/Console Font"}}
lib/commit.tcl
+15
@@ -260,8 +260,23 @@ proc commit_prehook_wait {fd_ph curHEAD msg_p} {
260 }
261
262 proc commit_commitmsg {curHEAD msg_p} {
263 + global is_detached repo_config
264 global pch_error
265
266 + if {$is_detached && $repo_config(gui.warndetachedcommit)} {
267 + set msg [mc "You are about to commit on a detached head.\
268 +This is a potentially dangerous thing to do because if you switch\
269 +to another branch you will loose your changes and it can be difficult\
270 +to retrieve them later from the reflog. You should probably cancel this\
271 +commit and create a new branch to continue.\n\
272 +\n\
273 +Do you really want to proceed with your Commit?"]
274 + if {[ask_popup $msg] ne yes} {
275 + unlock_index
276 + return
277 + }
278 + }
279 +
280 # -- Run the commit-msg hook.
281 #
282 set fd_ph [githook_read commit-msg $msg_p]