hack-is-art hack-is-art - 1 year ago 63
Git Question

How to output file name inside system(git log) command in ruby script?

The problem I encounter is that I don't manage to put the name of the file inside the below screen output inside git log using pretty format flag.

An extract of my code is the following:

filename = File.basename file
system('git log --pretty=format:"%cd: (here I want the filename)"')

presented as sample.c for example.

I tried
but is interpreted as a string from the compiler and the result is the same as the input.

Thank you in advance.

Answer Source

It is interpreting it as a string because single quotes do now allow string interpolation.

system('git log --pretty=format:"%cd: (here I want the filename)"')

You can change this to use double quotes so you can take advantage of interpolation and escaping.

system("git log --pretty=format:\"%cd: #{filename}\"")


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download