[PATCH] git-gui: Modify push dialog to support Gerrit review

Subsystems: library code, the rest

STALE3739d

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] git-gui: Modify push dialog to support Gerrit review

From: Joergen Edelbo <hidden>
Date: 2016-06-15 22:58:39

Problem: It is not possible to push for Gerrit review as you will
always try to push to "refs/heads/..." on the remote.

Changes done:

Add an option to select "Gerrit review" and a corresponding entry
for a branch name. If this option is selected, push the changes to
"refs/for/<gerrit-branch>/<local branch>". In this way the local branch
names will be used as topic branches on Gerrit.
---
Hi all,

This is a second attempt to support Gerrit review. It is fully backwards
compatible as the Gerrit option is an addition only. It is also better
than the first approach as it supports pushing more local branches to
Gerrit - each having their own topic branch there.

Further improvement could be to make the Gerrit branch specification a
drop down list, but I would like to have this first simple approach 
evaluated first.

BR Joergen

 lib/transport.tcl |   30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/lib/transport.tcl b/lib/transport.tcl
index e5d211e..adf2bbb 100644
--- a/lib/transport.tcl
+++ b/lib/transport.tcl
@@ -61,6 +61,7 @@ proc push_to {remote} {
 
 proc start_push_anywhere_action {w} {
 	global push_urltype push_remote push_url push_thin push_tags
+	global gerrit_review gerrit_branch
 	global push_force
 	global repo_config
 
@@ -95,7 +96,15 @@ proc start_push_anywhere_action {w} {
 		set cnt 0
 		foreach i [$w.source.l curselection] {
 			set b [$w.source.l get $i]
-			lappend cmd "refs/heads/$b:refs/heads/$b"
+			if {$gerrit_review && $gerrit_branch ne {}} {
+				if {$gerrit_branch eq $b} {
+					lappend cmd "refs/heads/$b:refs/for/$b"
+				} else {
+					lappend cmd "refs/heads/$b:refs/for/$gerrit_branch/$b"
+				}
+			} else {
+				lappend cmd "refs/heads/$b:refs/heads/$b"
+			}
 			incr cnt
 		}
 		if {$cnt == 0} {
@@ -120,6 +129,7 @@ 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 gerrit_review gerrit_branch
 	global push_force use_ttk NS
 
 	set w .push_setup
@@ -215,6 +225,24 @@ proc do_push_anywhere {} {
 		-text [mc "Include tags"] \
 		-variable push_tags
 	grid $w.options.tags -columnspan 2 -sticky w
+	${NS}::checkbutton $w.options.gerrit \
+		-text [mc "Gerrit review.  Branch: "] \
+		-variable gerrit_review
+	${NS}::entry $w.options.gerrit_br \
+		-width 50 \
+		-textvariable gerrit_branch \
+		-validate key \
+		-validatecommand {
+			if {%d == 1 && [regexp {\s} %S]} {return 0}
+			if {%d == 1 && [string length %S] > 0} {
+				set gerrit_review 1
+			}
+			if {[string length %P] == 0} {
+				set gerrit_review 0
+			}
+			return 1
+		}
+	grid $w.options.gerrit $w.options.gerrit_br -sticky we -padx {0 5}
 	grid columnconfigure $w.options 1 -weight 1
 	pack $w.options -anchor nw -fill x -pady 5 -padx 5
 
-- 
1.7.9.5

Re: [PATCH] git-gui: Modify push dialog to support Gerrit review

From: Phil Hord <hidden>
Date: 2016-06-15 22:58:39

On Fri, Sep 6, 2013 at 6:30 AM, Joergen Edelbo [off-list ref] wrote:
Problem: It is not possible to push for Gerrit review as you will
always try to push to "refs/heads/..." on the remote.

Changes done:

Add an option to select "Gerrit review" and a corresponding entry
for a branch name. If this option is selected, push the changes to
"refs/for/<gerrit-branch>/<local branch>". In this way the local branch
names will be used as topic branches on Gerrit.

In my gerrit repos, I have this configuration

  $  git config remote.origin.push HEAD:refs/for/master

And so I can simply 'git push' and git does what I mean.

My main complaint with git-gui's push is that it ignores my
configuration. Can you teach git-gui to honor this setting, instead?

I would like for this remote."name".push option to be smarter and figure
out which $branch I mean when I am not on master, but that is a different
discussion. Having said that, I see that your change to git-gui attempts to
make that automatic.  Kudos for that, but I don't think this will work for
me as I am often on a detached branch and so "refs/heads/$b" is meaningless.

Can you think of a sane way to separate the "from" and the "to" branches in
the GUI?  I mean, I would like to push "HEAD" and I would like it to
go to "refs/for/frotz-2.0".

Phil

Re: [PATCH] git-gui: Modify push dialog to support Gerrit review

From: Jørgen Edelbo <hidden>
Date: 2016-06-15 22:58:40

On 06-09-2013 23:49, Phil Hord wrote:
Can you think of a sane way to separate the "from" and the "to" branches in
the GUI?  I mean, I would like to push "HEAD" and I would like it to
go to "refs/for/frotz-2.0".
My first attemt at this change was to do do exactly that: always push 
HEAD, and being able to specify the destination branches. If it was a 
Gerrit review server, it would replace refs/heads/... with refs/for/...

However, it is now clear, that we have to support specifying the 
branches to push.

My next thought was: could we add an entry to the list of branches to 
push, meaning "omit the branch specs in the command". Then it should 
just perform a "git push <remote>". What was then pushed would depend
on the push configuration for the remote. In the Gerrit case we could 
then have:
   push = HEAD:refs/for/master, or whatever.

The drawback of this solution is that the UI is not so intuitive and it 
would not support the case where you would want to push your branch 
frotz to refs/for/master/frotz, which is the way you specify a topic in 
Gerrit. The current solution supports this.

What remains to support is the case where you work on a detached HEAD. 
Most of it should be straight forward. The gui knows we are in detached 
state, so in this case, a "HEAD" entry could be added to the list of 
branches. The question is just: to which branch to push to in the non 
Gerrit case? Perhaps the ref specs could just be left out in this case.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help