Obter todos os patches ativos do gerrit

Este script ajuda a evitar a mudança para o navegador para buscar novos patchsets do gerrit:

https://gist.github.com/3293907

#!/usr/bin/env tclsh
# GistID: 3293907
#
# USAGE:
#
# 1. put somewhere in the PATH as git-fetch-patches
# and make it executable
# 2. ensure that repository has remote with name 'gerrit'
# 3. execute 'git fetch-patches'

package require json

set remote gerrit
set url [exec git config --get remote.$remote.url]
set parts [split $url {: /}]
set hostname [lindex $parts 3]
set port [lindex $parts 4]
set project [regsub .git$ [lindex $parts 5] {}]

file
delete -force [exec git rev-parse --git-dir]/refs/patches
set refs {}
set query "ssh -p $port $hostname gerrit query --format=JSON --current-patch-set status:open $project"
foreach {line} [exec sh -c $query] {
set change [json::json2dict "{$line}"]
if {[dict exists $change currentPatchSet]} {
lappend refs
"+[dict get $change currentPatchSet ref]:refs/patches/[dict get $change number]"
}
}
puts
"Found [llength $refs] patches. Fetching..."
exec -ignorestderr sh -c "git fetch $remote $refs"