class GitDiffLCS::LibGit
Git
Attributes
git[R]
Public Class Methods
new(git_target, dir, src, dest)
click to toggle source
initialize GitDiffLCS::LibGit
Arguments:
[String] git_target: git repository address or working directory [String] dir: temporary folder [String] src: commit or branch [String] dest: commit or branch
# File lib/git_diff_lcs/lib_git.rb, line 17 def initialize(git_target, dir, src, dest) @dir = dir @src = src @dest = dest get_git(git_target) end
Public Instance Methods
diff()
click to toggle source
# File lib/git_diff_lcs/lib_git.rb, line 24 def diff @diff ||= @git.diff(@src, @dest) end
Private Instance Methods
copy_to_tmp(commit, src_dir, dest_dir)
click to toggle source
# File lib/git_diff_lcs/lib_git.rb, line 45 def copy_to_tmp(commit, src_dir, dest_dir) @git.checkout(commit) diff.name_status.each do |filename, _| copy_with_path("#{@dir}/#{src_dir}/#{filename}", "#{@dir}/#{dest_dir}/#{filename}") end end
copy_with_path(src_file, dest_file)
click to toggle source
If there is no folder, create a new one.
# File lib/git_diff_lcs/lib_git.rb, line 38 def copy_with_path(src_file, dest_file) FileUtils.mkpath(File.dirname(dest_file)) FileUtils.cp(src_file, dest_file) rescue Errno::ENOENT nil end
get_git(git_target)
click to toggle source
Git.open or Git.clone
# File lib/git_diff_lcs/lib_git.rb, line 31 def get_git(git_target) git_clone(git_target) rescue Git::GitExecuteError git_open(git_target) end
git_clone(repo)
click to toggle source
git clone and copy to destination folder for compare
# File lib/git_diff_lcs/lib_git.rb, line 63 def git_clone(repo) @git = Git.clone(repo, GitDiffLCS::SRC_FOLDER, path: @dir) @git.checkout(@src) copy_to_tmp(@dest, GitDiffLCS::SRC_FOLDER, GitDiffLCS::DEST_FOLDER) @git.checkout(@src) end
git_open(working_dir)
click to toggle source
git open and copy to destination folder for compare
# File lib/git_diff_lcs/lib_git.rb, line 53 def git_open(working_dir) @git = Git.open(working_dir) prev_branch = @git.branch.name @git.checkout(@src) copy_to_tmp(@dest, working_dir, GitDiffLCS::DEST_FOLDER) copy_to_tmp(@src, working_dir, GitDiffLCS::SRC_FOLDER) @git.checkout(prev_branch) end