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

[RFC PATCH 1/8] git gui: add a "compose review email" checkbox to push dialog

From
Heiko Voigt <hvoigt@hvoigt.net>
Date
Sep 21, 2009, 13:06 UTC
Message-ID
<f52bb968bf977dbbed78ce48856cd41d0add708f.1253481338.git.hvoigt@hvoigt.net>
In-Reply-To
<cover.1253481338.git.hvoigt@hvoigt.net>

This is useful when working with a central server. If a developer wants to send his changes to a reviewer we can help him fill out the necessary information about the branch he has pushed and launch his default email composer.

Composition of such an email is currently only allowed for pushing one
branch because the subject line size is limited.
---
 git-gui/git-gui.sh        |    2 +
 git-gui/lib/option.tcl    |    2 +
 git-gui/lib/transport.tcl |   75 +++++++++++++++++++++++++++++++++++++++++++-
 3 files changed, 77 insertions(+), 2 deletions(-)
diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index 3c0ce26..dfc1652 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -737,6 +737,8 @@ set default_config(gui.matchtrackingbranch) false
 set default_config(gui.pruneduringfetch) false
 set default_config(gui.trustmtime) false
 set default_config(gui.fastcopyblame) false
+set default_config(gui.emailafterpush) false
+set default_config(gui.upstreambranch) {master}
 set default_config(gui.copyblamethreshold) 40
 set default_config(gui.blamehistoryctx) 7
 set default_config(gui.diffcontext) 5
