stg 0.1.1 → 0.1.2
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 +51 -16
- 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: 230caddab1e3d4399c0b45c216170abce501826f39b0b64e760423c9ac09b0e5
|
|
4
|
+
data.tar.gz: 43ab838f4b5de8ab7c68fa51cd6ae895bf13eaf1e1de1d51f0e64cf04af7cd87
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a0f834b3a3de3f1717c4ec41384aa4170323f85a84732f498d788d95bbb70b054c225096961016bc2869b10736278cc1714f8e7d256927c929ba2572da5e0e43
|
|
7
|
+
data.tar.gz: 84e35003956f79895a4ac410fb80dd8c40c8fa33b6e724decaf2b56a095c5decac87433dccc363ccf9bf793acfe0509dcd71c10190aab742bd1b4ceb1aad8dea
|
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
|
+
define_method(:stage_file) 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,35 @@ module Actions
|
|
|
75
77
|
index[file_path] ||= default_index_obj
|
|
76
78
|
index[file_path]['hash'] = file_hash
|
|
77
79
|
end
|
|
80
|
+
|
|
81
|
+
define_method(:stage_directory) do |dir_path|
|
|
82
|
+
Dir.children(dir_path).each do |entry|
|
|
83
|
+
# puts "entry: #{entry}"
|
|
84
|
+
path = File.join(dir_path, entry)
|
|
85
|
+
if File.file?(path)
|
|
86
|
+
# puts "entry_file: #{path}"
|
|
87
|
+
stage_file(path)
|
|
88
|
+
else
|
|
89
|
+
# puts "entry_dir: #{path}"
|
|
90
|
+
stage_directory(path)
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
inp.each do |inp_path|
|
|
96
|
+
unless File.exist? inp_path
|
|
97
|
+
puts "#{inp_path} doesn't exist"
|
|
98
|
+
next
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
if File.file?(inp_path)
|
|
102
|
+
stage_file(inp_path)
|
|
103
|
+
elsif File.directory? inp_path
|
|
104
|
+
stage_directory(inp_path)
|
|
105
|
+
else
|
|
106
|
+
puts "Error logging #{inp_path}. It's neither a file or a directory"
|
|
107
|
+
end
|
|
108
|
+
end
|
|
78
109
|
index = index.sort.to_h
|
|
79
110
|
File.write('.stolen-git/index.json', JSON.pretty_generate(index))
|
|
80
111
|
end
|
|
@@ -84,7 +115,7 @@ module Actions
|
|
|
84
115
|
|
|
85
116
|
# Getting commit name & description
|
|
86
117
|
OptionParser.new do |opts|
|
|
87
|
-
opts.banner = 'Usage:
|
|
118
|
+
opts.banner = 'Usage: stg commit [options]'
|
|
88
119
|
|
|
89
120
|
opts.on('-n', '--name NAME', 'Add a commit name') do |name|
|
|
90
121
|
options[:name] = name
|
|
@@ -221,18 +252,22 @@ module Actions
|
|
|
221
252
|
branch_id = pointer['point_to']
|
|
222
253
|
branch_content = read_json(".stolen-git/branches/#{branch_id}.json")
|
|
223
254
|
current_commit_hash = branch_content['commit_pointer']
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
255
|
+
|
|
256
|
+
new_commit = if !commit_id || commit_id.empty?
|
|
257
|
+
current_commit_hash
|
|
258
|
+
else
|
|
259
|
+
commit_history['commits'].find do |x|
|
|
260
|
+
x['id'] == commit_id
|
|
261
|
+
end['hash']
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
if new_commit.empty?
|
|
265
|
+
puts "This commit doesn't exit"
|
|
232
266
|
return
|
|
233
267
|
end
|
|
234
|
-
|
|
235
|
-
|
|
268
|
+
|
|
269
|
+
revert_to_commit(new_commit)
|
|
270
|
+
branch_content['commit_pointer'] = new_commit
|
|
236
271
|
File.write(".stolen-git/branches/#{branch_id}.json", JSON.pretty_generate(branch_content))
|
|
237
272
|
end
|
|
238
273
|
|
|
@@ -241,7 +276,7 @@ module Actions
|
|
|
241
276
|
|
|
242
277
|
# Getting commit name & description
|
|
243
278
|
OptionParser.new do |opts|
|
|
244
|
-
opts.banner = 'Usage:
|
|
279
|
+
opts.banner = 'Usage: stg checkout [options]'
|
|
245
280
|
|
|
246
281
|
opts.on('-c', '--commit', 'Add a commit id instead') do
|
|
247
282
|
options[:commit] = true
|
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.2
|
|
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
|