Class: GitReviewer::Checker
- Inherits:
-
Object
- Object
- GitReviewer::Checker
- Defined in:
- lib/gitreviewer/utils/checker.rb
Class Method Summary collapse
- .current_git_branch ⇒ Object
-
.diff_files(source, target) ⇒ Object
分析两个分支之间修改的文件.
-
.is_file_binary?(branch, filename) ⇒ Boolean
判断一个文件是否为二进制文件.
-
.is_file_exist?(branch, filename) ⇒ Boolean
判断 指定分支,指定文件 是否存在.
-
.is_git_branch_exist?(branch) ⇒ Boolean
判断 Git 分支是否存在.
-
.is_git_repository_exist? ⇒ Boolean
判断当前是否在一个 Git 仓库中.
-
.snapshot_of_blame_file(branch, filename) ⇒ Object
分析「指定分支、指定文件」的快照信息.
Class Method Details
.current_git_branch ⇒ Object
57 58 59 60 61 |
# File 'lib/gitreviewer/utils/checker.rb', line 57 def self.current_git_branch cmd = "git symbolic-ref --short HEAD" result = `#{cmd}` return result.chomp end |
.diff_files(source, target) ⇒ Object
分析两个分支之间修改的文件
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/gitreviewer/utils/checker.rb', line 46 def self.diff_files(source, target) cmd = "git merge-base #{source} #{target}" merge_base = `#{cmd}` merge_base = merge_base.chomp cmd = "git diff --name-only #{merge_base} #{source}" result = `#{cmd}` result = result.lines.map { |line| line.chomp } return result end |
.is_file_binary?(branch, filename) ⇒ Boolean
判断一个文件是否为二进制文件
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gitreviewer/utils/checker.rb', line 25 def self.is_file_binary?(branch, filename) tmpfile = "/tmp/analyzer-tmp-file" cmd = "git show #{branch}:#{filename.chomp} > #{tmpfile}" `#{cmd}` cmd = "file --mime #{tmpfile}" result = `#{cmd}` cmd = "rm #{tmpfile}" `#{cmd}` return result.include? 'charset=binary' end |
.is_file_exist?(branch, filename) ⇒ Boolean
判断 指定分支,指定文件 是否存在
18 19 20 21 22 |
# File 'lib/gitreviewer/utils/checker.rb', line 18 def self.is_file_exist?(branch, filename) cmd = "git ls-tree -r #{branch} --name-only | grep '#{filename}' > /dev/null 2>&1" success = system(cmd) return success end |
.is_git_branch_exist?(branch) ⇒ Boolean
判断 Git 分支是否存在
11 12 13 14 15 |
# File 'lib/gitreviewer/utils/checker.rb', line 11 def self.is_git_branch_exist?(branch) cmd = "git show-ref --verify --quiet refs/heads/#{branch}" success = system(cmd) return success end |
.is_git_repository_exist? ⇒ Boolean
判断当前是否在一个 Git 仓库中
4 5 6 7 8 |
# File 'lib/gitreviewer/utils/checker.rb', line 4 def self.is_git_repository_exist? cmd = "git rev-parse --is-inside-work-tree > /dev/null 2>&1" success = system(cmd) return success end |
.snapshot_of_blame_file(branch, filename) ⇒ Object
分析「指定分支、指定文件」的快照信息
39 40 41 42 43 |
# File 'lib/gitreviewer/utils/checker.rb', line 39 def self.snapshot_of_blame_file(branch, filename) cmd = "git blame #{branch} -l -c #{filename}" result = `#{cmd}` return result end |