git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Joshua Williams <joshua.williams@qlogic.com>
To: "Shawn O. Pearce" <spearce@spearce.org>
Cc: git@vger.kernel.org,
	Jay Blakeborough <jay.blakeborough@qlogic.com>,
	Bill Lohse <bill.lohse@qlogic.com>
Subject: [GIT-GUI PATCH] call prepare-commit-msg hook
Date: Tue, 16 Sep 2008 16:12:36 -0500	[thread overview]
Message-ID: <48D02144.8030409@qlogic.com> (raw)

This patch adds support to git-gui for calling out to the
prepare-commit-msg hook.

Signed-off-by: Joshua Williams <joshua.williams@qlogic.com>
---
  git-gui/git-gui.sh |   66 
++++++++++++++++++++++++++++++++++++++++++++++++++-
  1 files changed, 64 insertions(+), 2 deletions(-)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 10d8a44..1e269de 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -1131,8 +1131,7 @@ proc rescan {after {honor_trustmtime 1}} {
  		|| [string trim [$ui_comm get 0.0 end]] eq {})} {
  		if {[string match amend* $commit_type]} {
  		} elseif {[load_message GITGUI_MSG]} {
-		} elseif {[load_message MERGE_MSG]} {
-		} elseif {[load_message SQUASH_MSG]} {
+		} elseif {[run_prepare_commit_msg_hook]} {
  		}
  		$ui_comm edit reset
  		$ui_comm edit modified false
@@ -1230,6 +1229,69 @@ proc load_message {file} {
  	return 0
  }

+proc run_prepare_commit_msg_hook {} {
+	global pch_error
+
+	# prepare-commit-msg requires PREPARE_COMMIT_MSG exist.  From git-gui
+	# it will be .git/MERGE_MSG (merge), .git/SQUASH_MSG (squash), or an
+	# empty file but existant file.
+
+	set fd_pcm [open [gitdir PREPARE_COMMIT_MSG] a]
+
+	if {[file isfile [gitdir MERGE_MSG]]} {
+		set pcm_source "merge"
+		set fd_mm [open [gitdir MERGE_MSG] r]
+		puts -nonewline $fd_pcm [read $fd_mm]
+		close $fd_mm
+	} elseif {[file isfile [gitdir SQUASH_MSG]]} {
+		set pcm_source "squash"
+		set fd_sm [open [gitdir SQUASH_MSG] r]
+		puts -nonewline $fd_pcm [read $fd_sm]
+		close $fd_sm
+	} else {
+		set pcm_source ""
+	}
+
+	close $fd_pcm
+
+	set fd_ph [githook_read prepare-commit-msg \
+			[gitdir PREPARE_COMMIT_MSG] $pcm_source]
+	if {$fd_ph eq {}} {
+		catch {file delete [gitdir PREPARE_COMMIT_MSG]}
+		return 0;
+	}
+
+	ui_status [mc "Calling prepare-commit-msg hook..."]
+	set pch_error {}
+
+	fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
+	fileevent $fd_ph readable \
+		[list prepare_commit_msg_hook_wait $fd_ph]
+
+	return 1;
+}
+
+proc prepare_commit_msg_hook_wait {fd_ph} {
+	global pch_error
+
+	append pch_error [read $fd_ph]
+	fconfigure $fd_ph -blocking 1
+	if {[eof $fd_ph]} {
+		if {[catch {close $fd_ph}]} {
+			ui_status [mc "Commit declined by prepare-commit-msg hook."]
+			hook_failed_popup prepare-commit-msg $pch_error
+			exit 1
+		} else {
+			load_message PREPARE_COMMIT_MSG
+		}
+		set pch_error {}
+		catch {file delete [gitdir PREPARE_COMMIT_MSG]}
+		return
+        }
+	fconfigure $fd_ph -blocking 0
+	catch {file delete [gitdir PREPARE_COMMIT_MSG]}
+}
+
  proc read_diff_index {fd after} {
  	global buf_rdi

             reply	other threads:[~2008-09-16 21:13 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-16 21:12 Joshua Williams [this message]
2008-09-16 22:05 ` [GIT-GUI PATCH] call prepare-commit-msg hook Joshua Williams
2008-09-24 17:04   ` Shawn O. Pearce
2008-09-24 19:11     ` Joshua Williams
2008-09-24 19:46       ` Shawn O. Pearce

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=48D02144.8030409@qlogic.com \
    --to=joshua.williams@qlogic.com \
    --cc=bill.lohse@qlogic.com \
    --cc=git@vger.kernel.org \
    --cc=jay.blakeborough@qlogic.com \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).