On Tue, Sep 29, 2020 at 02:14:58PM +0800, Lu Kaiyi wrote:
On Tue, Sep 29, 2020 at 01:08:58PM +0800, Li Ping wrote:
On Tue, Sep 29, 2020 at 09:52:37AM +0800, Lu Kaiyi wrote:
On Mon, Sep 28, 2020 at 09:02:48PM +0800, Li Ping wrote:
lib/git.rb | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-)
diff --git a/lib/git.rb b/lib/git.rb index db97c47..a181ec9 100644 --- a/lib/git.rb +++ b/lib/git.rb @@ -3,8 +3,34 @@ # wrap common git commands class GitCommit def initialize(repo, commit)
- @git_prefix = "git -C /srv/git/#{repo}.git"
- @repo = repo @commit = commit
- @git_prefix = cd_repo_path
- end
- def check_repo
- fork_name = @repo.split('/')[0]
- project = @repo.split('/')[1]
- first_letter = project[0]
- fork_name = 'linus' if project == 'linux'
- path_a = find_path("/srv/git/#{first_letter}/#{project}/#{project}.git")
- path_b = find_path("/srv/git/#{first_letter}/#{project}/#{fork_name}.git")
- path_c = find_path("/srv/git/#{project}/#{fork_name}.git")
- path_d = find_path("/srv/git/#{project}/#{project}.git")
- path_a || path_b || path_c || path_d
- end
- def find_path(path)
- return false if Dir.glob(path).empty?
- Dir.glob(path).first
return path if Dir.exist?(path)
But i also want a Boolean value
It also return Boolean value nil if path doesn't exist, and It seems there is no much difference between false and nil when do || operation
ok, i got it, thank you for your advice.
Thanks, Ping
Thanks, Kaiyi
Thanks, Kaiyi
end
def cd_repo_path
find_repo = check_repo
return unless find_repo
"git -C #{find_repo}" end
def author_name
-- 2.23.0