Module: Git::Multi::Commands

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

Class Method Summary collapse

Class Method Details

.archived(multi_repo = nil) ⇒ Object



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

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

.clone(multi_repo = nil) ⇒ Object



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

def clone(multi_repo = nil)
  Git::Multi.missing_repositories_for(multi_repo).each do |repo|
    FileUtils.mkdir_p repo.parent_dir
    repo.just_do_it(
      ->(project) {
        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

.countObject



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

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



132
133
134
135
136
137
138
139
140
141
# File 'lib/git/multi/commands.rb', line 132

def eval(commands, multi_repo)
  Git::Multi.cloned_repositories_for(multi_repo).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(multi_repo = nil) ⇒ Object



92
93
94
# File 'lib/git/multi/commands.rb', line 92

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

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



148
149
150
151
# File 'lib/git/multi/commands.rb', line 148

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



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

def find(commands, multi_repo = nil)
  Git::Multi.cloned_repositories_for(multi_repo).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(multi_repo = nil) ⇒ Object



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

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

.helpObject



11
12
13
# File 'lib/git/multi/commands.rb', line 11

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

.htmlObject



15
16
17
# File 'lib/git/multi/commands.rb', line 15

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

.json(multi_repo = nil) ⇒ Object



45
46
47
# File 'lib/git/multi/commands.rb', line 45

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

.list(multi_repo = nil) ⇒ Object



49
50
51
# File 'lib/git/multi/commands.rb', line 49

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

.missing(multi_repo = nil) ⇒ Object



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

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

.paths(multi_repo = nil) ⇒ Object



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

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

.private(multi_repo = nil) ⇒ Object



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

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

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



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/git/multi/commands.rb', line 100

def query(args = [], multi_repo = nil)
  Git::Multi.repositories_for(multi_repo).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, multi_repo = nil) ⇒ Object



143
144
145
146
# File 'lib/git/multi/commands.rb', line 143

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

.refreshObject



41
42
43
# File 'lib/git/multi/commands.rb', line 41

def refresh
  Git::Multi.refresh_repositories
end

.reportObject



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

def report
  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)
end

.spurious(multi_repo = nil) ⇒ Object



96
97
98
# File 'lib/git/multi/commands.rb', line 96

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

.stale(multi_repo = nil) ⇒ Object



88
89
90
# File 'lib/git/multi/commands.rb', line 88

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

.versionObject



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

def version
  puts Git::Multi::LONG_VERSION
end