17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32 
     | 
    
      # File 'lib/git_miner/git_util.rb', line 17
def update_current_ref(author_date, committer_date)
  commit_object = shell("git cat-file -p HEAD | head -n 2").chomp
  tree = shell("echo \"#{commit_object}\" | head -n 1 | cut -c 6-46").chomp
  head = shell("echo \"#{commit_object}\" | tail -n 1 | cut -c 8-48").chomp
  branch = shell("git branch | sed -n -e 's/^\\* \\(.*\\)/\\1/p'").chomp
  environment = {
    "GIT_AUTHOR_DATE" => author_date.iso8601,
    "GIT_COMMITTER_DATE" => committer_date.iso8601,
  }
  cmd = "git commit-tree #{tree} -p #{head} -F -"
  git_commit_message = shell('git log -1 --pretty=%B').chomp
  new_sha = shell(cmd, environment: environment, stdin_data: git_commit_message).chomp
  shell("git update-ref refs/heads/#{branch} #{new_sha}").chomp
end
     |