gitoc 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d8b6b5dd358d217cb2ba8ad12dd703789d5247a083e129bc86d5875756f27493
4
- data.tar.gz: 5d7867eca5b70d823a240ed4bf80e6ed324d9b9e3e586775e0f7eb8388e9bfc6
3
+ metadata.gz: 513d44a622185a25c2b61a76fc13428929270accd5a0b6d3d18c3486a1a091b5
4
+ data.tar.gz: 3098d79bbf8b4c9d0e2ee94e3364e2605068f511f9b4244a1548940da95e276a
5
5
  SHA512:
6
- metadata.gz: d1a30f8ef8937307c43e0fd9bee373c9128011b8ef7fca067ca50325788eb0c7c42b917dc03d0de5123f65301f30598720c8ff278acebf6f0260bfe13c0658bb
7
- data.tar.gz: 8054851334fd52afd83c2afa1375a91c046b50cc36e6d93e9905b526a33f689b1ab655e71b9b591918833ba4e37769e6c9efa6724f6ad3751ab5cf8290f6ebec
6
+ metadata.gz: e47a187855854a4649e51239b185ab44a2201f302d632c1f88f3fa50b55899a6c244385e206b8f246c97b0544b23671166da58de9f56cfc943a3840fa291325d
7
+ data.tar.gz: fe55eba056525dfafca3bce14bf14103a9ddc45d7f1cd6bfe9336f6663ddd6a80dc0eff1da108e246f3f82a63ad1f3c611a40b4206a0227409f617f189ba827f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## Release v0.4.0 (17 Nov 2021)
2
+
3
+ * gitoc check scans the filesystem and the GiTOC file
4
+ * gitoc generate replaces gitoc dump
5
+
6
+
1
7
  ## Release v0.3.0 (26 Oct 2021)
2
8
 
3
9
  * first public release
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
- list = repositories.map do |repo|
16
- path, url = repo.to_hash.values
17
- path = set_color(path, :red) if url.nil? || url.empty?
18
- [path, url]
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
- print_table list
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 "dump", "Recursively scan base for git repositories and generate GiTOC file"
25
- def dump
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 = Gitoc::Repository.base.glob("**/.git").map do |git_dir|
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
- say "Skip repository, #{repo.path} already exists.", :red
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
- say "Skip repository, #{repo.path} doesn't exist.", :red
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 repositories
89
- @repositories ||= begin
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
- repositories.each_with_index do |repo, index|
127
+ repositories_gitoc.each_with_index do |repo, index|
103
128
  puts
104
- say "~/#{repo.path.relative_path_from(home)} (#{index + 1}/#{repositories.count})", :cyan
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
@@ -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: path.relative_path_from(self.class.base).to_s,
31
+ path: rel_path.to_s,
24
32
  url: url
25
33
  }
26
34
  end
data/lib/gitoc/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Gitoc
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
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.3.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-10-26 00:00:00.000000000 Z
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.1.6
73
+ rubygems_version: 3.2.22
74
74
  signing_key:
75
75
  specification_version: 4
76
- summary: gitoc 0.3.0
76
+ summary: gitoc 0.4.0
77
77
  test_files: []