gitoc 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rspec +3 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +35 -0
- data/Rakefile +8 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/exe/gitoc +5 -0
- data/gitoc.gemspec +37 -0
- data/lib/gitoc/cli.rb +118 -0
- data/lib/gitoc/repository.rb +59 -0
- data/lib/gitoc/version.rb +5 -0
- data/lib/gitoc.rb +11 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: bef45ac911fb315a1dbcf743edfff6dc8f49cc621662e4b410de4807c4e81142
|
4
|
+
data.tar.gz: 8f0fc609562e69ca190a350d84d935c26a920d5472dd6beabbe011348d043ec6
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0e72e70f2813c6193334f027b7f5c28491f0aa9692d6f3b896f9a285ea61c5429a71c163e2629b850f9234a305dda9803afdaf9996ef387e24d770b75b5bb8be
|
7
|
+
data.tar.gz: e5aa5b03fd8e363204fda516c58a59aee3ccae36f1a7d47c480d6691bca4d534a094dc4123c4d7e0bbde29dad496215b80e914e93f66439a2951581f85d0e990
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Patrick Marchi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
# Gitoc
|
2
|
+
|
3
|
+
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.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install gitoc
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
The local directory tree of your git repositories defaults to `~/git` and the default GiTOC file path is set to `~/.gitoc.yaml`. Use `--base=DIRECTORY` and `--toc=GiTOC-FILE` to overwrite these defaults.
|
12
|
+
|
13
|
+
First you have to generate a GiTOC file with
|
14
|
+
|
15
|
+
$ gitoc dump
|
16
|
+
|
17
|
+
Then you can run things on your local repositories
|
18
|
+
|
19
|
+
# Run git pull on all your repositories
|
20
|
+
$ gitoc pull
|
21
|
+
|
22
|
+
# Clone all git repositories to a new location using the same directory structure specified in your GiTOC file.
|
23
|
+
|
24
|
+
# ... to a new location on the same computer
|
25
|
+
$ gitoc clone --base=NEW-DIRECTORY
|
26
|
+
|
27
|
+
# ... to a new computer (copy/move your GiTOC file first)
|
28
|
+
$ gitoc clone
|
29
|
+
|
30
|
+
# Check your GiTOC file
|
31
|
+
$ gitoc check
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/gitoc.
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "gitoc"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/exe/gitoc
ADDED
data/gitoc.gemspec
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "lib/gitoc/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "gitoc"
|
7
|
+
spec.version = Gitoc::VERSION
|
8
|
+
spec.authors = ["Patrick Marchi"]
|
9
|
+
spec.email = ["mail@patrickmarchi.ch"]
|
10
|
+
|
11
|
+
spec.summary = [spec.name, spec.version].join(" ")
|
12
|
+
spec.description = "Manage git repositories in directory tree."
|
13
|
+
spec.homepage = "https://github.com/pmarchi/gitoc"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.4.0"
|
16
|
+
|
17
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
18
|
+
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
21
|
+
spec.metadata["changelog_uri"] = File.join(spec.homepage, "blob/main/CHANGELOG.md")
|
22
|
+
|
23
|
+
# Specify which files should be added to the gem when it is released.
|
24
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
27
|
+
end
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
|
32
|
+
# Uncomment to register a new dependency of your gem
|
33
|
+
spec.add_dependency "thor"
|
34
|
+
|
35
|
+
# For more information and examples about making a new gem, checkout our
|
36
|
+
# guide at: https://bundler.io/guides/creating_gem.html
|
37
|
+
end
|
data/lib/gitoc/cli.rb
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
require "pathname"
|
2
|
+
require "yaml"
|
3
|
+
require "thor"
|
4
|
+
|
5
|
+
class Gitoc::Cli < Thor
|
6
|
+
include Thor::Actions
|
7
|
+
|
8
|
+
class_option :base, default: "~/git", desc: "Local git base directory"
|
9
|
+
class_option :toc, default: "~/.gitoc.yaml", desc: "GiTOC file"
|
10
|
+
|
11
|
+
desc "check", "Check GiTOC file"
|
12
|
+
def check
|
13
|
+
init_base
|
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]
|
19
|
+
end
|
20
|
+
|
21
|
+
print_table list
|
22
|
+
end
|
23
|
+
|
24
|
+
desc "dump", "Recursively scan base for git repositories and generate GiTOC file"
|
25
|
+
def dump
|
26
|
+
init_base
|
27
|
+
|
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)
|
31
|
+
|
32
|
+
# Write git_toc file
|
33
|
+
gitoc.write toc.to_yaml
|
34
|
+
puts "Write #{gitoc}"
|
35
|
+
end
|
36
|
+
|
37
|
+
desc "clone", "Read GiTOC file and clone all repositories"
|
38
|
+
def clone
|
39
|
+
init_base
|
40
|
+
|
41
|
+
each_repository do |repo|
|
42
|
+
if repo.exist?
|
43
|
+
say "Skip repository, #{repo.path} already exists.", :red
|
44
|
+
next
|
45
|
+
end
|
46
|
+
|
47
|
+
repo.clone
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
desc "pull", "Read GiTOC file and pull all repositories"
|
52
|
+
def pull
|
53
|
+
init_base
|
54
|
+
|
55
|
+
each_repository do |repo|
|
56
|
+
unless repo.exist?
|
57
|
+
say "Skip repository, #{repo.path} doesn't exist.", :red
|
58
|
+
next
|
59
|
+
end
|
60
|
+
|
61
|
+
repo.pull
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "clone-or-pull", "Read GiTOC file and clone/pull all repositories"
|
66
|
+
def clone_or_pull
|
67
|
+
init_base
|
68
|
+
|
69
|
+
each_repository do |repo|
|
70
|
+
if repo.exist?
|
71
|
+
repo.pull
|
72
|
+
else
|
73
|
+
repo.clone
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def init_base
|
81
|
+
Gitoc::Repository.base = Pathname.new(options[:base]).expand_path
|
82
|
+
end
|
83
|
+
|
84
|
+
def gitoc
|
85
|
+
@gitoc ||= Pathname.new(options[:toc]).expand_path
|
86
|
+
end
|
87
|
+
|
88
|
+
def repositories
|
89
|
+
@repositories ||= begin
|
90
|
+
unless gitoc.exist?
|
91
|
+
say "#{gitoc} not found", :red
|
92
|
+
exit 1
|
93
|
+
end
|
94
|
+
|
95
|
+
YAML.load_file(gitoc).map do |attributes|
|
96
|
+
Gitoc::Repository.load attributes
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def each_repository
|
102
|
+
repositories.each_with_index do |repo, index|
|
103
|
+
puts
|
104
|
+
say "~/#{repo.path.relative_path_from(home)} (#{index + 1}/#{repositories.count})", :cyan
|
105
|
+
|
106
|
+
unless repo.url?
|
107
|
+
say "Skip repository with no remote.origin.url", :red
|
108
|
+
next
|
109
|
+
end
|
110
|
+
|
111
|
+
yield repo
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
def home
|
116
|
+
@home ||= Pathname.new(ENV["HOME"])
|
117
|
+
end
|
118
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require "open3"
|
2
|
+
require "pathname"
|
3
|
+
|
4
|
+
class Gitoc::Repository
|
5
|
+
class << self
|
6
|
+
attr_accessor :base
|
7
|
+
|
8
|
+
def load attribute
|
9
|
+
new base.join(attribute[:path]), attribute[:url]
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# Path to the git repository
|
14
|
+
attr_reader :path
|
15
|
+
|
16
|
+
def initialize path, url = nil
|
17
|
+
@path = Pathname.new(path).expand_path
|
18
|
+
@url = url
|
19
|
+
end
|
20
|
+
|
21
|
+
def to_hash
|
22
|
+
{
|
23
|
+
path: path.relative_path_from(self.class.base).to_s,
|
24
|
+
url: url
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def exist?
|
29
|
+
path.exist?
|
30
|
+
end
|
31
|
+
|
32
|
+
def url?
|
33
|
+
!(url.nil? || url.empty?)
|
34
|
+
end
|
35
|
+
|
36
|
+
def url
|
37
|
+
@url ||= begin
|
38
|
+
out, _status = run_in path, "git config remote.origin.url"
|
39
|
+
out.chomp
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def clone
|
44
|
+
return unless url?
|
45
|
+
path.parent.mkpath
|
46
|
+
run_in path.parent, "git clone #{url}"
|
47
|
+
end
|
48
|
+
|
49
|
+
def pull
|
50
|
+
return unless exist?
|
51
|
+
run_in path, "git pull"
|
52
|
+
end
|
53
|
+
|
54
|
+
def run_in path, cmd
|
55
|
+
Dir.chdir path do
|
56
|
+
Open3.capture2 cmd
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
data/lib/gitoc.rb
ADDED
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitoc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Patrick Marchi
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-10-26 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
description: Manage git repositories in directory tree.
|
28
|
+
email:
|
29
|
+
- mail@patrickmarchi.ch
|
30
|
+
executables:
|
31
|
+
- gitoc
|
32
|
+
extensions: []
|
33
|
+
extra_rdoc_files: []
|
34
|
+
files:
|
35
|
+
- ".gitignore"
|
36
|
+
- ".rspec"
|
37
|
+
- CHANGELOG.md
|
38
|
+
- Gemfile
|
39
|
+
- LICENSE.txt
|
40
|
+
- README.md
|
41
|
+
- Rakefile
|
42
|
+
- bin/console
|
43
|
+
- bin/setup
|
44
|
+
- exe/gitoc
|
45
|
+
- gitoc.gemspec
|
46
|
+
- lib/gitoc.rb
|
47
|
+
- lib/gitoc/cli.rb
|
48
|
+
- lib/gitoc/repository.rb
|
49
|
+
- lib/gitoc/version.rb
|
50
|
+
homepage: https://github.com/pmarchi/gitoc
|
51
|
+
licenses:
|
52
|
+
- MIT
|
53
|
+
metadata:
|
54
|
+
allowed_push_host: https://rubygems.org
|
55
|
+
homepage_uri: https://github.com/pmarchi/gitoc
|
56
|
+
source_code_uri: https://github.com/pmarchi/gitoc
|
57
|
+
changelog_uri: https://github.com/pmarchi/gitoc/blob/main/CHANGELOG.md
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: 2.4.0
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.1.6
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: gitoc 0.2.0
|
77
|
+
test_files: []
|