diff --git a/git-gui/lib/option.tcl b/git-gui/lib/option.tcl
index 1d55b49..55ecfe6 100644
--- a/git-gui/lib/option.tcl
+++ b/git-gui/lib/option.tcl
@@ -147,6 +147,8 @@ proc do_options {} {
 		{b gui.pruneduringfetch {mc "Prune Tracking Branches During Fetch"}}
 		{b gui.matchtrackingbranch {mc "Match Tracking Branches"}}
 		{b gui.fastcopyblame {mc "Blame Copy Only On Changed Files"}}
+		{b gui.emailafterpush {mc "Open Email Composer after Push of Feature Branch"}}
+		{t gui.upstreambranch {mc "Upstream branch"}}
 		{i-20..200 gui.copyblamethreshold {mc "Minimum Letters To Blame Copy On"}}
 		{i-0..300 gui.blamehistoryctx {mc "Blame History Context Radius (days)"}}
 		{i-1..99 gui.diffcontext {mc "Number of Diff Context Lines"}}
diff --git a/git-gui/lib/transport.tcl b/git-gui/lib/transport.tcl
index b18d9c7..77a2f46 100644
--- a/git-gui/lib/transport.tcl
+++ b/git-gui/lib/transport.tcl
@@ -30,10 +30,63 @@ proc push_to {remote} {
 	console::exec $w $cmd
 }
 
+proc compose_email {to subject} {
+	set mail_link mailto:
+	append mail_link $to "?subject=" $subject
+	start_browser $mail_link
+}
+
+proc after_push_anywhere_action {cons ok} {
+	global push_email r_url branches
+
+	console::done $cons $ok
+
+	if {$ok} {
+		if {$push_email} {
+			set rconfig_var "remote.$r_url.url"
+			set remote_url [exec git config $rconfig_var]
+			set remote_short_name [lindex [split $remote_url / ] end ]
+			set remote_short_name [lindex [split $remote_short_name . ] 0 ]
+			# TODO: create a configuration variable for the
+			# subject
+			set email_subject "Review%20request:%20$remote_short_name:$branches"
+			compose_email {} $email_subject
+		}
+	}
+}
+
+proc do_push_on_change_branch {w} {
+	global upstream_branch
+
+	$w.options.email select
+
+	set cnt 0
+	set b {}
+	foreach i [$w.source.l curselection] {
+		set b [$w.source.l get $i]
+		incr cnt
+	}
+
+	if {$cnt != 1} {
+		$w.options.email deselect
+		$w.options.email configure -state disabled
+		return
+	}
+
+	$w.options.email configure -state normal
+
+	if { $b eq $upstream_branch } {
+		if {[is_config_true gui.emailafterpush]} {
+			$w.options.email deselect
+		}
+	}
+}
+
 proc start_push_anywhere_action {w} {
 	global push_urltype push_remote push_url push_thin push_tags
 	global push_force
 	global repo_config
+	global r_url branches
 
 	set is_mirror 0
 	set r_url {}
@@ -64,9 +117,11 @@ proc start_push_anywhere_action {w} {
 			[mc "Mirroring to %s" $r_url]]
 	} else {
 		set cnt 0
+		set branches {}
 		foreach i [$w.source.l curselection] {
 			set b [$w.source.l get $i]
 			lappend cmd "refs/heads/$b:refs/heads/$b"
+			lappend branches $b
 			incr cnt
 		}
 		if {$cnt == 0} {
@@ -81,7 +136,7 @@ proc start_push_anywhere_action {w} {
 			[mc "push %s" $r_url] \
 			[mc "Pushing %s %s to %s" $cnt $unit $r_url]]
 	}
-	console::exec $cons $cmd
+	console::exec $cons $cmd "after_push_anywhere_action $cons"
 	destroy $w
 }
 
@@ -91,7 +146,8 @@ trace add variable push_remote write \
 proc do_push_anywhere {} {
 	global all_remotes current_branch
 	global push_urltype push_remote push_url push_thin push_tags
-	global push_force
+	global push_force push_email upstream_branch
+	global repo_config
 
 	set w .push_setup
 	toplevel $w
@@ -117,6 +173,9 @@ proc do_push_anywhere {} {
 		-width 70 \
 		-selectmode extended \
 		-yscrollcommand [list $w.source.sby set]
+	if {[is_config_true gui.emailafterpush]} {
+		bind $w.source.l <ButtonRelease-1> [list do_push_on_change_branch $w]
+	}
 	foreach h [load_all_heads] {
 		$w.source.l insert end $h
 		if {$h eq $current_branch} {
@@ -179,6 +238,11 @@ proc do_push_anywhere {} {
 		-text [mc "Include tags"] \
 		-variable push_tags
 	grid $w.options.tags -columnspan 2 -sticky w
+	checkbutton $w.options.email \
+		-text [mc "Compose email with review request"] \
+		-variable push_email
+	grid $w.options.email -columnspan 2 -sticky w
+	$w.options.email deselect
 	grid columnconfigure $w.options 1 -weight 1
 	pack $w.options -anchor nw -fill x -pady 5 -padx 5
 
@@ -186,6 +250,13 @@ proc do_push_anywhere {} {
 	set push_force 0
 	set push_thin 0
 	set push_tags 0
+	set push_email 0
+
+	set upstream_branch $repo_config(gui.upstreambranch)
+
+	if {[is_config_true gui.emailafterpush]} {
+		do_push_on_change_branch $w
+	}
 
 	bind $w <Visibility> "grab $w; focus $w.buttons.create"
 	bind $w <Key-Escape> "destroy $w"
-- 
1.6.5.rc1.12.gc72fe
Previous: Heiko VoigtNext: Heiko Voigt
Message 2 of 9 in “Extend git gui for better "centralized" workflow integration”
  1. 0/8 Extend git gui for better "centralized" workflow integrationHeiko Voigt, Sep 21, 2009
  2. 1/8 git gui: add a "compose review email" checkbox to push dialogHeiko Voigt, Sep 21, 2009
  3. 2/8 git gui: teach delete dialog to open with a default remoteHeiko Voigt, Sep 21, 2009
  4. 3/8 git gui: add checkbox to launch remote branch delete after pushHeiko Voigt, Sep 21, 2009
  5. 4/8 git gui: teach fetch operation to close dialog on successful completionHeiko Voigt, Sep 21, 2009
  6. 5/8 git gui: do fetch from a default remote on startupHeiko Voigt, Sep 21, 2009
  7. 6/8 git gui: add "review topic" menuitem which supports feature branch workflowHeiko Voigt, Sep 21, 2009
  8. 7/8 Add documentation for git gui variables for email and delete after pushHeiko Voigt, Sep 21, 2009
  9. 8/8 git gui: make gc hint and fetch on startup sequentialHeiko Voigt, Sep 21, 2009

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.