Module: Git::Multi::Commands

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

Class Method Summary collapse

Class Method Details

.archived ⇒ Object



39
40
41
# File 'lib/git/multi/commands.rb', line 39

def archived
  puts Git::Multi.archived_repositories.map(&:full_name)
end

.check ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/git/multi/commands.rb', line 11

def check
  # Settings.user_status(Git::Multi::USER)
  # Settings.organization_status(Git::Multi::ORGANIZATIONS)
  # Settings.token_status(Git::Multi::TOKEN)
  Settings.home_status(Git::Multi::HOME)
  Settings.main_workarea_status(Git::Multi::WORKAREA)
  Settings.user_workarea_status(Git::Multi::USERS)
  Settings.organization_workarea_status(Git::Multi::ORGANIZATIONS)
  # Settings.file_status(Git::Multi::REPOSITORIES)
end

.clone ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/git/multi/commands.rb', line 94

def clone
  Git::Multi.missing_repositories.each do |repo|
    FileUtils.mkdir_p repo.parent_dir
    repo.just_do_it(
      ->(project) {
        notify "Cloning '#{repo.full_name}' repo into #{repo.parent_dir.parent}"
        Kernel.system "git clone -q #{project.rels[:ssh].href.shellescape}"
      },
      ->(project) {
        Kernel.system "git clone -q #{project.rels[:ssh].href.shellescape}"
      },
      in: 'parent_dir'
    )
  end
end

.count ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/git/multi/commands.rb', line 71

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) ⇒ Object



167
168
169
170
171
172
173
174
175
176
# File 'lib/git/multi/commands.rb', line 167

def eval(commands)
  Git::Multi.cloned_repositories.each do |repo|
    Dir.chdir(repo.local_path) do
      repo.instance_eval(commands.join(' ; '))
    rescue Octokit::NotFound
      # project no longer exists on github.com
      # consider running "git multi --stale"...
    end
  end
end

.excess ⇒ Object



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

def excess
  puts Git::Multi.excess_repositories.map(&:full_name)
end

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



146
147
148
149
# File 'lib/git/multi/commands.rb', line 146

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

.find(commands) ⇒ Object



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/git/multi/commands.rb', line 151

def find(commands)
  Git::Multi.cloned_repositories.each do |repo|
    Dir.chdir(repo.local_path) do
      if repo.instance_eval(commands.join(' && '))
        repo.just_do_it(
          ->(_project) { nil },
          ->(project) { puts project.full_name },
        )
      end
    rescue Octokit::NotFound
      # project no longer exists on github.com
      # consider running "git multi --stale"...
    end
  end
end

.forked ⇒ Object



43
44
45
# File 'lib/git/multi/commands.rb', line 43

def forked
  puts Git::Multi.forked_repositories.map(&:full_name)
end

.help ⇒ Object



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

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

.html ⇒ Object



26
27
28
# File 'lib/git/multi/commands.rb', line 26

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

.json ⇒ Object



90
91
92
# File 'lib/git/multi/commands.rb', line 90

def json
  puts Git::Multi.repositories.to_json
end

.list ⇒ Object



35
36
37
# File 'lib/git/multi/commands.rb', line 35

def list
  puts Git::Multi.repositories.map(&:full_name)
end

.missing ⇒ Object



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

def missing
  puts Git::Multi.missing_repositories.map(&:full_name)
end

.paths ⇒ Object



51
52
53
# File 'lib/git/multi/commands.rb', line 51

def paths
  puts Git::Multi.repositories.map(&:local_path)
end

.private ⇒ Object



47
48
49
# File 'lib/git/multi/commands.rb', line 47

def private
  puts Git::Multi.private_repositories.map(&:full_name)
end

.query(args = []) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/git/multi/commands.rb', line 110

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

.raw(args) ⇒ Object



141
142
143
144
# File 'lib/git/multi/commands.rb', line 141

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

.refresh ⇒ Object



86
87
88
# File 'lib/git/multi/commands.rb', line 86

def refresh
  Git::Multi.refresh_repositories
end

.report ⇒ Object



30
31
32
33
# File 'lib/git/multi/commands.rb', line 30

def report
  (missing_repos = Git::Multi.missing_repositories).any? &&
    notify(missing_repos.map(&:full_name), subtitle: "#{missing_repos.count} missing repos")
end

.spurious ⇒ Object



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

def spurious
  puts Git::Multi.spurious_repositories.map(&:full_name)
end

.stale ⇒ Object



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

def stale
  puts Git::Multi.stale_repositories.map(&:full_name)
end

.system(args = []) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/git/multi/commands.rb', line 126

def system(args = [])
  cmd = args.map!(&:shellescape).join(' ')
  Git::Multi.cloned_repositories.each do |repo|
    repo.just_do_it(
      ->(_project) {
        Kernel.system cmd
      },
      ->(project) {
        Kernel.system "#{cmd} 2>&1 | sed -e 's#^##{project.full_name.shellescape}: #'"
      },
      in: 'local_path'
    )
  end
end

.version ⇒ Object



7
8
9
# File 'lib/git/multi/commands.rb', line 7

def version
  puts Git::Multi::LONG_VERSION
end