From b1a2359036aefa401b67943ae52f76a3a24bac53 Mon Sep 17 00:00:00 2001 From: Tom Willemse Date: Fri, 7 Jun 2013 22:34:27 +0200 Subject: [PATCH] Only show branches with changes by default Unless `show-unchanged-branches?' has been set to `#t' in the user's configuration only branches with pushable or pullable commits are shown. --- doc/gitto.texi | 7 +++++++ gitto/git.scm | 19 ++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/doc/gitto.texi b/doc/gitto.texi index 6537b7e..b109769 100644 --- a/doc/gitto.texi +++ b/doc/gitto.texi @@ -339,6 +339,13 @@ A plain list of repository names to skip when merging configurations and installing hooks. @end defopt +@defopt show-unchanged-branches? +A boolean. If @code{#t} all branches will be shown no matter their +state, if @code{#f} (the default) only those branches that either have +commits to push or commits to pull will be shown in the output of the +@samp{list} command. +@end defopt + @node Copying This Manual, Index, Configuration, Top @appendix Copying This Manual diff --git a/gitto/git.scm b/gitto/git.scm index 425e26e..83674be 100644 --- a/gitto/git.scm +++ b/gitto/git.scm @@ -22,6 +22,7 @@ #:use-module (ice-9 popen) #:use-module (ice-9 rdelim) #:use-module (oop goops) + #:use-module (srfi srfi-1) #:export ( @@ -37,6 +38,8 @@ repo-name same-repository?)) +(define show-unchanged-branches? #f) + (define-generic print) (define-generic same-repository?) @@ -136,9 +139,14 @@ sub-directory." (git-branches dir)))))) (define-method (print (branch )) - (format #t " ~a:~15t~d to push and ~d to pull. Last update: ~a~%" - (branch-name branch) (branch-pushable branch) - (branch-pullable branch) (branch-updated branch))) + (let ((pushable (branch-pushable branch)) + (pullable (branch-pullable branch))) + (if (or show-unchanged-branches? + (> (+ pushable pullable) 0)) + (format #t " ~a:~15t~d to push and ~d to pull. Last update: ~a~%" + (branch-name branch) pushable pullable + (branch-updated branch)) + #f))) (define (repo-state-description repo) "Return the state of REPO as either clean or dirty. @@ -151,8 +159,9 @@ REPO should be of type `' and the result is a string." (begin (format #t "~a: Worktree is ~a~%" (repo-name repo) (repo-state-description repo)) - (for-each print (repo-branches repo)) - (newline)) + (when (any identity (map-in-order print (repo-branches repo))) + (newline)) + #t) (format #t "~a:~15tnot found at ~s\n" (repo-name repo) (repo-location repo))))