module GitEvolution
  class Repository
    def initialize(directory_name)
      @git_repo = Rugged::Repository.discover(File.expand_path(directory_name))
    end

    def dir
      @git_repo.workdir
    end

    def line_commits(start_line, end_line, file, since = nil)
      raw_results = raw_line_history(start_line, end_line, file, since)
      raw_results.split("\u0000").map { |raw_commit| Commit.new(raw_commit) }
    end

    def raw_line_history(start_line, end_line, file, since = nil)
      since_option = "--since '#{since}'"

      Dir.chdir(dir) do
        return `git --no-pager log -z #{since_option if since} -L#{start_line},#{end_line}:#{file} --follow #{file}`
      end
    end
  end
end

module GitEvolution
  class Repository
    def initialize(directory_name)
      @git_repo = Rugged::Repository.discover(File.expand_path(directory_name))
    end

    def dir
      @git_repo.workdir
    end

    def line_commits(start_line, end_line, file, since = nil)
      raw_results = raw_line_history(start_line, end_line, file, since)
      raw_results.split("\u0000").map { |raw_commit| Commit.new(raw_commit) }
    end

    def raw_line_history(start_line, end_line, file, since = nil)
      since_option = "--since '#{since}'"

      Dir.chdir(dir) do
        return `git --no-pager log -p -z\
        #{since_option if since}\
        #{"-L#{start_line},#{end_line}:#{file}" if start_line && end_line}\
        --follow #{file}`
      end
    end
  end
end

Fix git log for when no range was specified
Fix git log for when no range was specified

When no range was specified the following arguments were passed to git
log: `-L,:<file>`. While it was still valid for the whole file it was
restricted to the bounds of the current file's state (i.e., 1:10, which
then restricted how far back the history will go by the nature of the
`-L` argument.

This commit conditionally removes the `-L` argument if there is no
starting or ending lines specified. This allows the history to go 'all'
the way back while following the file movements.

Slight refactor to improve readability of the ever growing git command.
