0

I am iterating over a git repo, or sub repos recursively and I want to output (along with other details) the revision id of the latest commit (aka most recent) of when a file was modified.

My problem is that the revision id and date stay the same all the time, and I can't find my bug! Can you please help me?

A part of my code:

Dir.glob(Dir.pwd << "/**/*").each do |file|

  filename = "#{File.basename file}"

  output = `git log -1 -r -n 1 --abbrev=5 --`pretty=format:\"%cd [%h]: #{filename}\"

  # Splits the string into different lines.
  gitLogArray = output.split("\n")

  # Outputs the content of the array.
  gitLogArray.each { |singleFile| file }
  puts gitLogArray
  end
end

As a result, I am getting:

2016-10-12T20:21:47+01:00 [6a2b6]: simple.sh
2016-10-12T20:21:47+01:00 [6a2b6]: writeexit.o 
2016-10-12T20:21:47+01:00 [6a2b6]: writeexit.s
Scott Bartell
  • 2,801
  • 3
  • 24
  • 36
hack-is-art
  • 325
  • 5
  • 20
  • Possible duplicate: http://stackoverflow.com/questions/4784575/how-do-i-find-the-most-recent-git-commit-that-modified-a-file – Briana Swift Oct 12 '16 at 21:13
  • The question you attached the link to helped me achieved that but my big problem remains on how to check individual files if are checked into git. I achieve that with directories using system('git rev-parse') – hack-is-art Oct 12 '16 at 21:54
  • Add `-- #{filename}` at the end of `git log`. – ElpieKay Oct 13 '16 at 01:00
  • It looks like you have a syntax error, you have a line `gitLogArray.each { |singleFile| file}` which does nothing, followed by `puts gitLogArray` and then a random `end`. – Scott Bartell Oct 13 '16 at 05:23
  • @ElpieKay thank you so much! – hack-is-art Oct 13 '16 at 06:31

0 Answers0