multipull 0.0.0 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d5b0438e618d1ba1be329f027bb3bb449763a7f76f517b956f052608ffc62610
4
- data.tar.gz: 272f5c45b26d43d9d8e366d3ba4c3bb43300eb219a13215aba382c3f1406f12a
3
+ metadata.gz: 85fbb74adfa51265fbf7ac03bcebe9bbc82a5788b711fd5fc01a0205e32f8979
4
+ data.tar.gz: de2d5d1e0653eaca926d60e5707a3e909139c217a210040d3f7f912f0ab23086
5
5
  SHA512:
6
- metadata.gz: f9a218a785d6bf9165f642fbc57f43485a1c49f44d3b00f52a9a908cdec5c208b466138bdce9c0d3377d4ba2f9a36b8527fd79df0898d663605d95f8ea6822fa
7
- data.tar.gz: 0f5b6075aa72ba0ab1dcb6d51ee84a7c885f0bda10098631cbcc426d2b37e9bf6c467d1094368c096442212c6ba96e55e45ccc9a397cf7973d012ecbc899b44a
6
+ metadata.gz: e7ec2bace5daaa5954e78f3861e921c13fef5fa911b7b7e575c149deecfe89f370aa69ae6f21513089a406b17d11739d8ec5f2f2e3723c53365f1555d6e62ca9
7
+ data.tar.gz: eecb8376e777f44490ec41da96e1394d5742eca1e215692b4e2ace790d67e03e151320756c9538d4ba60ab55dedd3dd2cd172062ef0e8f55e44ae1df054a1ead
data/README.md CHANGED
@@ -1,23 +1,62 @@
1
1
  # multipull
2
2
 
