stg 0.1.1 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +79 -12
- data/lib/actions.rb +48 -16
- data/lib/stg.rb +40 -43
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: a24fa114435be573b5b125dc7631052ba02e9b87c071d900aef8be5dd3c771e3
|
|
4
|
+
data.tar.gz: ae2e3189797eb7f737bf2e6f44502458dbf0567d69c8659a1adf18c5a7619a0b
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e9b91105669be9f1b50129e3c347af9c7b9dc6adfd1d476d7c015005db0990927848956587961f16f6e3cd8a134edfc4cf4707ea720bd78423110d807e197e7e
|
|
7
|
+
data.tar.gz: c19cea532598c24f46e8743f6f5af524d087780730b19e1081cc0318dea0ec2a68757effdd440429384e17107abf714161f302f4d9daf90f861a7e0206029fd8
|
data/README.md
CHANGED
|
@@ -10,18 +10,85 @@
|
|
|
10
10
|
|
|
11
11
|
Stolen git is well... you get it. I'm building a mini git clone to learn version control and get comfortable with ruby.
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## Usage
|
|
14
14
|
|
|
15
|
-
| Command
|
|
16
|
-
|
|
|
17
|
-
| init
|
|
18
|
-
| stage
|
|
19
|
-
| commit
|
|
20
|
-
| diff
|
|
21
|
-
| log
|
|
22
|
-
| checkout | check a commit or a branch without loss in data | `-c [--commit] <commit_id>` to check out a commit instaed of a branch wihout changing HEAD pointer |
|
|
23
|
-
| branch | List all branches. (or creating a branch by `branch <name>`) | N/A |
|
|
15
|
+
| Command | description | Flags |
|
|
16
|
+
| ------- | ----------------------------------------------------------------- | --------------------------------------- |
|
|
17
|
+
| init | Initialize the project | N/A |
|
|
18
|
+
| stage | add a file or directory to be tracked | N/A |
|
|
19
|
+
| commit | Save the current tracked state | `-n [--name]` <br> `-d [--description]` |
|
|
20
|
+
| diff | get the difference between working directory and the last commit | N/A |
|
|
21
|
+
| log | print out commit history (limit print by a number `log <number>`) | N/A |
|
|
24
22
|
|
|
25
|
-
|
|
23
|
+
| reset | Reset to the last commit | N/A |
|
|
24
|
+
| checkout | check a commit or a branch without loss in data | `-c [--commit] <commit_id>` to check out a commit instaed of a branch wihout changing HEAD pointer |
|
|
25
|
+
| branch | List all branches. (or creating a branch by `branch <name>`) | N/A |
|
|
26
26
|
|
|
27
|
-
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
1. Make sure you have Ruby installed on your system. You can check by running:
|
|
30
|
+
|
|
31
|
+
```
|
|
32
|
+
ruby -v
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
(If you don't have Ruby, visit [ruby-lang installation](https://www.ruby-lang.org/en/documentation/installation/) to get set up.)
|
|
36
|
+
|
|
37
|
+
2. Install the Gem
|
|
38
|
+
Run the following command in your terminal:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
gem install stg
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Run `stg` to verify your installation
|
|
45
|
+
|
|
46
|
+
## Examples
|
|
47
|
+
|
|
48
|
+
> [!NOTE]
|
|
49
|
+
> You have to initialize with `stg init` for any of the other commands to work
|
|
50
|
+
|
|
51
|
+
- Initialization
|
|
52
|
+
|
|
53
|
+
```
|
|
54
|
+
stg init
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
- Staging
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
stg stage src/page.ts
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
- Committing
|
|
64
|
+
|
|
65
|
+
```
|
|
66
|
+
stg commit -n "Adding main page"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
- Logging all commits
|
|
70
|
+
|
|
71
|
+
```
|
|
72
|
+
stg log
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Logging last 5 commits
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
stg log 5
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
- Help
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
stg
|
|
85
|
+
or
|
|
86
|
+
stg help
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
- Hard reset
|
|
90
|
+
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
stg
|
|
94
|
+
```
|
data/lib/actions.rb
CHANGED
|
@@ -54,14 +54,16 @@ module Actions
|
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def stage
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
inp = ARGV
|
|
58
|
+
|
|
59
|
+
if inp.empty?
|
|
60
|
+
puts 'Usage: stg stage <directory/> <file.xy>'
|
|
60
61
|
return
|
|
61
62
|
end
|
|
62
63
|
|
|
63
64
|
index = JSON.parse(File.read('.stolen-git/index.json'))
|
|
64
|
-
|
|
65
|
+
|
|
66
|
+
stage_file = lambda do |file_path|
|
|
65
67
|
file_hash = get_file_hash(file_path)
|
|
66
68
|
file_content = File.read(file_path)
|
|
67
69
|
|
|
@@ -75,6 +77,32 @@ module Actions
|
|
|
75
77
|
index[file_path] ||= default_index_obj
|
|
76
78
|
index[file_path]['hash'] = file_hash
|
|
77
79
|
end
|
|
80
|
+
|
|
81
|
+
stage_directory = lambda do |dir_path|
|
|
82
|
+
Dir.children(dir_path).each do |entry|
|
|
83
|
+
path = File.join(dir_path, entry)
|
|
84
|
+
if File.file?(path)
|
|
85
|
+
stage_file.call(path)
|
|
86
|
+
else
|
|
87
|
+
stage_directory.call(path)
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
inp.each do |inp_path|
|
|
93
|
+
unless File.exist? inp_path
|
|
94
|
+
puts "#{inp_path} doesn't exist"
|
|
95
|
+
next
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
if File.file?(inp_path)
|
|
99
|
+
stage_file.call(inp_path)
|
|
100
|
+
elsif File.directory? inp_path
|
|
101
|
+
stage_directory.call(inp_path)
|
|
102
|
+
else
|
|
103
|
+
puts "Error logging #{inp_path}. It's neither a file or a directory"
|
|
104
|
+
end
|
|
105
|
+
end
|
|
78
106
|
index = index.sort.to_h
|
|
79
107
|
File.write('.stolen-git/index.json', JSON.pretty_generate(index))
|
|
80
108
|
end
|
|
@@ -84,7 +112,7 @@ module Actions
|
|
|
84
112
|
|
|
85
113
|
# Getting commit name & description
|
|
86
114
|
OptionParser.new do |opts|
|
|
87
|
-
opts.banner = 'Usage:
|
|
115
|
+
opts.banner = 'Usage: stg commit [options]'
|
|
88
116
|
|
|
89
117
|
opts.on('-n', '--name NAME', 'Add a commit name') do |name|
|
|
90
118
|
options[:name] = name
|
|
@@ -221,18 +249,22 @@ module Actions
|
|
|
221
249
|
branch_id = pointer['point_to']
|
|
222
250
|
branch_content = read_json(".stolen-git/branches/#{branch_id}.json")
|
|
223
251
|
current_commit_hash = branch_content['commit_pointer']
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
252
|
+
|
|
253
|
+
new_commit = if !commit_id || commit_id.empty?
|
|
254
|
+
current_commit_hash
|
|
255
|
+
else
|
|
256
|
+
commit_history['commits'].find do |x|
|
|
257
|
+
x['id'] == commit_id
|
|
258
|
+
end['hash']
|
|
259
|
+
end
|
|
260
|
+
|
|
261
|
+
if new_commit.empty?
|
|
262
|
+
puts "This commit doesn't exit"
|
|
232
263
|
return
|
|
233
264
|
end
|
|
234
|
-
|
|
235
|
-
|
|
265
|
+
|
|
266
|
+
revert_to_commit(new_commit)
|
|
267
|
+
branch_content['commit_pointer'] = new_commit
|
|
236
268
|
File.write(".stolen-git/branches/#{branch_id}.json", JSON.pretty_generate(branch_content))
|
|
237
269
|
end
|
|
238
270
|
|
|
@@ -241,7 +273,7 @@ module Actions
|
|
|
241
273
|
|
|
242
274
|
# Getting commit name & description
|
|
243
275
|
OptionParser.new do |opts|
|
|
244
|
-
opts.banner = 'Usage:
|
|
276
|
+
opts.banner = 'Usage: stg checkout [options]'
|
|
245
277
|
|
|
246
278
|
opts.on('-c', '--commit', 'Add a commit id instead') do
|
|
247
279
|
options[:commit] = true
|
data/lib/stg.rb
CHANGED
|
@@ -1,47 +1,44 @@
|
|
|
1
1
|
require_relative 'help'
|
|
2
2
|
require_relative 'actions'
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
when '
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
when 'stage'
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
when '
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
else
|
|
45
|
-
puts "Unknown command: #{command}"
|
|
46
|
-
exit 1
|
|
4
|
+
module Stg
|
|
5
|
+
class CLI
|
|
6
|
+
extend Actions
|
|
7
|
+
extend Help
|
|
8
|
+
|
|
9
|
+
def self.start
|
|
10
|
+
command = ARGV.shift
|
|
11
|
+
case command
|
|
12
|
+
when 'init'
|
|
13
|
+
p_initialize
|
|
14
|
+
when 'commit'
|
|
15
|
+
commit
|
|
16
|
+
when 'diff'
|
|
17
|
+
diff
|
|
18
|
+
when 'test'
|
|
19
|
+
test
|
|
20
|
+
when 'stage'
|
|
21
|
+
stage
|
|
22
|
+
when 'check_router'
|
|
23
|
+
check_router
|
|
24
|
+
when 'reset'
|
|
25
|
+
reset
|
|
26
|
+
when 'log'
|
|
27
|
+
log
|
|
28
|
+
when 'checkout'
|
|
29
|
+
checkout
|
|
30
|
+
when 'branch'
|
|
31
|
+
branch
|
|
32
|
+
when 'help'
|
|
33
|
+
puts print_usage
|
|
34
|
+
exit 1
|
|
35
|
+
when nil
|
|
36
|
+
puts print_usage
|
|
37
|
+
exit 1
|
|
38
|
+
else
|
|
39
|
+
puts "Unknown command: #{command}"
|
|
40
|
+
exit 1
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
47
44
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: stg
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Amr ElTaweel
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-
|
|
11
|
+
date: 2026-05-02 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: colorize
|