thomasb
thomasb

Reputation: 6035

Append command result to git log pretty format

I have a bunch of pretty git log aliases using pretty-format, like such:

lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit

which gives me this:

* cb847da - (HEAD -> master, origin/trunk) foo (4 hours ago) <thomasb>
* 2117663 - bar (8 hours ago) <thomasb>

I'm actually using git-svn, and I have a different command to list the SVN revisions:

slg = svn log --oneline --show-commit

I want to insert the SVN revision inside my git lg output. I have found how to get the SVN revision of a commit (git svn find-rev $(git log --max-count 1 --pretty=format:%H)), but I can't find how to insert a command result inside a pretty-format, so I would get something like this for instance:

* cb847da - r1234 - (HEAD -> master, origin/trunk) foo (4 hours ago) <thomasb>
* 2117663 - r1233 - bar (8 hours ago) <thomasb>

Any idea?

Upvotes: 0

Views: 656

Answers (2)

Vampire
Vampire

Reputation: 38734

This is slow but works as you want it:

git config alias.lgs '!git log --graph --pretty=format:'\''%Cred%h%Creset - %C(bold red)-%H-%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'\'' --abbrev-commit | while IFS=- read -r prefix color revision rest; do echo "$prefix-$color$(git svn find-rev "$revision")$rest"; done'

of if you prefer to edit the config files directly:

lgs = "!git log --graph --pretty=format:'%Cred%h%Creset - %C(bold red)-%H-%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit | while IFS=- read -rprefix color revision rest; do echo \"$prefix-$color$(git svn find-rev \"$revision\")$rest\"; done"

Upvotes: 1

thomasb
thomasb

Reputation: 6035

For now I have created a Powershell alias (source) to get a message (to copy/paste in bugtracker messages) but it's pretty long and complicated for not much:

function Get-GitSvnMessage (
  $rev
) {
  if ($rev -eq $null -or $rev -eq "") {
    $rev = "HEAD"
  }

  # get svn revision
  $svn = (git svn find-rev $rev)

  # get git message
  $msg = (git show -s --format=%B $rev | ? { $_ -notmatch "^git-svn-id:" -and $_.Trim() -ne "" })

  # get changed files
  $files = (git diff-tree --no-commit-id --name-status -r $rev)

  Write-Output "SVN revision $svn"
  Write-Output $msg
  Write-Output ""
  Write-Output $files
}

Upvotes: 0

Related Questions