Module: Git::Multi::Commands

Defined in:
lib/git/multi/commands.rb

Class Method Summary collapse

Class Method Details

.archived(multi_repo = nil) ⇒ Object



66
67
68
# File 'lib/git/multi/commands.rb', line 66

def archived(multi_repo = nil)
  puts Git::Multi.archived_repositories_for(multi_repo).map(&:full_name)
end

.clone(multi_repo = nil) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/git/multi/commands.rb', line 86

def clone(multi_repo = nil)
  Git::Multi.missing_repositories_for(multi_repo).each do |repository|
    FileUtils.mkdir_p repository.parent_dir # create multi-repo workarea
    repository.just_do_it(
      ->(repo) {
        Kernel.system "git clone -q #{repo.rels[:ssh].href.shellescape}"
      },
      ->(repo) {
        Kernel.system "git clone -q #{repo.rels[:ssh].href.shellescape}"
      },
      nil, # captured
      in: 'parent_dir'
    )
  end
end

.countObject



39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/git/multi/commands.rb', line 39

def count
  # https://developer.github.com/v3/repos/#list-user-repositories
  Git::Multi::USERS.each do |user|
    %w[all owner member].each { |type|
      puts ["#{user}/#{type}", Git::Hub.user_repositories(user, type).count].join("\t")
    }
  end
  # https://developer.github.com/v3/repos/#list-organization-repositories
  Git::Multi::ORGANIZATIONS.each do |org|
    %w[all public private forks sources member].each { |type|
      puts ["#{org}/#{type}", Git::Hub.org_repositories(org, type).count].join("\t")
    }
  end
end

.eval(commands, multi_repo) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/git/multi/commands.rb', line 148

def eval(commands, multi_repo)
  Git::Multi.cloned_repositories_for(multi_repo).each do |repo|
    Dir.chdir(repo.local_path) do
      begin
        repo.instance_eval(commands.join(' ; '))
      rescue Octokit::NotFound
        # repository no longer exists on GitHub
        # consider running "git multi --stale"!
      end
    end
  end
end

.excess(multi_repo = nil) ⇒ Object



106
107
108
# File 'lib/git/multi/commands.rb', line 106

def excess(multi_repo = nil)
  puts Git::Multi.excess_repositories_for(multi_repo).map(&:full_name)
end

.exec(command, args = [], multi_repo = nil) ⇒ Object



171
172
173
174
# File 'lib/git/multi/commands.rb', line 171

def exec(command, args = [], multi_repo = nil)
  args.unshift ['git', '--no-pager', command]
  system(args.flatten, multi_repo)
end

.find(commands, multi_repo = nil) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/git/multi/commands.rb', line 130

def find(commands, multi_repo = nil)
  Git::Multi.cloned_repositories_for(multi_repo).each do |repository|
    Dir.chdir(repository.local_path) do
      begin
        if repository.instance_eval(commands.join(' && '))
          repository.just_do_it(
            ->(_repo) {}, # empty lambda: nil
            ->(repo) { puts repo.full_name },
          )
        end
      rescue Octokit::NotFound
        # repository no longer exists on GitHub
        # consider running "git multi --stale"!
      end
    end
  end
end

.forked(multi_repo = nil) ⇒ Object



70
71
72
# File 'lib/git/multi/commands.rb', line 70

def forked(multi_repo = nil)
  puts Git::Multi.forked_repositories_for(multi_repo).map(&:full_name)
end

.helpObject



18
19
20
# File 'lib/git/multi/commands.rb', line 18

def help
  Kernel.exec "man #{Git::Multi::MAN_PAGE}"
end

.htmlObject



22
23
24
# File 'lib/git/multi/commands.rb', line 22

def html
  Kernel.exec "open #{Git::Multi::HTML_PAGE}"
end

.json(multi_repo = nil) ⇒ Object



58
59
60
# File 'lib/git/multi/commands.rb', line 58

def json(multi_repo = nil)
  puts Git::Multi.repositories_for(multi_repo).to_json
end

.list(multi_repo = nil) ⇒ Object



62
63
64
# File 'lib/git/multi/commands.rb', line 62

def list(multi_repo = nil)
  puts Git::Multi.repositories_for(multi_repo).map(&:full_name)
end

.missing(multi_repo = nil) ⇒ Object



82
83
84
# File 'lib/git/multi/commands.rb', line 82

def missing(multi_repo = nil)
  puts Git::Multi.missing_repositories_for(multi_repo).map(&:full_name)
end

.paths(multi_repo = nil) ⇒ Object



78
79
80
# File 'lib/git/multi/commands.rb', line 78

def paths(multi_repo = nil)
  puts Git::Multi.repositories_for(multi_repo).map(&:local_path)
end

.private(multi_repo = nil) ⇒ Object



74
75
76
# File 'lib/git/multi/commands.rb', line 74

def private(multi_repo = nil)
  puts Git::Multi.private_repositories_for(multi_repo).map(&:full_name)
end

.query(args = [], multi_repo = nil) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/git/multi/commands.rb', line 114

def query(args = [], multi_repo = nil)
  Git::Multi.repositories_for(multi_repo).each do |repository|
    repository.just_do_it(
      ->(repo) {
        args.each do |attribute|
          puts "#{attribute}: #{repo[attribute]}"
        end
      },
      ->(repo) {
        print "#{repo.full_name}: "
        puts args.map { |attribute| repo[attribute] }.join(' ')
      },
    )
  end
end

.raw(args, multi_repo = nil) ⇒ Object



166
167
168
169
# File 'lib/git/multi/commands.rb', line 166

def raw(args, multi_repo = nil)
  args.unshift ['sh', '-c']
  system(args.flatten, multi_repo)
end

.refreshObject



54
55
56
# File 'lib/git/multi/commands.rb', line 54

def refresh
  Git::Multi.refresh_repositories
end

.report(multi_repo = nil) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/git/multi/commands.rb', line 26

def report(multi_repo = nil)
  case multi_repo
  when nil
    Report.home_status(Git::Multi::HOME)
    Report.workarea_status(Git::Multi::WORKAREA)
    Report.for(*MULTI_REPOS)
  when *MULTI_REPOS
    Report.for(multi_repo)
  else
    raise ArgumentError, multi_repo
  end
end

.shell(args, multi_repo) ⇒ Object



161
162
163
164
# File 'lib/git/multi/commands.rb', line 161

def shell(args, multi_repo)
  args.unshift [ENV.fetch('SHELL', '/bin/sh'), '-l']
  system(args.flatten, multi_repo)
end

.spurious(multi_repo = nil) ⇒ Object



110
111
112
# File 'lib/git/multi/commands.rb', line 110

def spurious(multi_repo = nil)
  puts Git::Multi.spurious_repositories_for(multi_repo).map(&:full_name)
end

.stale(multi_repo = nil) ⇒ Object



102
103
104
# File 'lib/git/multi/commands.rb', line 102

def stale(multi_repo = nil)
  puts Git::Multi.stale_repositories_for(multi_repo).map(&:full_name)
end

.versionObject



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/git/multi/commands.rb', line 6

def version
  dependencies = [
    "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(', ')

  puts "#{Git::Multi::NAME} v#{Git::Multi::VERSION} (#{dependencies})"
end