lib/git/multi.rb in git-multi-6.0.0 vs lib/git/multi.rb in git-multi-7.0.0

- old
+ new

@@ -34,20 +34,18 @@ DEFAULT_TOKEN = env_var('OCTOKIT_ACCESS_TOKEN') # same as Octokit TOKEN = global_option('github.token', DEFAULT_TOKEN) GIT_MULTI_DIR = File.join(HOME, '.git', 'multi') - - FileUtils.mkdir_p(GIT_MULTI_DIR) # ensure `~/.git/multi` directory exists - GITHUB_CACHE = File.join(GIT_MULTI_DIR, 'repositories.byte') USERS = global_list('git.multi.users') ORGANIZATIONS = global_list('git.multi.organizations') SUPERPROJECTS = global_list('git.multi.superprojects') MULTI_REPOS = (USERS + ORGANIZATIONS + SUPERPROJECTS) + EXCLUDED_REPOS = global_options('git.multi.exclude') MAN_PAGE = File.expand_path('../../man/git-multi.1', __dir__) HTML_PAGE = File.expand_path('../../man/git-multi.html', __dir__) module_function @@ -127,10 +125,13 @@ # # manage the local repository cache # def refresh_repositories + # ensure `~/.git/multi` directory exists + FileUtils.mkdir_p(GIT_MULTI_DIR) + File.open(GITHUB_CACHE, 'wb') do |file| Marshal.dump(github_repositories, file) end end @@ -192,10 +193,12 @@ repo.client = Git::Hub.send(:client) # adorn 'repo', which is a Sawyer::Resource repo.parent_dir = Pathname.new(File.join(WORKAREA, repo.owner.login)) repo.local_path = Pathname.new(File.join(WORKAREA, repo.full_name)) repo.fractional_index = "#{index + 1}/#{repos.count}" + # git multi will "hard ignore" all excluded repos + repo.excluded = EXCLUDED_REPOS.include?(repo.full_name) # fix 'repo' => https://github.com/octokit/octokit.rb/issues/727 repo.compliant_ssh_url = "ssh://#{repo.ssh_url.split(':', 2).join('/')}" # remove optional '.git' suffix from 'git@github.com:pvdb/git-multi.git' repo.abbreviated_ssh_url = repo.ssh_url.chomp('.git') # extend 'repo' with 'just do it' capabilities @@ -211,11 +214,15 @@ # # lists of repos for a given multi-repo # - def repositories_for(multi_repo = nil) + def full_names_for(superproject) + global_options("superproject.#{superproject}.repo") + end + + def all_repositories_for(multi_repo = nil) case (owner = superproject = full_names = multi_repo) when nil repositories # all of them when Array repositories.find_all { |repository| @@ -224,29 +231,37 @@ when *USERS, *ORGANIZATIONS repositories.find_all { |repository| repository.owner.login == owner } when *SUPERPROJECTS - repositories_for(full_names_for(superproject)) + all_repositories_for(full_names_for(superproject)) else raise ArgumentError, multi_repo end end + def repositories_for(multi_repo = nil) + all_repositories_for(multi_repo).delete_if(&:excluded) + end + # # lists of repositories with a given state # def archived_repositories_for(multi_repo = nil) - repositories_for(multi_repo).find_all(&:archived) + all_repositories_for(multi_repo).find_all(&:archived) end def forked_repositories_for(multi_repo = nil) - repositories_for(multi_repo).find_all(&:fork) + all_repositories_for(multi_repo).find_all(&:fork) end def private_repositories_for(multi_repo = nil) - repositories_for(multi_repo).find_all(&:private) + all_repositories_for(multi_repo).find_all(&:private) + end + + def excluded_repositories_for(multi_repo = nil) + all_repositories_for(multi_repo).find_all(&:excluded) end # # derived lists of repositories #