0

I'm looking for a list containing:

  • Date
  • Branch Name

For all branches coming off 'develop' with 'release' in the name.

similar to

2014-03-11 10:52:04 +0100 9 months ago  release-1.0
2014-03-28 10:33:23 +0100 8 months ago  release-2.0
2014-04-02 10:40:59 +0200 8 months ago  release-3.0
2014-04-18 17:01:54 +0200 8 months ago  release-3.0.1
2014-05-05 15:25:31 +0200 7 months ago  release-3.0.2

I've found several answers which have really helped me, and now I'm stumbling on syntax. Useful information was:

So far I have the following as an alias in bash

for k in `git branch|sed s/^..//`;
    do  echo -e `git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr %Creset" 
         <(`diff -u <(git rev-list --first-parent "$k") <(git rev-list --first-parent develop)|sed -ne '"'"'s/^ //p'"'"'|head -1`)
           --`\\t"$k";

done|sort;'

running each part of this individually works. But not altogether.

So these work:

  • git branch|sed s/^..//
  • git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr %Creset" release-3.0
  • diff -u <(git rev-list --first-parent release-3.0) <(git rev-list --first-parent develop)

But not when I put them together.

Help?

Community
  • 1
  • 1
TheMightyLlama
  • 1,243
  • 1
  • 19
  • 51

1 Answers1

2

You cannot nest backtick commands like this:

echo `echo foo `echo bar` baz`

To nest you need to use the (all around more preferable) $() syntax.

You also don't need backticks inside a <(...)

unless you want the substitution to run the output from the ... command instead of the ... command itself.

So try something more like this:

for k in $(git branch|sed s/^..//);
    do  echo -e $(git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr %Creset" 
         <(`diff -u <(git rev-list --first-parent "$k") <(git rev-list --first-parent develop)|sed -ne '"'"'s/^ //p'"'"'|head -1`)
           --)\\t"$k";
done|sort;'

Or without the <() backticks

for k in $(git branch|sed s/^..//);
    do echo -e $(git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr %Creset" 
         <(diff -u <(git rev-list --first-parent "$k") <(git rev-list --first-parent develop)|sed -ne '"'"'s/^ //p'"'"'|head -1)
           --)\\t"$k";
done|sort;'

Additionally, I don't think you need to use echo -e here at all since you can probably just put the \t$k in the git log format string directly.

for k in $(git branch|sed s/^..//); do
    git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr %Creset"$'\t'"$k" 
         <(diff -u <(git rev-list --first-parent "$k") <(git rev-list --first-parent develop)|sed -ne '"'"'s/^ //p'"'"'|head -1)
           --;
done|sort;'

Which, assuming I did that all right, looks like it is trying to feed git log the revision to log from standard input but I don't believe git log takes input that way. So you would need to make it an argument instead.

for k in $(git branch|sed s/^..//); do
    git log -1 --pretty=format:"%Cgreen%ci %Cblue%cr %Creset"$'\t'"$k" 
         "$(diff -u <(git rev-list --first-parent "$k") <(git rev-list --first-parent develop)|sed -ne '"'"'s/^ //p'"'"'|head -1)"
         --;
done|sort;'

And you can probably get rid of that dangling -- too.

Etan Reisner
  • 77,877
  • 8
  • 106
  • 148
  • @TomFenech Honestly, I'm not sure what that is. The snippet in the OP isn't complete (it leaves off the alias prefix at very least) and the quoting issues are confusing me. I can try though. – Etan Reisner Dec 05 '14 at 17:19
  • The reason I mentioned it was that I was considering making an answer which combined usage of `$()` and a function myself but got a bit confused too! – Tom Fenech Dec 05 '14 at 17:21