3
- Ruby implementation of multipull
3
+ [![Gem Version](https://badge.fury.io/rb/multipull.svg)](https://badge.fury.io/rb/multipull)
4
4
 
5
- ## installation
5
+ Ruby implementation of [multipull](https://dev.to/rmpato/git-pull-multiple-repositories-at-once-4l68).
6
+
7
+ ## Installation
6
8
 
7
9
  ```sh
8
10
  gem install multipull
9
11
  ```
10
12
 
13
+ ## Usage
14
+
15
+ ```sh
16
+ multipull
17
+ ```
18
+
19
+ ```sh
20
+ multipull ~/Ruby # directory
21
+ ```
22
+
11
23
  ## What is this?
12
24
 
13
- The original implementation is here.
25
+ The name of the command multipull was borrowed from the following article.
14
26
 
15
27
  [Git pull multiple repositories at once](https://dev.to/rmpato/git-pull-multiple-repositories-at-once-4l68) by [@rmpato](https://github.com/rmpato)
16
28
 
17
- ```
29
+ ```sh
18
30
  alias multipull="find . -mindepth 1 -maxdepth 1 -type d -print -exec git -C {} pull \;"
19
31
  ```
20
32
 
33
+ The following pages include some great one-liners.
34
+
35
+ [Run git pull over all subdirectories](https://stackoverflow.com/questions/3497123/run-git-pull-over-all-subdirectories#12495234).
36
+
37
+ ```sh
38
+ find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \;
39
+ ```
40
+
41
+ ```sh
42
+ ls | xargs -I{} git -C {} pull
43
+ ls | xargs -P10 -I{} git -C {} pull
44
+ ```
45
+
46
+ ```sh
47
+ git config --global alias.all '!f() { ls -R -d */.git | xargs -I{} bash -c "echo {} && git -C {}/../ $1"; }; f'
48
+ ```
49
+
50
+ ```sh
51
+ for i in */.git; do ( echo $i; cd $i/..; git pull; ); done
52
+ ```
53
+
54
+ While these one-liners are nice, this multipull gem is better in the following ways
55
+
56
+ 1. No need to remember one-liners. `gem install multipull` is easier than writing alias in bashrc.
57
+ 2. No need to modify scripts for each OS.
58
+ 3. Options can be added as needed.
59
+
21
60
  ## Development
22
61
 
23
62
  PR welcome.
@@ -8,7 +8,9 @@ module Multipull
8
8
  include TerminalColor
9
9
 
10
10
  def initialize
11
- @dir = nil
11
+ # @options = {}
12
+ @dirs = []
13
+ @git_opts = []
12
14
  end
13
15
 
14
16
  def run
@@ -19,29 +21,66 @@ module Multipull
19
21
  private
20
22
 
21
23
  def parse_options
22
- OptionParser.new do |opts|
23
- opts.banner = 'Usage: multipull [options] [dir]'
24
+ opts = OptionParser.new
25
+ opts.banner = 'Usage: multipull [options] [dir...]'
24
26
 
25
- opts.on('-v', '--version', 'Show version') do
26
- puts VERSION
27
- exit
28
- end
27
+ opts.on('--version', 'Show version') do
28
+ puts VERSION
29
+ exit
30
+ end
29
31
 
30
- opts.on('-h', '--help', 'Show help') do
31
- puts opts
32
- exit
33
- end
34
- end.parse!
32
+ opts.on('--help', 'Show help') do
33
+ puts opts
34
+ exit
35
+ end
36
+
37
+ begin
38
+ opts.parse!
39
+ rescue OptionParser::InvalidOption => e
40
+ @git_opts += e.args
41
+ retry
42
+ end
43
+
44
+ @dirs = ARGV.empty? ? ['.'] : ARGV
45
+ end
35
46
 
36
- @dir = ARGV.shift || '.'
47
+ def start_banner(dirs)
48
+ targets = blue(dirs.join(' '))
49
+ puts bold("multipull: #{targets}")
37
50
  end
38
51
 
39
- def main
40
- Dir.chdir(@dir) do
41
- Dir.glob('*/').each do |dir|
42
- puts blue(bold(dir))
43
- system("git -C #{dir} pull")
52
+ def main(dirs = @dirs)
53
+ start_banner(dirs)
54
+ dirs.each do |dir|
55
+ unless File.directory?(dir)
56
+ puts magenta("#{dir} is not a directory")
57
+ next
58
+ end
59
+
60
+ skipped = []
61
+ succeeded = []
62
+ failed = []
63
+ Dir.chdir(dir) do
64
+ Dir.glob('*/').each do |subdir|
65
+ Dir.chdir(subdir) do
66
+ dirname = subdir.delete_suffix('/')
67
+ if File.directory?('.git')
68
+ puts blue(bold(dirname))
69
+ else
70
+ skipped << dirname
71
+ next
72
+ end
73
+ if system("git pull #{@git_opts.join(' ')}")
74
+ succeeded << dirname
75
+ else
76
+ failed << dirname
77
+ end
78
+ end
79
+ end
44
80
  end
81
+ warn bold('Skipped : ') + skipped.join(' ')
82
+ warn bold(green('Succeeded : ')) + succeeded.join(' ')
83
+ warn bold(magenta('Failed : ')) + failed.join(' ')
45
84
  end
46
85
  end
47
86
  end
@@ -6,6 +6,10 @@ module Multipull
6
6
  "\e[1m#{s}\e[22m"
7
7
  end
8
8
 
9
+ def green(s)
10
+ "\e[32m#{s}\e[0m"
11
+ end
12
+
9
13
  def cyan(s)
10
14
  "\e[36m#{s}\e[0m"
11
15
  end
@@ -13,5 +17,13 @@ module Multipull
13
17
  def blue(s)
14
18
  "\e[34m#{s}\e[0m"
15
19
  end
20
+
21
+ def magenta(s)
22
+ "\033[35m#{s}\033[0m"
23
+ end
24
+
25
+ def red(s)
26
+ "\033[31m#{s}\033[0m"
27
+ end
16
28
  end
17
29
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Multipull
4
- VERSION = '0.0.0'
4
+ VERSION = '0.0.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multipull
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - kojix2
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-06-01 00:00:00.000000000 Z
11
+ date: 2022-06-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Git pull multiple repositories at once
14
14
  email:
@@ -28,7 +28,7 @@ homepage: https://github.com/kojix2/multipull
28
28
  licenses:
29
29
  - MIT
30
30
  metadata: {}
31
- post_install_message:
31
+ post_install_message:
32
32
  rdoc_options: []
33
33
  require_paths:
34
34
  - lib
@@ -44,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
44
  version: '0'
45
45
  requirements: []
46
46
  rubygems_version: 3.3.7
47
- signing_key:
47
+ signing_key:
48
48
  specification_version: 4
49
49
  summary: Git pull multiple repositories at once
50
50
  test_files: []