git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: Gelonida N <gelonida@gmail.com>
Cc: git@vger.kernel.org, Sitaram Chamarty <sitaramc@gmail.com>
Subject: Re: best way to fastforward all tracking branches after a fetch
Date: Sun, 11 Dec 2011 10:22:42 -0800 (PST)	[thread overview]
Message-ID: <m3ehwbge8f.fsf@localhost.localdomain> (raw)
In-Reply-To: <jc2l2a$som$1@dough.gmane.org>

Don't remove people from Cc, please.

Gelonida N <gelonida@gmail.com> writes:
> On 12/11/2011 03:22 AM, Sitaram Chamarty wrote:
> > On Sat, Dec 10, 2011 at 01:26:32PM +0100, Gelonida N wrote:

> > So what you want would boil down to this script (untested):
> > 
> >     #!/bin/bash
> >     git status --porcelain -uno | grep . && {echo dirty tree, exiting...; exit 1; }
> > 
> >     for b in `git for-each-ref '--format=%(refname:short)' refs/heads`
> >     do
> >         git checkout $b
> >         git merge --ff-only @{u}
> >     done
> 
> Is there no way to distinguish tracking branches from other branches?
> without checking them out?
> 
> In order to save time I'd like to avoid checking out local branches.

You can use 'upstream' field name in git-for-each-ref invocation,
for example

  git for-each-ref '--format=%(refname:short) %(upstream:short)' refs/heads |
  	grep -e ' [^ ]' |
  	sed  -e 's/ .*$//
 
This could probably be done using only sed -- grep is not necessary.

> Ideally I would even like to avoid checking out branches, which don't
> need to be forwarded.
 
You can use git-update-ref plumbing, but you would have to do the
check if it does fast-forward yourself, and provide reflog message
yourself too.
 
Something like

  git for-each-ref '--format=%(refname) %(upstream)' |
  while read refname upstream
  do
  	# there is upstream
  	test -n "$upstream" || break
  	# and if fast-forwards
  	test $(git merge-base $refname $upstream) = $(git rev-parse $refname) || break
  	git update-ref -m "$message" $refname $upstream
  done

> I also had to remember on which branch I was in order to avoid, that I
> am at a random branch after running the script.
> 
> I could imagine something like my snippet below , though I guess,
> there's something more elegant.
> 
> git stash
> mybranch=`git branch | sed -n 's/\* *//p'`
> # do_script . . .
> git checkout $mybranch
> git stash apply

Don't use git-branch in scripting.  See __git_ps1 function in
contrib/completion/git-completion.bash how it can be done:

  b="$(git symbolic-ref HEAD 2>/dev/null)" ||
  b="$(git rev-parse --verify HEAD)"

Nb. the second part is here only if there is possibility that you are
on detached HEAD (unnamed branch).

HTH (hope that helps)
-- 
Jakub Narębski

  reply	other threads:[~2011-12-11 18:22 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-10 12:26 best way to fastforward all tracking branches after a fetch Gelonida N
2011-12-11  2:22 ` Sitaram Chamarty
2011-12-11 16:17   ` Gelonida N
2011-12-11 18:22     ` Jakub Narebski [this message]
2011-12-11 18:56       ` Sitaram Chamarty
2011-12-11 19:00       ` Andreas Schwab
2011-12-11 19:53         ` Jakub Narebski
2011-12-11 19:58       ` Gelonida N
2011-12-11 20:30         ` Andreas Schwab
2011-12-11 16:27 ` Martin Langhoff
2011-12-11 20:14 ` Stefan Haller
2011-12-11 20:27   ` Gelonida N
2011-12-11 20:43     ` Martin Langhoff
2011-12-11 22:22   ` Hallvard B Furuseth
2011-12-12  7:33     ` Stefan Haller
2011-12-12  8:25       ` Jeff King
2011-12-12  9:19         ` Stefan Haller
2011-12-13 19:05       ` Hallvard Breien Furuseth
2011-12-12  8:28     ` Junio C Hamano
2011-12-12  8:09 ` Junio C Hamano
2011-12-12 10:13   ` Gelonida N
2011-12-12 10:24     ` Gelonida N
2011-12-17 10:10 ` Sitaram Chamarty
2011-12-17 10:11   ` Sitaram Chamarty
2011-12-19  6:31     ` Nazri Ramliy
2012-01-18  1:50       ` Sitaram Chamarty
2012-01-18  1:48   ` Sitaram Chamarty

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=m3ehwbge8f.fsf@localhost.localdomain \
    --to=jnareb@gmail.com \
    --cc=gelonida@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=sitaramc@gmail.com \
    /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).