git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] git-gui: give more advice when detaching HEAD

From
Heiko Voigt <hvoigt@hvoigt.net>
Date
Feb 13, 2011, 12:31 UTC
Message-ID
<20110213123151.GA31375@book.hvoigt.net>
In-Reply-To
<20110212070538.GA2459@sigill.intra.peff.net>
Hi,
On Sat, Feb 12, 2011 at 02:05:38AM -0500, Jeff King wrote:
Show 5 quoted lines
>   1. Give some indication or warning during commit that you're in a
>      detached state. The CLI template says "You are not on any branch"
>      when editing the commit message, and mentions "detached HEAD" as
>      the branch in the post-commit summary. As far as I can tell,
>      git-gui says nothing at all.
How about something like this:
---8<----
From 8e2b61cd5e8d85f43ed6f00935a757f0dfa56b3b Mon Sep 17 00:00:00 2001
From: Heiko Voigt <hvoigt@hvoigt.net>
Date: Sun, 13 Feb 2011 13:25:04 +0100
Subject: [PATCH] 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>
---
The wording of the warning might need some cleanup and documentation of
the configuration variable is still missing but if you like it I will
add it.
 git-gui/git-gui.sh     |    1 +
 git-gui/lib/commit.tcl |   14 ++++++++++++++
 2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index d3acf0d..5314a3f 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -831,6 +831,7 @@ set default_config(gui.fontdiff) [font configure font_diff]
 # TODO: this option should be added to the git-config documentation
 set default_config(gui.maxfilesdisplayed) 5000
 set default_config(gui.usettk) 1
+set default_config(gui.warndetachedcommit) 1
 set font_descs {
 	{fontui   font_ui   {mc "Main Font"}}
 	{fontdiff font_diff {mc "Diff/Console Font"}}
diff --git a/git-gui/lib/commit.tcl b/git-gui/lib/commit.tcl
index 7f459cd..9bef8ee 100644
--- a/git-gui/lib/commit.tcl
+++ b/git-gui/lib/commit.tcl
@@ -259,8 +259,22 @@ proc commit_prehook_wait {fd_ph curHEAD msg_p} {
 }
 
 proc commit_commitmsg {curHEAD msg_p} {
+	global is_detached repo_config
 	global pch_error
 
+	if {$is_detached && $repo_config(gui.warndetachedcommit)} {
+		set msg [mc "You are about to commit on a detached head.
+This is a potentially dangerous thing to do because
+if you switch to another branch you will loose your
+changes and it can be difficult to get them back.
+
+Do you really want to proceed?"]
+		if {[ask_popup $msg] ne yes} {
+			unlock_index
+			return
+		}
+	}
+
 	# -- Run the commit-msg hook.
 	#
 	set fd_ph [githook_read commit-msg $msg_p]
-- 
1.7.4.rc3.4.g155c4
Previous: Junio C HamanoNext: Jeff King
Message 11 of 19 in “git-gui: give more advice when detaching HEAD”
  1. git-gui: give more advice when detaching HEADJeff King, Feb 12, 2011
  2. Junio C HamanoFeb 12, 2011
  3. Jeff KingFeb 12, 2011
  4. Junio C HamanoFeb 12, 2011
  5. Jeff KingFeb 12, 2011
  6. Junio C HamanoFeb 17, 2011
  7. Junio C HamanoFeb 12, 2011
  8. Sverre RabbelierFeb 13, 2011
  9. Johannes SixtFeb 13, 2011
  10. Junio C HamanoFeb 13, 2011
  11. Heiko VoigtFeb 13, 2011
  12. Jeff KingFeb 15, 2011
  13. Heiko VoigtFeb 15, 2011
  14. Pat ThoytsFeb 15, 2011
  15. Jeff KingFeb 16, 2011
  16. Heiko VoigtFeb 17, 2011
  17. Jeff KingFeb 16, 2011
  18. Heiko VoigtFeb 17, 2011
  19. Victor EngmarkFeb 16, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.