G4t 1.0 → 1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/g4t +2 -2
- data/lib/g4t.rb +249 -252
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12071d7efb40562adf27b9085f76a9b39518051cffe8c4d5474c8535e0d39239
|
4
|
+
data.tar.gz: efc7c982c40fd67c732a2d5fa0f0346b06399c426544c92ae0f4d2921645f7af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 808946461f0318062406a275f61e1c15fa568d8dc15525c581a005f0ee39e77516c2d9436e26cabe3bd30c27d427e370c53207779651f016b1741c28c00ed4d7
|
7
|
+
data.tar.gz: fab9e8efe83b793b9902a8205851cfccae5dec41861b9bf629e0f1587e65e2e8271f2c6f388beaebef2abe39fadbb1b31e6f863140d73c7a46572b0a4f126231
|
data/bin/g4t
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require "g4t"
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require "g4t"
|
data/lib/g4t.rb
CHANGED
@@ -1,252 +1,249 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
require "os"
|
4
|
-
require "tty-prompt"
|
5
|
-
require "etc"
|
6
|
-
|
7
|
-
module G4t
|
8
|
-
class Options
|
9
|
-
def initialize
|
10
|
-
$prompt = TTY::Prompt.new
|
11
|
-
end
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
all_files
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
"
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
when "
|
164
|
-
@opt.
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
"
|
187
|
-
"
|
188
|
-
"
|
189
|
-
"Show
|
190
|
-
"
|
191
|
-
"Show
|
192
|
-
"
|
193
|
-
"
|
194
|
-
"
|
195
|
-
"
|
196
|
-
"
|
197
|
-
"
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
Run.new
|
252
|
-
end
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
require "os"
|
4
|
+
require "tty-prompt"
|
5
|
+
require "etc"
|
6
|
+
|
7
|
+
module G4t
|
8
|
+
class Options
|
9
|
+
def initialize
|
10
|
+
$prompt = TTY::Prompt.new
|
11
|
+
end
|
12
|
+
def commit_files
|
13
|
+
$lastmsg = "Now that we commited the files"
|
14
|
+
msg = $prompt.ask("Commit message:")
|
15
|
+
|
16
|
+
if msg[0] != "\""
|
17
|
+
msg = "\"#{msg}"
|
18
|
+
end
|
19
|
+
|
20
|
+
if msg[-1] != "\""
|
21
|
+
msg = "#{msg}\""
|
22
|
+
end
|
23
|
+
|
24
|
+
puts msg
|
25
|
+
run_command("git commit -m #{msg}")
|
26
|
+
end
|
27
|
+
|
28
|
+
def add_files
|
29
|
+
$lastmsg = "Now that we added the files"
|
30
|
+
all_files = $prompt.yes?("Add all files?")
|
31
|
+
if all_files
|
32
|
+
cmd = "git add ."
|
33
|
+
puts("Adding all files...")
|
34
|
+
else
|
35
|
+
fname = $prompt.ask("File to add:")
|
36
|
+
cmd = "git add #{fname}"
|
37
|
+
end
|
38
|
+
run_command(cmd)
|
39
|
+
end
|
40
|
+
|
41
|
+
def logs
|
42
|
+
run_command("git log")
|
43
|
+
end
|
44
|
+
|
45
|
+
def push_branch
|
46
|
+
branch = $prompt.ask("Branch to push:")
|
47
|
+
run_command("git push origin #{branch}")
|
48
|
+
end
|
49
|
+
|
50
|
+
def remote_adress
|
51
|
+
$lastmsg = "Now that we the remote address"
|
52
|
+
uname = $prompt.ask("Your github username:")
|
53
|
+
repo = $prompt.ask("Your repository name:")
|
54
|
+
puts("Adding remote repository https://github.com/#{uname}/#{repo}...")
|
55
|
+
run_command("git remote add origin https://github.com/#{uname}/#{repo}.git")
|
56
|
+
end
|
57
|
+
|
58
|
+
def status
|
59
|
+
run_command("git status")
|
60
|
+
end
|
61
|
+
|
62
|
+
def clone_repo
|
63
|
+
uname = $prompt.ask("Username:")
|
64
|
+
repo = $prompt.ask("Repository name:")
|
65
|
+
run_command("git clone https://github.com/#{uname}/#{repo}/")
|
66
|
+
end
|
67
|
+
|
68
|
+
def restore
|
69
|
+
fname = $prompt.ask("File name:")
|
70
|
+
run_command("git restore #{fname}")
|
71
|
+
end
|
72
|
+
|
73
|
+
def reset
|
74
|
+
commit = $prompt.ask("Commit id:")
|
75
|
+
run_command("git reset --hard #{commit}")
|
76
|
+
end
|
77
|
+
|
78
|
+
def hard_reset
|
79
|
+
confirmation = $prompt.yes?("do you really want to hard reset?")
|
80
|
+
|
81
|
+
if confirmation
|
82
|
+
run_command("git reset --hard HEAD~")
|
83
|
+
else
|
84
|
+
puts "Cancelling operation"
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
def initialize_git
|
90
|
+
$lastmsg = "Now that we initialized .git"
|
91
|
+
puts("Initializing Git repository in '#{Dir.pwd}/.git'...")
|
92
|
+
run_command("git init")
|
93
|
+
end
|
94
|
+
|
95
|
+
def diff
|
96
|
+
run_command("git diff")
|
97
|
+
end
|
98
|
+
|
99
|
+
def change_branch
|
100
|
+
bname = $prompt.ask("Branch name:")
|
101
|
+
run_command("git checkout -b #{bname}")
|
102
|
+
end
|
103
|
+
|
104
|
+
def git_info
|
105
|
+
status = {
|
106
|
+
"Git branch" => IO.popen("git branch"),
|
107
|
+
"Repository url" => IO.popen("git config --get remote.origin.url")
|
108
|
+
}
|
109
|
+
status.each do |k, v|
|
110
|
+
puts("#{k}: #{v.read}")
|
111
|
+
end
|
112
|
+
puts("____________\n\n")
|
113
|
+
end
|
114
|
+
|
115
|
+
def remove_file
|
116
|
+
file_name = $prompt.ask("Enter the file name: ")
|
117
|
+
run_command("git rm #{file_name}")
|
118
|
+
end
|
119
|
+
|
120
|
+
def show_last_commit
|
121
|
+
run_command("git show")
|
122
|
+
end
|
123
|
+
|
124
|
+
def pull_changes
|
125
|
+
git_pull_options = ["rebase", "no-rebase", "ff-only"]
|
126
|
+
chose = $prompt.select("chose: ", git_pull_options)
|
127
|
+
run_command("git pull --#{chose}")
|
128
|
+
end
|
129
|
+
|
130
|
+
def run_command(cmd)
|
131
|
+
puts "Command: #{cmd}"
|
132
|
+
system(cmd)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
class Run
|
137
|
+
def initialize
|
138
|
+
@opt = Options.new
|
139
|
+
git_init?
|
140
|
+
start
|
141
|
+
end
|
142
|
+
|
143
|
+
def verify_system
|
144
|
+
if OS.windows?; "C:\\Users\\#{Etc.getlogin}\\.gitconfig" else "/home/#{Etc.getlogin}/.gitconfig" end
|
145
|
+
end
|
146
|
+
def git_init?
|
147
|
+
identify_user
|
148
|
+
unless File.directory?(".git")
|
149
|
+
begin
|
150
|
+
options = ["Clone a repo", "Initialize a repo", "Close"]
|
151
|
+
@git_init_select = $prompt.select("The .git directory was not found, what do you want to do?", options)
|
152
|
+
git_init_verify
|
153
|
+
rescue TTY::Reader::InputInterrupt
|
154
|
+
abort("\nCloseed")
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def git_init_verify
|
160
|
+
case @giti_init_select
|
161
|
+
when "Clone a repo"
|
162
|
+
@opt.clone_repo
|
163
|
+
when "Init a repo"
|
164
|
+
@opt.init_repo
|
165
|
+
else
|
166
|
+
abort("It is not possible to continue without a .git repository or cloned repository!")
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
def identify_user
|
171
|
+
if(File.exist?(verify_system)) == false
|
172
|
+
begin
|
173
|
+
email = $prompt.ask("Github email: ")
|
174
|
+
uname = $prompt.ask("Github username: ")
|
175
|
+
@opt.run_command("git config --global user.email #{email} && git config --global user.name #{uname}")
|
176
|
+
rescue TTY::Reader::InputInterrupt
|
177
|
+
abort("\nYou closed the application")
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
def show_panel
|
183
|
+
options = ["Add remote address",
|
184
|
+
"Add files",
|
185
|
+
"Commit files",
|
186
|
+
"Push files to branch",
|
187
|
+
"Show git status",
|
188
|
+
"Show git logs",
|
189
|
+
"Show the last commit",
|
190
|
+
"Remove a file",
|
191
|
+
"Show diff",
|
192
|
+
"Change branch",
|
193
|
+
"Git pull changes",
|
194
|
+
"Restore a file",
|
195
|
+
"Reset to a commit",
|
196
|
+
"Reset to the last commit",
|
197
|
+
"Close"
|
198
|
+
]
|
199
|
+
|
200
|
+
begin
|
201
|
+
@opt.git_info
|
202
|
+
@opt_select = $prompt.select("Select: ", options)
|
203
|
+
verify_option
|
204
|
+
rescue TTY::Reader::InputInterrupt
|
205
|
+
abort("\nYou has closed the application.")
|
206
|
+
end
|
207
|
+
end
|
208
|
+
def verify_option
|
209
|
+
case @opt_select
|
210
|
+
when "Add remote address" then
|
211
|
+
@opt.remote_adress
|
212
|
+
when "Add files" then
|
213
|
+
@opt.add_files
|
214
|
+
when "Commit files" then
|
215
|
+
@opt.commit_files
|
216
|
+
when "Push files to branch" then
|
217
|
+
@opt.push_branch
|
218
|
+
when "Show git status" then
|
219
|
+
@opt.status
|
220
|
+
when "Show git logs" then
|
221
|
+
@opt.logs
|
222
|
+
when "Show diff" then
|
223
|
+
@opt.diff
|
224
|
+
when "Restore a file" then
|
225
|
+
@opt.restore
|
226
|
+
when "Reset to a commit" then
|
227
|
+
@opt.reset
|
228
|
+
when "Reset to the last commit" then
|
229
|
+
@opt.hard_reset
|
230
|
+
when "Change branch" then
|
231
|
+
@opt.change_branch
|
232
|
+
when "Remove a file" then
|
233
|
+
@opt.remove_file
|
234
|
+
when "Show the last commit" then
|
235
|
+
@opt.show_last_commit
|
236
|
+
when "Git pull changes" then
|
237
|
+
@opt.pull_changes
|
238
|
+
else
|
239
|
+
abort("Goodbye, closed.")
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
def start
|
244
|
+
loop { show_panel }
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
Run.new
|
249
|
+
end
|