Module: Git::Multi
- Defined in:
- lib/git/multi.rb,
lib/git/multi/utils.rb,
lib/git/multi/gemspec.rb,
lib/git/multi/version.rb,
lib/git/multi/commands.rb,
lib/git/multi/settings.rb
Defined Under Namespace
Modules: Commands, Nike, Settings
Constant Summary
collapse
- HOME =
Dir.home
- DEFAULT_WORKAREA =
File.join(HOME, 'Workarea')
- WORKAREA =
git_option('git.multi.workarea', DEFAULT_WORKAREA)
- DEFAULT_TOKEN =
env_var('OCTOKIT_ACCESS_TOKEN')
- TOKEN =
git_option('github.token', DEFAULT_TOKEN)
- CACHE =
File.join(HOME, '.git', 'multi')
- REPOSITORIES =
File.join(CACHE, 'repositories.byte')
- USERS =
git_list('github.users')
- ORGANIZATIONS =
git_list('github.organizations')
- MAN_PAGE =
File.expand_path('../../man/git-multi.1', __dir__)
- HTML_PAGE =
File.expand_path('../../man/git-multi.html', __dir__)
- PIM =
gem post_install_message, used in git-multi.gemspec
<<~"PIM".freeze # gem post_install_message, used in git-multi.gemspec
The only required setting for \033[1mgit multi\33[0m is:
\tgit config --global --add \033[1mgithub.token\033[0m <your_github_oauth_token>
The following settings for \033[1mgit multi\33[0m are
optional, and take 0, 1 or more values:
\tgit config --global --add \033[1mgithub.users\033[0m <list_of_github_users>
\tgit config --global --add \033[1mgithub.organizations\033[0m <list_of_github_orgs>
Unless your top-level workarea is `${HOME}/Workarea` you should also set:
\tgit config --global --add \033[1mgit.multi.workarea\033[0m <your_root_workarea>
Thanks for using \033[1mgit multi\033[0m
- NAME =
'git-multi'.freeze
- VERSION =
'1.0.9'.freeze
- DEPENDENCY_VERSIONS =
[
"octokit.rb v#{Octokit::VERSION}",
"sawyer v#{Sawyer::VERSION}",
"faraday v#{Faraday::VERSION}",
"addressable v#{Addressable::VERSION::STRING}",
"#{RUBY_ENGINE} #{RUBY_VERSION}p#{RUBY_PATCHLEVEL}",
].join(', ').freeze
- LONG_VERSION =
"#{NAME} v#{VERSION} (#{DEPENDENCY_VERSIONS})".freeze
Class Method Summary
collapse
Class Method Details
.archived_repositories ⇒ Object
lists of repositories with a given state
139
140
141
|
# File 'lib/git/multi.rb', line 139
def archived_repositories
repositories.find_all(&:archived)
end
|
.cloned_repositories ⇒ Object
188
189
190
191
192
|
# File 'lib/git/multi.rb', line 188
def cloned_repositories
repositories.find_all { |project|
File.directory? project.local_path
}
end
|
.env_var(name, default = nil) ⇒ Object
51
52
53
54
|
# File 'lib/git/multi/utils.rb', line 51
def env_var(name, default = nil)
value = ENV[name].freeze
(value.nil? || value.empty?) && default ? default : value
end
|
.excess_repositories ⇒ Object
derived lists of repositories
155
156
157
158
159
160
|
# File 'lib/git/multi.rb', line 155
def excess_repositories
repository_full_names = repositories.map(&:full_name)
local_repositories.reject { |project|
repository_full_names.include? project.full_name
}
end
|
.forked_repositories ⇒ Object
143
144
145
|
# File 'lib/git/multi.rb', line 143
def forked_repositories
repositories.find_all(&:fork)
end
|
.git_list(name, default = nil) ⇒ Object
47
48
49
|
# File 'lib/git/multi/utils.rb', line 47
def git_list(name, default = nil)
git_option(name, default).split(',').map(&:strip)
end
|
.git_option(name, default = nil) ⇒ Object
42
43
44
45
|
# File 'lib/git/multi/utils.rb', line 42
def git_option(name, default = nil)
value = `git config #{name}`.chomp.freeze
value.empty? && default ? default : value
end
|
.github_repositories ⇒ Object
remote repositories (on GitHub)
.local_repositories ⇒ Object
58
59
60
61
62
63
|
# File 'lib/git/multi.rb', line 58
def local_repositories
(
USERS.map { |user| @local_user_repositories[user] } +
ORGANIZATIONS.map { |org| @local_org_repositories[org] }
).flatten
end
|
.missing_repositories ⇒ Object
182
183
184
185
186
|
# File 'lib/git/multi.rb', line 182
def missing_repositories
repositories.find_all { |project|
!File.directory? project.local_path
}
end
|
.private_repositories ⇒ Object
147
148
149
|
# File 'lib/git/multi.rb', line 147
def private_repositories
repositories.find_all(&:private)
end
|
.refresh_repositories ⇒ Object
76
77
78
79
80
81
82
|
# File 'lib/git/multi.rb', line 76
def refresh_repositories
File.directory?(CACHE) || FileUtils.mkdir_p(CACHE)
File.open(REPOSITORIES, 'wb') do |file|
Marshal.dump(github_repositories, file)
end
end
|
.repositories ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/git/multi.rb', line 108
def repositories
if File.size?(REPOSITORIES)
@repositories ||= Marshal.load(File.read(REPOSITORIES)).tap do |projects|
notify "Finished loading #{REPOSITORIES}"
projects.each_with_index do |project, index|
project.client = Git::Hub.send(:client)
project.parent_dir = Pathname.new(File.join(WORKAREA, project.owner.login))
project.local_path = Pathname.new(File.join(WORKAREA, project.full_name))
project.fractional_index = "#{index + 1}/#{projects.count}"
project.compliant_ssh_url = 'ssh://' + project.ssh_url.split(':', 2).join('/')
project.abbreviated_ssh_url = project.ssh_url.chomp('.git')
project.extend Nike
end
end
else
refresh_repositories
repositories end
end
|
.spurious_repositories ⇒ Object
169
170
171
172
173
174
175
176
177
178
179
180
|
# File 'lib/git/multi.rb', line 169
def spurious_repositories
cloned_repositories.find_all { |project|
origin_url = `git -C #{project.local_path} config --get remote.origin.url`.chomp
![
project.clone_url,
project.ssh_url,
project.compliant_ssh_url,
project.abbreviated_ssh_url,
project.git_url,
].include? origin_url
}
end
|
.stale_repositories ⇒ Object
162
163
164
165
166
167
|
# File 'lib/git/multi.rb', line 162
def stale_repositories
repository_full_names = github_repositories.map(&:full_name)
repositories.reject { |project|
repository_full_names.include? project.full_name
}
end
|