hack-is-art hack-is-art - 5 months ago 23
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.


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}\"")