git_fonky 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/git_fonky/command.rb +34 -0
- data/lib/git_fonky/repo_dir.rb +17 -77
- data/lib/git_fonky/reporter.rb +53 -0
- data/lib/git_fonky/version.rb +1 -1
- data/lib/git_fonky.rb +1 -0
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 075ddc336d9482d77d083db40a4b6ff7553ece62c759b3213a92df3bf277cfe9
|
4
|
+
data.tar.gz: bc74101affa62955eb5a1ed03a430cce6f59038aad66aeb99f3821dc264a55c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c2b26d77154d1281978063c57be33fe6f31d82c09879f81b41081542eceaaf7af032c05824fadba674d8fb5d7388253119756c9d0b9f433cc6831ff48c655674
|
7
|
+
data.tar.gz: ca914d2c8d384f32b37b91f0ba87cdcefc9ff40bb8cbd6bfaa42a93415899cae27ec592d5b9afbda35d57a0fe7010347c493fd9bf4fa08442f923ac5c7c22754
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module GitFonky
|
2
|
+
class Command
|
3
|
+
attr_reader :repo_dir
|
4
|
+
|
5
|
+
def initialize(repo_dir)
|
6
|
+
@repo_dir = repo_dir
|
7
|
+
end
|
8
|
+
|
9
|
+
def current_branch
|
10
|
+
`git branch --show-current`.strip
|
11
|
+
end
|
12
|
+
|
13
|
+
def fetch_upstream
|
14
|
+
announce("fetching")
|
15
|
+
`git fetch upstream #{repo_dir.branch} 2>&1`
|
16
|
+
end
|
17
|
+
|
18
|
+
def pull_upstream
|
19
|
+
announce("pulling")
|
20
|
+
`git pull upstream #{repo_dir.branch} 2>&1`
|
21
|
+
end
|
22
|
+
|
23
|
+
def push_to_origin
|
24
|
+
announce("pushing", "to", "origin")
|
25
|
+
`git push origin #{repo_dir.branch} 2>&1`
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def announce(action, direction = "from", remote = "upstream")
|
31
|
+
puts "-----> #{action} #{direction} #{remote} #{repo_dir.branch}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/lib/git_fonky/repo_dir.rb
CHANGED
@@ -1,97 +1,37 @@
|
|
1
|
+
require_relative "reporter"
|
2
|
+
require_relative "command"
|
3
|
+
|
1
4
|
module GitFonky
|
2
5
|
class RepoDir
|
3
|
-
attr_reader :dirname
|
6
|
+
attr_reader :command, :dirname, :reporter
|
4
7
|
|
5
8
|
def initialize(dirname)
|
9
|
+
@command = Command.new(self)
|
6
10
|
@dirname = dirname
|
11
|
+
@reporter = Reporter.new(self)
|
7
12
|
end
|
8
13
|
|
9
14
|
def branch
|
10
|
-
@branch ||=
|
15
|
+
@branch ||= command.current_branch
|
11
16
|
end
|
12
17
|
|
13
18
|
def sync
|
14
19
|
Dir.chdir dirname do
|
15
|
-
announce_update
|
16
|
-
|
17
|
-
fetch_upstream
|
18
|
-
pull_upstream
|
19
|
-
if $?.success?
|
20
|
-
push_to_origin
|
21
|
-
announce_success
|
22
|
-
else
|
23
|
-
failed_pull_msg
|
24
|
-
end
|
25
|
-
end
|
26
|
-
puts "\n\n"
|
27
|
-
end
|
28
|
-
|
29
|
-
def on_invalid_branch?
|
30
|
-
!branch.match?(/(main|master)/)
|
31
|
-
end
|
32
|
-
|
33
|
-
def invalid_branch_msg
|
34
|
-
msg = "You are not on the main/master branch. Please checkout the main/master branch and try again."
|
35
|
-
sub_msg = "-----> skipping #{dirname} | #{branch} branch <-----"
|
36
|
-
border = border_for(msg, "*")
|
37
|
-
|
38
|
-
puts border
|
39
|
-
puts warning_header.center(border.length)
|
40
|
-
puts msg.center(border.length)
|
41
|
-
puts sub_msg.center(border.length)
|
42
|
-
puts border
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
|
47
|
-
def failed_pull_msg
|
48
|
-
msg = "-----> Failed to pull upstream #{branch}. Moving on to next repo. <-----"
|
49
|
-
border = border_for(msg, "*")
|
50
|
-
|
51
|
-
puts border
|
52
|
-
puts warning_header.center(border.length)
|
53
|
-
puts msg.center(border.length)
|
54
|
-
puts border
|
55
|
-
end
|
20
|
+
reporter.announce_update
|
21
|
+
return reporter.invalid_branch_msg if on_invalid_branch?
|
56
22
|
|
57
|
-
|
58
|
-
|
59
|
-
border = border_for(msg, "=")
|
23
|
+
command.fetch_upstream
|
24
|
+
command.pull_upstream
|
60
25
|
|
61
|
-
|
62
|
-
puts msg.center(border.length)
|
63
|
-
puts border
|
64
|
-
end
|
65
|
-
|
66
|
-
def announce_success
|
67
|
-
puts "-----> Successfully updated #{dirname} | #{branch} branch"
|
68
|
-
end
|
69
|
-
|
70
|
-
def announce(action, direction = "from", remote = "upstream")
|
71
|
-
puts "-----> #{action} #{direction} #{remote} #{branch}"
|
72
|
-
end
|
73
|
-
|
74
|
-
def fetch_upstream
|
75
|
-
announce("fetching")
|
76
|
-
`git fetch upstream #{branch} 2>&1`
|
77
|
-
end
|
26
|
+
return reporter.failed_pull_msg unless $?.success?
|
78
27
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
end
|
83
|
-
|
84
|
-
def push_to_origin
|
85
|
-
announce("pushing", "to", "origin")
|
86
|
-
`git push origin #{branch} 2>&1`
|
87
|
-
end
|
88
|
-
|
89
|
-
def warning_header
|
90
|
-
"WARNING"
|
28
|
+
command.push_to_origin
|
29
|
+
reporter.announce_success
|
30
|
+
end
|
91
31
|
end
|
92
32
|
|
93
|
-
def
|
94
|
-
|
33
|
+
def on_invalid_branch?
|
34
|
+
!branch.match?(/(main|master)/)
|
95
35
|
end
|
96
36
|
end
|
97
37
|
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module GitFonky
|
2
|
+
class Reporter
|
3
|
+
attr_reader :repo_dir
|
4
|
+
|
5
|
+
def initialize(repo_dir)
|
6
|
+
@repo_dir = repo_dir
|
7
|
+
end
|
8
|
+
|
9
|
+
def announce_success
|
10
|
+
puts "-----> Successfully updated #{repo_dir.dirname} | #{repo_dir.branch} branch"
|
11
|
+
end
|
12
|
+
|
13
|
+
def announce_update
|
14
|
+
msg = "Updating -> #{repo_dir.dirname} | #{repo_dir.branch} branch "
|
15
|
+
border = calculate_border_for("=", msg)
|
16
|
+
|
17
|
+
output_border_and_msg(border, msg, warn: false)
|
18
|
+
end
|
19
|
+
|
20
|
+
def invalid_branch_msg
|
21
|
+
msg = "You are not on the main/master branch. Please checkout the main/master branch and try again."
|
22
|
+
sub_msg = "-----> skipping #{repo_dir.dirname} | #{repo_dir.branch} branch <-----"
|
23
|
+
border = calculate_border_for("*", msg)
|
24
|
+
|
25
|
+
output_border_and_msg(border, msg, sub_msg)
|
26
|
+
end
|
27
|
+
|
28
|
+
def failed_pull_msg
|
29
|
+
msg = "-----> Failed to pull upstream #{branch}. Moving on to next repo. <-----"
|
30
|
+
border = calculate_border_for(msg, "*")
|
31
|
+
|
32
|
+
output_border_and_msg(border, msg)
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def calculate_border_for(border_char, msg)
|
38
|
+
border_char * (msg.length + 20)
|
39
|
+
end
|
40
|
+
|
41
|
+
def output_border_and_msg(border, msg, sub_msg = nil, warn: true)
|
42
|
+
puts border
|
43
|
+
puts warning_header.center(border.length) if warn
|
44
|
+
puts msg.center(border.length)
|
45
|
+
puts sub_msg.center(border.length) if sub_msg
|
46
|
+
puts border
|
47
|
+
end
|
48
|
+
|
49
|
+
def warning_header
|
50
|
+
"WARNING"
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
data/lib/git_fonky/version.rb
CHANGED
data/lib/git_fonky.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_fonky
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Collin Jilbert
|
@@ -27,7 +27,9 @@ files:
|
|
27
27
|
- bin/gfonk
|
28
28
|
- git_fonky.gemspec
|
29
29
|
- lib/git_fonky.rb
|
30
|
+
- lib/git_fonky/command.rb
|
30
31
|
- lib/git_fonky/repo_dir.rb
|
32
|
+
- lib/git_fonky/reporter.rb
|
31
33
|
- lib/git_fonky/version.rb
|
32
34
|
- lib/git_fonky/work_repo_names.rb
|
33
35
|
- sig/git_fonky.rbs
|