
--- lib/git.rb | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/lib/git.rb b/lib/git.rb index a181ec9..4939c94 100644 --- a/lib/git.rb +++ b/lib/git.rb @@ -2,7 +2,7 @@ # wrap common git commands class GitCommit - def initialize(repo, commit) + def initialize(repo, commit = nil) @repo = repo @commit = commit @git_prefix = cd_repo_path @@ -28,32 +28,42 @@ class GitCommit def cd_repo_path find_repo = check_repo - return unless find_repo + message = "The repo is not found in the upstream-repo" + + raise StandardError, message unless find_repo "git -C #{find_repo}" end + def check_author_in_upstream_repos(email) + author_email = %x(#{@git_prefix} log | grep '^Author'| grep #{email}).chomp + + message = "The author's email address is not found in the upstream-repo" + + raise StandardError, message if author_email.empty? + end + def author_name - `#{@git_prefix} log -n1 --pretty=format:'%an' #{@commit}`.chomp + %x(#{git_prefix} log -n1 --pretty=format:'%an' #{@commit}).chomp end def author_email - `#{@git_prefix} log -n1 --pretty=format:'%ae' #{@commit}`.chomp + %x(#{@git_prefix} log -n1 --pretty=format:'%ae' #{@commit}).chomp end def subject - `#{@git_prefix} log -n1 --pretty=format:'%s' #{@commit}`.chomp + %x(#{@git_prefix} log -n1 --pretty=format:'%s' #{@commit}).chomp end def commit_time - `#{@git_prefix} log -n1 --pretty=format:'%ci' #{@commit}`.chomp + %x(#{@git_prefix} log -n1 --pretty=format:'%ci' #{@commit}).chomp end def url - `#{@git_prefix} remote -v`.split[1] + %x(#{@git_prefix} remote -v).split[1] end def diff - `#{@git_prefix} diff -1 #{@commit}~..#{@commit}`.chomp + %x(#{@git_prefix} diff -1 #{@commit}~..#{@commit}).chomp end end -- 2.23.0