gitoc 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -0
- data/lib/gitoc/cli.rb +42 -17
- data/lib/gitoc/repository.rb +9 -1
- data/lib/gitoc/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 513d44a622185a25c2b61a76fc13428929270accd5a0b6d3d18c3486a1a091b5
|
4
|
+
data.tar.gz: 3098d79bbf8b4c9d0e2ee94e3364e2605068f511f9b4244a1548940da95e276a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e47a187855854a4649e51239b185ab44a2201f302d632c1f88f3fa50b55899a6c244385e206b8f246c97b0544b23671166da58de9f56cfc943a3840fa291325d
|
7
|
+
data.tar.gz: fe55eba056525dfafca3bce14bf14103a9ddc45d7f1cd6bfe9336f6663ddd6a80dc0eff1da108e246f3f82a63ad1f3c611a40b4206a0227409f617f189ba827f
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/gitoc.svg)](https://badge.fury.io/rb/gitoc)
|
2
|
+
|
1
3
|
# Gitoc
|
2
4
|
|
3
5
|
GiTOC generates a table of contents from a local directory tree of git repositories. Use this GiTOC file to clone all your git repositories to a new location (computer) or run a command on all your repositories.
|
data/lib/gitoc/cli.rb
CHANGED
@@ -8,26 +8,45 @@ class Gitoc::Cli < Thor
|
|
8
8
|
class_option :base, default: "~/git", desc: "Local git base directory"
|
9
9
|
class_option :toc, default: "~/.gitoc.yaml", desc: "GiTOC file"
|
10
10
|
|
11
|
-
desc "check", "Check GiTOC file"
|
11
|
+
desc "check", "Check local repositories and GiTOC file"
|
12
12
|
def check
|
13
13
|
init_base
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
[
|
15
|
+
# Get all repositories from the filesystem
|
16
|
+
# and tag them with :fs
|
17
|
+
repositories = repositories_fs.map do |repository_fs|
|
18
|
+
[repository_fs, [:fs]]
|
19
19
|
end
|
20
20
|
|
21
|
-
|
21
|
+
# Add missing repositories from the GiTOC file
|
22
|
+
# and tag all repositories from the GiTOC file with :toc
|
23
|
+
repositories_gitoc.each do |repository_gitoc|
|
24
|
+
_, tags = repositories.find {|repository_fs, _| repository_fs == repository_gitoc }
|
25
|
+
if tags
|
26
|
+
tags << :toc
|
27
|
+
else
|
28
|
+
repositories << [repository_gitoc, [:toc]]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# Sort repositories list
|
33
|
+
# and build table rows: [path, url, comment]
|
34
|
+
rows = repositories.sort_by {|repository, _| repository.rel_path }.map do |repository, tags|
|
35
|
+
path, url = repository.to_hash.values
|
36
|
+
url = "-" if url.nil? || url.empty?
|
37
|
+
comment = tags.include?(:fs) && tags.include?(:toc) ? "" : {fs: "not in GiTOC", toc: "not on filesystem"}[tags.first]
|
38
|
+
|
39
|
+
[path, url, comment]
|
40
|
+
end
|
41
|
+
|
42
|
+
print_table rows
|
22
43
|
end
|
23
44
|
|
24
|
-
desc "
|
25
|
-
def
|
45
|
+
desc "generate", "Recursively scan base for git repositories and generate/update GiTOC file"
|
46
|
+
def generate
|
26
47
|
init_base
|
27
48
|
|
28
|
-
toc =
|
29
|
-
Gitoc::Repository.new(git_dir.parent)
|
30
|
-
end.sort_by(&:path).map(&:to_hash)
|
49
|
+
toc = repositories_fs.map(&:to_hash)
|
31
50
|
|
32
51
|
# Write git_toc file
|
33
52
|
gitoc.write toc.to_yaml
|
@@ -40,7 +59,7 @@ class Gitoc::Cli < Thor
|
|
40
59
|
|
41
60
|
each_repository do |repo|
|
42
61
|
if repo.exist?
|
43
|
-
|
62
|
+
puts "Skip repository, #{repo.path} already exists."
|
44
63
|
next
|
45
64
|
end
|
46
65
|
|
@@ -54,7 +73,7 @@ class Gitoc::Cli < Thor
|
|
54
73
|
|
55
74
|
each_repository do |repo|
|
56
75
|
unless repo.exist?
|
57
|
-
|
76
|
+
puts "Skip repository, #{repo.path} doesn't exist."
|
58
77
|
next
|
59
78
|
end
|
60
79
|
|
@@ -85,8 +104,8 @@ class Gitoc::Cli < Thor
|
|
85
104
|
@gitoc ||= Pathname.new(options[:toc]).expand_path
|
86
105
|
end
|
87
106
|
|
88
|
-
def
|
89
|
-
@
|
107
|
+
def repositories_gitoc
|
108
|
+
@repositories_gitoc ||= begin
|
90
109
|
unless gitoc.exist?
|
91
110
|
say "#{gitoc} not found", :red
|
92
111
|
exit 1
|
@@ -98,10 +117,16 @@ class Gitoc::Cli < Thor
|
|
98
117
|
end
|
99
118
|
end
|
100
119
|
|
120
|
+
def repositories_fs
|
121
|
+
@repositories_fs ||= Gitoc::Repository.base.glob("**/.git").map do |git_dir|
|
122
|
+
Gitoc::Repository.new(git_dir.parent)
|
123
|
+
end.sort_by(&:path)
|
124
|
+
end
|
125
|
+
|
101
126
|
def each_repository
|
102
|
-
|
127
|
+
repositories_gitoc.each_with_index do |repo, index|
|
103
128
|
puts
|
104
|
-
say "~/#{repo.path.relative_path_from(home)} (#{index + 1}/#{
|
129
|
+
say "~/#{repo.path.relative_path_from(home)} (#{index + 1}/#{repositories_gitoc.count})", :cyan
|
105
130
|
|
106
131
|
unless repo.url?
|
107
132
|
say "Skip repository with no remote.origin.url", :red
|
data/lib/gitoc/repository.rb
CHANGED
@@ -18,9 +18,17 @@ class Gitoc::Repository
|
|
18
18
|
@url = url
|
19
19
|
end
|
20
20
|
|
21
|
+
def == other
|
22
|
+
self.to_hash == other.to_hash
|
23
|
+
end
|
24
|
+
|
25
|
+
def rel_path
|
26
|
+
@rel_path ||= path.relative_path_from(self.class.base)
|
27
|
+
end
|
28
|
+
|
21
29
|
def to_hash
|
22
30
|
{
|
23
|
-
path:
|
31
|
+
path: rel_path.to_s,
|
24
32
|
url: url
|
25
33
|
}
|
26
34
|
end
|
data/lib/gitoc/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrick Marchi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -70,8 +70,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|
73
|
-
rubygems_version: 3.
|
73
|
+
rubygems_version: 3.2.22
|
74
74
|
signing_key:
|
75
75
|
specification_version: 4
|
76
|
-
summary: gitoc 0.
|
76
|
+
summary: gitoc 0.4.0
|
77
77
|
test_files: []
|