dorian-git-tree 0.3.2 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/git-tree +61 -2
- metadata +19 -6
- data/lib/dorian/git/tree.rb +0 -79
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4bc2379bc6a4479fab44b8445488de106eceda00467633a8b3da63609c3818e
|
4
|
+
data.tar.gz: 449dd3fb52f36dcf7b992e69642dcdecf721232e01a42e9e5f2aaeb68840c861
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 33e48042b40e400fcf610ed35520294256fa64b5e0da0379be06b87566e6372038a011c884d757f4fb03616673511e5637cade0e4765a65039b4069e08407e5c
|
7
|
+
data.tar.gz: d3dcade7ca4465db565af515b6c67077cac2bdd78891746c4649d58721a112bc3c8130b2a9ccfa4eac5fcaedb1067cc9e5edf144ed6f20a59db9f6fd2c3cb96f
|
data/bin/git-tree
CHANGED
@@ -1,5 +1,64 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
|
-
require "
|
5
|
-
|
4
|
+
require "git"
|
5
|
+
|
6
|
+
SPACE = " "
|
7
|
+
RIGHT = "└── "
|
8
|
+
DOWN = "│ "
|
9
|
+
DOWN_AND_RIGHT = "├── "
|
10
|
+
|
11
|
+
def git_ls_files(path)
|
12
|
+
Git.open(".").ls_files(path).map(&:first)
|
13
|
+
end
|
14
|
+
|
15
|
+
def group(files)
|
16
|
+
files
|
17
|
+
.group_by { |file| file.split("/").first }
|
18
|
+
.transform_values do |values|
|
19
|
+
group(
|
20
|
+
values.map { |value| value.split("/")[1..].join("/") }.reject(&:empty?)
|
21
|
+
)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def print(key:, values:, index: 0, size: 1, prefix: "")
|
26
|
+
key = "#{key}/" if values.any?
|
27
|
+
last = index + 1 == size
|
28
|
+
right_prefix = last ? RIGHT : DOWN_AND_RIGHT
|
29
|
+
puts prefix + right_prefix + key
|
30
|
+
values.each.with_index do |(value_key, value_values), value_index|
|
31
|
+
print(
|
32
|
+
key: value_key,
|
33
|
+
values: value_values,
|
34
|
+
index: value_index,
|
35
|
+
size: values.size,
|
36
|
+
prefix: prefix + (last ? SPACE : DOWN)
|
37
|
+
)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
if ARGV[0] == "--help" || ARGV[0] == "-h" || ARGV.size > 1
|
42
|
+
puts "USAGE: git tree [PATH]"
|
43
|
+
exit
|
44
|
+
end
|
45
|
+
|
46
|
+
key = ARGV.first || "."
|
47
|
+
|
48
|
+
files =
|
49
|
+
git_ls_files(key).map { |file| ARGV.first ? file.sub(ARGV.first, "") : file }
|
50
|
+
|
51
|
+
values = group(files)
|
52
|
+
|
53
|
+
key = "#{key}/" if values.any? && key != "." && key[-1] != "/"
|
54
|
+
|
55
|
+
puts key
|
56
|
+
|
57
|
+
values.each.with_index do |(value_key, value_values), value_index|
|
58
|
+
print(
|
59
|
+
key: value_key,
|
60
|
+
values: value_values,
|
61
|
+
index: value_index,
|
62
|
+
size: values.size
|
63
|
+
)
|
64
|
+
end
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dorian-git-tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-03
|
12
|
-
dependencies:
|
11
|
+
date: 2024-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: git
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1'
|
13
27
|
description: |-
|
14
28
|
Lists your files and directories in your git repository as a tree
|
15
29
|
|
@@ -21,8 +35,7 @@ extensions: []
|
|
21
35
|
extra_rdoc_files: []
|
22
36
|
files:
|
23
37
|
- bin/git-tree
|
24
|
-
|
25
|
-
homepage: https://github.com/dorianmariecom/git-tree
|
38
|
+
homepage: https://github.com/dorianmariecom/dorian-git-tree
|
26
39
|
licenses:
|
27
40
|
- MIT
|
28
41
|
metadata:
|
@@ -35,7 +48,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
35
48
|
requirements:
|
36
49
|
- - ">="
|
37
50
|
- !ruby/object:Gem::Version
|
38
|
-
version:
|
51
|
+
version: 3.3.0
|
39
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
53
|
requirements:
|
41
54
|
- - ">="
|
data/lib/dorian/git/tree.rb
DELETED
@@ -1,79 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "English"
|
4
|
-
|
5
|
-
require "shellwords"
|
6
|
-
|
7
|
-
module Dorian
|
8
|
-
module Git
|
9
|
-
class Tree
|
10
|
-
SPACE = " "
|
11
|
-
RIGHT = "└── "
|
12
|
-
DOWN = "│ "
|
13
|
-
DOWN_AND_RIGHT = "├── "
|
14
|
-
|
15
|
-
def self.run
|
16
|
-
if ARGV[0] == "--help" || ARGV[0] == "-h" || ARGV.size > 1
|
17
|
-
puts "USAGE: git tree [PATH]"
|
18
|
-
exit
|
19
|
-
end
|
20
|
-
|
21
|
-
key = ARGV.first || "."
|
22
|
-
|
23
|
-
files =
|
24
|
-
git_ls_files(key).map do |file|
|
25
|
-
ARGV.first ? file.sub(ARGV.first, "") : file
|
26
|
-
end
|
27
|
-
|
28
|
-
values = group(files)
|
29
|
-
|
30
|
-
key = "#{key}/" if values.any? && key != "." && key[-1] != "/"
|
31
|
-
|
32
|
-
puts key
|
33
|
-
|
34
|
-
values.each.with_index do |(value_key, value_values), value_index|
|
35
|
-
print(
|
36
|
-
key: value_key,
|
37
|
-
values: value_values,
|
38
|
-
index: value_index,
|
39
|
-
size: values.size
|
40
|
-
)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
def self.git_ls_files(path)
|
45
|
-
result = `#{["git", "ls-files", path].compact.shelljoin}`.split("\n")
|
46
|
-
exit $CHILD_STATUS.exitstatus if $CHILD_STATUS.exitstatus.positive?
|
47
|
-
result
|
48
|
-
end
|
49
|
-
|
50
|
-
def self.group(files)
|
51
|
-
files
|
52
|
-
.group_by { |file| file.split("/").first }
|
53
|
-
.transform_values do |values|
|
54
|
-
group(
|
55
|
-
values
|
56
|
-
.map { |value| value.split("/")[1..].join("/") }
|
57
|
-
.reject(&:empty?)
|
58
|
-
)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def self.print(key:, values:, index: 0, size: 1, prefix: "")
|
63
|
-
key = "#{key}/" if values.any?
|
64
|
-
last = index + 1 == size
|
65
|
-
right_prefix = last ? RIGHT : DOWN_AND_RIGHT
|
66
|
-
puts prefix + right_prefix + key
|
67
|
-
values.each.with_index do |(value_key, value_values), value_index|
|
68
|
-
print(
|
69
|
-
key: value_key,
|
70
|
-
values: value_values,
|
71
|
-
index: value_index,
|
72
|
-
size: values.size,
|
73
|
-
prefix: prefix + (last ? SPACE : DOWN)
|
74
|
-
)
|
75
|
-
end
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|