git_fonky 0.2.0 → 0.4.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 +29 -0
- data/lib/git_fonky/repo_dir.rb +17 -77
- data/lib/git_fonky/reporter.rb +57 -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: 2d9e659e91221b3600b3d9924a209748976b7880108f49d724d4ffaaf2189ff6
|
4
|
+
data.tar.gz: 947bf8009681841bd4fcdd46c962bcc2d824b39851161aefa3777e75f5b0cd0b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 83e34338ffc13a6af5f9fe7d6684066bc74796037353122c9ee5bdc73a86e424d9438325d1634a8d5ba35cebd2ef86d3e3ecce2fcc8762bed39624b7e7ae0381
|
7
|
+
data.tar.gz: 2601863350da5d6a26b5a263cf9e9b903f43ec5b85858737c760ab122479467b7f535e3531a49255b1aab2b53324a9207d80a0e6e022b6dcc6e4d059dd433f47
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module GitFonky
|
2
|
+
class Command
|
3
|
+
attr_reader :repo_dir, :reporter
|
4
|
+
|
5
|
+
def initialize(repo_dir:, reporter:)
|
6
|
+
@repo_dir = repo_dir
|
7
|
+
@reporter = reporter
|
8
|
+
end
|
9
|
+
|
10
|
+
def current_branch
|
11
|
+
`git branch --show-current`.strip
|
12
|
+
end
|
13
|
+
|
14
|
+
def fetch_upstream
|
15
|
+
reporter.announce("fetching")
|
16
|
+
`git fetch upstream #{repo_dir.branch} 2>&1`
|
17
|
+
end
|
18
|
+
|
19
|
+
def pull_upstream
|
20
|
+
reporter.announce("pulling")
|
21
|
+
`git pull upstream #{repo_dir.branch} 2>&1`
|
22
|
+
end
|
23
|
+
|
24
|
+
def push_to_origin
|
25
|
+
reporter.announce("pushing", "to", "origin")
|
26
|
+
`git push origin #{repo_dir.branch} 2>&1`
|
27
|
+
end
|
28
|
+
end
|
29
|
+
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)
|
6
9
|
@dirname = dirname
|
10
|
+
@reporter = Reporter.new(self)
|
11
|
+
@command = Command.new(repo_dir: self, reporter: reporter)
|
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,57 @@
|
|
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(action, direction = "from", remote = "upstream")
|
10
|
+
puts "-----> #{action} #{direction} #{remote} #{repo_dir.branch}"
|
11
|
+
end
|
12
|
+
|
13
|
+
def announce_success
|
14
|
+
puts "-----> Successfully updated #{repo_dir.dirname} | #{repo_dir.branch} branch"
|
15
|
+
end
|
16
|
+
|
17
|
+
def announce_update
|
18
|
+
msg = "Updating -> #{repo_dir.dirname} | #{repo_dir.branch} branch "
|
19
|
+
border = calculate_border_for("=", msg)
|
20
|
+
|
21
|
+
output_border_and_msg(border, msg, warn: false)
|
22
|
+
end
|
23
|
+
|
24
|
+
def invalid_branch_msg
|
25
|
+
msg = "You are not on the main/master branch. Please checkout the main/master branch and try again."
|
26
|
+
sub_msg = "-----> skipping #{repo_dir.dirname} | #{repo_dir.branch} branch <-----"
|
27
|
+
border = calculate_border_for("*", msg)
|
28
|
+
|
29
|
+
output_border_and_msg(border, msg, sub_msg)
|
30
|
+
end
|
31
|
+
|
32
|
+
def failed_pull_msg
|
33
|
+
msg = "-----> Failed to pull upstream #{branch}. Moving on to next repo. <-----"
|
34
|
+
border = calculate_border_for(msg, "*")
|
35
|
+
|
36
|
+
output_border_and_msg(border, msg)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def calculate_border_for(border_char, msg)
|
42
|
+
border_char * (msg.length + 20)
|
43
|
+
end
|
44
|
+
|
45
|
+
def output_border_and_msg(border, msg, sub_msg = nil, warn: true)
|
46
|
+
puts border
|
47
|
+
puts warning_header.center(border.length) if warn
|
48
|
+
puts msg.center(border.length)
|
49
|
+
puts sub_msg.center(border.length) if sub_msg
|
50
|
+
puts border
|
51
|
+
end
|
52
|
+
|
53
|
+
def warning_header
|
54
|
+
"WARNING"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
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.4.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
|