git_eraser 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 9c2a260bb2d50039ee1c4a8cf97d7113ff7b5cb51dee191ddb18c3ea19f381d1
4
+ data.tar.gz: 93a8034decfab3b1d3ef4dc5e8b8d6dc5bde6405bc95053d0aefe40bce06db58
5
+ SHA512:
6
+ metadata.gz: 25f0806bc3ed68855ecf58bae3747e7febd66cef2f718cd8ee8397f3f58fa3030b58ba001b85334a2d05eeac4ce51a0843e8980a374cc8925146e3912b68f6ca
7
+ data.tar.gz: 3dae50239cac78518abb2345959f425db9d948e7b3b62de912f831d142e6f87ee25f19b13a934440c0debba0d6201124f0096bc29e4a50fb1b80f1af6ed23137
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "git_eraser"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/git_eraser ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "git_eraser"
4
+ require "thor"
5
+
6
+ GitEraser::Eraser.start(ARGV)
@@ -0,0 +1,3 @@
1
+ module GitEraser
2
+ VERSION = "0.1.2"
3
+ end
data/lib/git_eraser.rb ADDED
@@ -0,0 +1,246 @@
1
+ require "git_eraser/version"
2
+ require "thor"
3
+ require "highline"
4
+ require "rainbow"
5
+ require "httpclient"
6
+ require "git"
7
+
8
+ module GitEraser
9
+ class Error < StandardError; end
10
+
11
+ class Eraser < Thor
12
+
13
+ desc 'erase', 'Erase git branches that had been merged into master'
14
+ option :local
15
+ option :origin
16
+ def erase
17
+ erase_local if options[:local]
18
+ erase_origin if options[:origin]
19
+ Helper.new.print_no_flag_error_message if options.empty?
20
+ end
21
+
22
+ desc 'preview', 'Preview git branches that had been merged into master'
23
+ option :local
24
+ option :origin
25
+ def preview
26
+ preview_local if options[:local]
27
+ preview_origin if options[:origin]
28
+ Helper.new.print_no_flag_error_message if options.empty?
29
+ end
30
+
31
+ no_commands do
32
+ def preview_local
33
+ Git.configure do |config|
34
+ # If you want to use a custom git binary
35
+ config.binary_path = "/usr/bin/git"
36
+ end
37
+ current_directory = Dir.pwd
38
+
39
+ Helper.new.print_preview_message('local')
40
+ begin
41
+ g = Git.open("#{current_directory}")
42
+
43
+ g.branches.local.each_with_index do |local_branch, index|
44
+ puts " 🧹 #{index + 1}. #{local_branch}"
45
+ end
46
+
47
+ puts "\n\n"
48
+ rescue
49
+ Helper.new.print_no_git_error_message
50
+ end
51
+ end
52
+ end
53
+
54
+ no_commands do
55
+ def preview_origin
56
+ Git.configure do |config|
57
+ # If you want to use a custom git binary
58
+ config.binary_path = "/usr/bin/git"
59
+ end
60
+ current_directory = Dir.pwd
61
+
62
+ Helper.new.print_preview_message('origin')
63
+ begin
64
+ g = Git.open("#{current_directory}")
65
+
66
+ g.branches.remote.each_with_index do |origin_branch, index|
67
+ puts " 🧹 #{index + 1}. #{origin_branch}"
68
+ end
69
+
70
+ puts "\n\n"
71
+ rescue
72
+ Helper.new.print_no_git_error_message
73
+ end
74
+ end
75
+ end
76
+
77
+ no_commands do
78
+ def erase_local
79
+ current_directory = Dir.pwd
80
+
81
+ Helper.new.print_cleanup_message
82
+ begin
83
+ g = Git.open("#{current_directory}")
84
+
85
+ g.branches.local.each_with_index do |local_branch, index|
86
+ puts " 🧹 #{index + 1}. #{local_branch}"
87
+ end
88
+
89
+ puts "\n\n"
90
+
91
+ inputStream = HighLine.new
92
+ should_delete_branches = inputStream.agree("Delete these branches? (y/n) ")
93
+ if should_delete_branches == true
94
+ puts "\n\n"
95
+ g.checkout('master')
96
+ g.branches.local.each_with_index do |local_branch, index|
97
+ begin
98
+ if g.branch('master').contains?(local_branch)
99
+ local_branch.delete
100
+ puts " #{index + 1}. '#{local_branch}' Removed ✅"
101
+ else
102
+ puts " #{index + 1}. '#{local_branch}' Not merged into 'master' ❌"
103
+ end
104
+ rescue
105
+ puts " #{index + 1}. Can't remove '#{local_branch}' ❌"
106
+ end
107
+ end
108
+ end
109
+ puts "\n\n"
110
+ rescue
111
+ Helper.new.print_no_git_error_message
112
+ end
113
+ end
114
+ end
115
+
116
+ no_commands do
117
+ def erase_origin
118
+ current_directory = Dir.pwd
119
+
120
+ Helper.new.print_cleanup_message
121
+ begin
122
+ g = Git.open("#{current_directory}")
123
+
124
+ g.branches.remote.each_with_index do |origin_branch, index|
125
+ puts " 🧹 #{index + 1}. #{origin_branch}"
126
+ end
127
+
128
+ puts "\n\n"
129
+
130
+ inputStream = HighLine.new
131
+ should_delete_branches = inputStream.agree("Delete these branches? (y/n) ")
132
+
133
+ if should_delete_branches == true
134
+ puts "\n\n"
135
+ g.checkout('master')
136
+ g.pull('origin', 'master')
137
+ array_of_remote_deleted_branches = []
138
+ g.branches.remote.each_with_index do |origin_branch, index|
139
+ begin
140
+ branch_string = origin_branch.to_s
141
+ branch_string['remotes/origin/'] = ''
142
+ g.checkout(branch_string)
143
+ if g.branch('master').contains?(branch_string) && branch_string != 'master'
144
+ system "git push -u origin --delete #{branch_string} -q"
145
+ puts " #{index + 1}. '#{origin_branch}' Removed ✅"
146
+ array_of_remote_deleted_branches.append(branch_string)
147
+ elsif branch_string == 'master'
148
+ puts " #{index + 1}. '#{origin_branch}' Can't remove 'master' branch ❌"
149
+ else
150
+ puts " #{index + 1}. '#{origin_branch}' Not merged into 'master' ❌"
151
+ end
152
+ rescue
153
+ puts " #{index + 1}. Can't remove '#{origin_branch}' ❌"
154
+ end
155
+ end
156
+ g.checkout('master')
157
+ delete_local_after_origin(array_of_remote_deleted_branches)
158
+ end
159
+ puts "\n\n"
160
+ rescue
161
+ Helper.new.print_no_git_error_message
162
+ end
163
+ end
164
+ end
165
+
166
+ no_commands do
167
+ def delete_local_after_origin(branches)
168
+ current_directory = Dir.pwd
169
+ begin
170
+ g = Git.open("#{current_directory}")
171
+ g.branches.local.each do |local_branch|
172
+ puts "Local: #{local_branch}"
173
+ branches.each do |value|
174
+ puts "coming: #{value}"
175
+ if local_branch.to_s == value
176
+ local_branch.delete
177
+ end
178
+ end
179
+ end
180
+ rescue
181
+ end
182
+ end
183
+ end
184
+
185
+ end
186
+
187
+ class Helper
188
+ def print_cleanup_message
189
+ text2 = "
190
+ _____ _ _ ______
191
+ / ____(_) | | ____|
192
+ | | __ _| |_ | |__ _ __ __ _ ___ ___ _ __
193
+ | | |_ | | __| | __| | '__/ _` / __|/ _ \\ '__|
194
+ | |__| | | |_ | |____| | | (_| \\__ \\ __/ |
195
+ \\_____|_|\\__| |______|_| \\__,_|___/\\___|_|
196
+ "
197
+ puts "#{text2} \n"
198
+ puts "Welcome to the #{Rainbow("Git Eraser").underline.bright.red} 🧹🧹 project!
199
+ Before we start cleaning your git branches, here is a preview of your branches: \n\n"
200
+ end
201
+
202
+ def print_preview_message(git_type)
203
+ text2 = "
204
+ _____ _ _ ______
205
+ / ____(_) | | ____|
206
+ | | __ _| |_ | |__ _ __ __ _ ___ ___ _ __
207
+ | | |_ | | __| | __| | '__/ _` / __|/ _ \\ '__|
208
+ | |__| | | |_ | |____| | | (_| \\__ \\ __/ |
209
+ \\_____|_|\\__| |______|_| \\__,_|___/\\___|_|
210
+ "
211
+ puts "#{text2} \n"
212
+ puts "Welcome to the #{Rainbow("Git Eraser").underline.bright.red} 🧹🧹 project!
213
+ Here is a preview of your #{git_type} branches: \n\n"
214
+ end
215
+
216
+ def print_no_git_error_message
217
+ text2 = "
218
+ _____ _ _ ______
219
+ / ____(_) | | ____|
220
+ | | __ _| |_ | |__ _ __ __ _ ___ ___ _ __
221
+ | | |_ | | __| | __| | '__/ _` / __|/ _ \\ '__|
222
+ | |__| | | |_ | |____| | | (_| \\__ \\ __/ |
223
+ \\_____|_|\\__| |______|_| \\__,_|___/\\___|_|
224
+ "
225
+ puts "#{text2} \n"
226
+ puts "Welcome to the #{Rainbow("Git Eraser").underline.bright.red} 🧹🧹 project! \n\n"
227
+ puts "⚠️⚠️ There is no #{Rainbow("git").underline.bright.red} directory here 😡 \n\n"
228
+ end
229
+
230
+ def print_no_flag_error_message
231
+ text2 = "
232
+ _____ _ _ ______
233
+ / ____(_) | | ____|
234
+ | | __ _| |_ | |__ _ __ __ _ ___ ___ _ __
235
+ | | |_ | | __| | __| | '__/ _` / __|/ _ \\ '__|
236
+ | |__| | | |_ | |____| | | (_| \\__ \\ __/ |
237
+ \\_____|_|\\__| |______|_| \\__,_|___/\\___|_|
238
+ "
239
+ puts "#{text2} \n"
240
+ puts "Welcome to the #{Rainbow("Git Eraser").underline.bright.red} 🧹🧹 project! \n\n"
241
+ puts "⚠️⚠️ You didn't specify any flag, please use --local or --origin flag 😡 \n\n"
242
+ end
243
+ end
244
+
245
+
246
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git_eraser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - KarimEbrahem
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.20.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.20.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: highline
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 2.0.2
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 2.0.2
41
+ - !ruby/object:Gem::Dependency
42
+ name: rainbow
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 3.0.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 3.0.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: git
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: httpclient
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.8.3
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.8.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: bundler
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '2.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '2.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '10.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '10.0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '3.0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '3.0'
125
+ description: git_eraser is used to help you in cleaning your branches.
126
+ email:
127
+ - karimabdelazizmansour@gmail.com
128
+ executables:
129
+ - git_eraser
130
+ extensions: []
131
+ extra_rdoc_files: []
132
+ files:
133
+ - bin/console
134
+ - bin/setup
135
+ - exe/git_eraser
136
+ - lib/git_eraser.rb
137
+ - lib/git_eraser/version.rb
138
+ homepage: https://github.com/KarimEbrahemAbdelaziz/git_eraser
139
+ licenses:
140
+ - MIT
141
+ metadata:
142
+ allowed_push_host: https://RubyGems.org
143
+ homepage_uri: https://github.com/KarimEbrahemAbdelaziz/git_eraser
144
+ source_code_uri: https://github.com/KarimEbrahemAbdelaziz/git_eraser
145
+ changelog_uri: https://github.com/KarimEbrahemAbdelaziz/git_eraser
146
+ post_install_message:
147
+ rdoc_options: []
148
+ require_paths:
149
+ - lib
150
+ required_ruby_version: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">="
153
+ - !ruby/object:Gem::Version
154
+ version: '0'
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ requirements: []
161
+ rubygems_version: 3.0.1
162
+ signing_key:
163
+ specification_version: 4
164
+ summary: git_eraser is used to help you in cleaning your git branches.
165
+ test_files: []