git_tree 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +17 -13
- data/git_tree.gemspec +1 -1
- data/lib/git_tree/version.rb +1 -1
- data/lib/git_tree_evars.rb +32 -15
- data/lib/git_tree_replicate.rb +28 -10
- metadata +6 -6
- /data/bindir/{git_tree_evars → git-tree-evars} +0 -0
- /data/bindir/{git_tree_replicate → git-tree-replicate} +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 744efed3dbbb3370021be4abf7e50f5105f340f0b00c2fe525416d18665b6561
|
4
|
+
data.tar.gz: 938fdd59658c6ec5a74b120da486ab65d418cb5f34e69b13279bfc3656abdf50
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b35184a83646f7ccffd3e34e744da2320163d46f37b2ea3f3f1511cb73d63f13f098e8472da6b792d31101f0b340b49bbc2b4eb29bdd903cae044cf129a2e34d
|
7
|
+
data.tar.gz: 1cc7aaa472d842c40c5f80b747af0d55c55737b2cf4aa32a73c42081898fbc051fc30169554380dcba649b96d33cf3f4125c55efbbffbc449a5a7117191cf8ae
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
+
## 0.2.3 / 2023-05-26
|
2
|
+
* Improved help messages.
|
3
|
+
* Renamed executables to `git-tree-replicate` and `git-tree-evars`.
|
4
|
+
|
1
5
|
## 0.2.2 / 2023-05-23
|
2
6
|
* `git_tree_evars` now checks for previous definitions and issues warnings.
|
7
|
+
|
3
8
|
## 0.2.1 / 2023-05-03
|
4
9
|
* Removed the here document wrapper from the output of `git_tree_evars`.
|
5
10
|
|
data/README.md
CHANGED
@@ -5,13 +5,13 @@
|
|
5
5
|
This Ruby gem installs two commands that scan a git directory tree and write out scripts.
|
6
6
|
Directories containing a file called `.ignore` are ignored.
|
7
7
|
|
8
|
-
- The `
|
8
|
+
- The `git-tree-replicate` command writes a script that clones the repos in the tree,
|
9
9
|
and adds any defined remotes.
|
10
10
|
- Any git repos that have already been cloned into the target directory tree are skipped.
|
11
|
-
This means you can rerun `
|
11
|
+
This means you can rerun `git-tree-replicate` as many times as you want, without ill effects.
|
12
12
|
- All remotes in each repo are replicated.
|
13
13
|
|
14
|
-
- The `
|
14
|
+
- The `git-tree-evars` command writes a script that defines environment variables pointing to git repos.
|
15
15
|
|
16
16
|
|
17
17
|
## Usage
|
@@ -20,18 +20,18 @@ Enclose the name of the environment variable within single quotes,
|
|
20
20
|
which will prevent the shell from expanding it before invoking the command.
|
21
21
|
|
22
22
|
|
23
|
-
## `
|
23
|
+
## `git-tree-replicate` Usage
|
24
24
|
The following creates a script in the current directory called `work.sh`,
|
25
25
|
that replicates the desired portions of the directory tree of git repos pointed to by `$work`:
|
26
26
|
```shell
|
27
|
-
$
|
27
|
+
$ git-tree-replicate '$work' > work.sh
|
28
28
|
```
|
29
29
|
|
30
30
|
The generated environment variables will all be relative to the
|
31
31
|
path pointed to by the expanded environment variable that you provided.
|
32
32
|
You will understand what this means once you look at the generated script.
|
33
33
|
|
34
|
-
When `
|
34
|
+
When `git-tree-replicate` completes,
|
35
35
|
edit the generated script to suit, then
|
36
36
|
copy it to the target machine and run it.
|
37
37
|
The following example copies the script to `machine2` and runs it:
|
@@ -43,7 +43,7 @@ $ ssh machine2 work.sh
|
|
43
43
|
```
|
44
44
|
|
45
45
|
|
46
|
-
### Generated Script from `
|
46
|
+
### Generated Script from `git-tree-replicate`
|
47
47
|
Following is a sample of one section, which is repeated for every git repo that is processed:
|
48
48
|
You can edit them to suit.
|
49
49
|
|
@@ -57,8 +57,8 @@ if [ ! -d "sinatra/sinatras-skeleton/.git" ]; then
|
|
57
57
|
fi
|
58
58
|
```
|
59
59
|
|
60
|
-
## `
|
61
|
-
The `
|
60
|
+
## `git-tree-evars` Usage
|
61
|
+
The `git-tree-evars` command should be run on the target computer.
|
62
62
|
The command requires only one parameter:
|
63
63
|
an environment variable reference, pointing to the top-level directory to replicate.
|
64
64
|
The environment variable reference must be contained within single quotes to prevent expansion by the shell.
|
@@ -66,13 +66,13 @@ The environment variable reference must be contained within single quotes to pre
|
|
66
66
|
The following appends to any script in the `$work` directory called `.evars`.
|
67
67
|
The script defines environment variables that point to each git repos pointed to by `$work`:
|
68
68
|
```shell
|
69
|
-
$
|
69
|
+
$ git-tree-evars '$work' >> $work/.evars
|
70
70
|
```
|
71
71
|
|
72
72
|
|
73
|
-
### Generated Script from `
|
73
|
+
### Generated Script from `git-tree-evars`
|
74
74
|
Following is a sample of environment variable definitions.
|
75
|
-
You
|
75
|
+
You are expected to edit it to suit.
|
76
76
|
|
77
77
|
```shell
|
78
78
|
export work=/mnt/c/work
|
@@ -103,12 +103,16 @@ $ cd $my_project
|
|
103
103
|
|
104
104
|
|
105
105
|
## Installation
|
106
|
-
Type the following at a shell prompt:
|
106
|
+
Type the following at a shell prompt on the machine you are copying the git tree from, and on the machine that you are copying the git tree to:
|
107
107
|
|
108
108
|
```shell
|
109
|
+
$ yes | sudo apt install cmake libgit2-dev libssh2-1-dev pkg-config
|
110
|
+
|
109
111
|
$ gem install git_tree
|
110
112
|
```
|
111
113
|
|
114
|
+
To register the new commands, either log out and log back in, or open a new console.
|
115
|
+
|
112
116
|
|
113
117
|
## Additional Information
|
114
118
|
More information is available on
|
data/git_tree.gemspec
CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
|
|
13
13
|
The git_tree_evars command writes a script that defines environment variables pointing to git repos.
|
14
14
|
END_OF_DESC
|
15
15
|
spec.email = ['mslinn@mslinn.com']
|
16
|
-
spec.executables = %w[
|
16
|
+
spec.executables = %w[git-tree-evars git-tree-replicate]
|
17
17
|
spec.files = Dir[
|
18
18
|
'{bindir,lib}/**/*',
|
19
19
|
'.rubocop.yml',
|
data/lib/git_tree/version.rb
CHANGED
data/lib/git_tree_evars.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'shellwords'
|
2
1
|
require_relative 'git_tree'
|
3
2
|
|
4
3
|
module GitTree
|
@@ -6,13 +5,16 @@ module GitTree
|
|
6
5
|
|
7
6
|
# @param root might be "$envar" or a fully qualified directory name ("/a/b/c")
|
8
7
|
def self.command_evars(root = ARGV[0])
|
9
|
-
|
8
|
+
help_evars "Environment variable reference was missing. Please enclose it within single quotes." if root.to_s.empty?
|
9
|
+
help_evars "Environment variable reference must start with a dollar sign ($)." unless root.start_with? '$'
|
10
10
|
|
11
11
|
base = MslinnUtil.expand_env root
|
12
|
-
|
12
|
+
help_evars "Environment variable '#{root}' is undefined." if base.strip.empty?
|
13
|
+
help_evars "Environment variable '#{root}' points to a non-existant directory (#{base})." unless File.exist?(base)
|
14
|
+
help_evars "Environment variable '#{root}' points to a file (#{base}), not a directory." unless Dir.exist?(base)
|
13
15
|
|
14
|
-
|
15
|
-
puts make_env_vars
|
16
|
+
dirs = directories_to_process base
|
17
|
+
puts make_env_vars(root, base, dirs)
|
16
18
|
end
|
17
19
|
|
18
20
|
def self.env_var_name(path)
|
@@ -21,12 +23,26 @@ module GitTree
|
|
21
23
|
end
|
22
24
|
|
23
25
|
def self.help_evars(msg = nil)
|
24
|
-
|
26
|
+
prog_name = File.basename $PROGRAM_NAME
|
27
|
+
puts "Error: #{msg}\n".red if msg
|
25
28
|
puts <<~END_HELP
|
26
|
-
Examines a tree of git
|
27
|
-
|
29
|
+
#{prog_name} - Examines a tree of git repositories and writes a bash script to STDOUT
|
30
|
+
that defines environment variables which point to the repositories in the tree.
|
31
|
+
|
32
|
+
Does not redefine existing environment variables; messages are written to
|
33
|
+
STDERR to indicate environment variables that are not redefined.
|
34
|
+
|
35
|
+
The environment variable must have been exported, for example:
|
36
|
+
|
37
|
+
$ export work=$HOME/work
|
28
38
|
|
29
39
|
Directories containing a file called .ignore are ignored.
|
40
|
+
|
41
|
+
Usage example:
|
42
|
+
|
43
|
+
$ #{prog_name} '$work'
|
44
|
+
|
45
|
+
The name of the environment variable must be preceded by a dollar sign and enclosed within single quotes.
|
30
46
|
END_HELP
|
31
47
|
exit 1
|
32
48
|
end
|
@@ -39,27 +55,28 @@ module GitTree
|
|
39
55
|
# @param base a fully qualified directory name ("/a/b/c")
|
40
56
|
# @param dirs directory list to process
|
41
57
|
def self.make_env_vars(root, base, dirs)
|
42
|
-
help_evars "Error: Please specify the subdirectory to traverse
|
58
|
+
help_evars "Error: Please specify the subdirectory to traverse." if root.to_s.empty?
|
43
59
|
|
44
60
|
result = []
|
45
61
|
result << make_env_var(env_var_name(base), MslinnUtil.deref_symlink(base))
|
46
62
|
dirs.each do |dir|
|
47
63
|
ename = env_var_name dir
|
48
64
|
ename_value = MslinnUtil.expand_env "$#{ename}"
|
49
|
-
ename_value = ename_value.
|
50
|
-
if ename_value.to_s.empty?
|
65
|
+
ename_value = ename_value.gsub(' ', '\\ ').delete_prefix('\\') unless ename_value.empty?
|
66
|
+
if ename_value.to_s.strip.empty?
|
51
67
|
result << make_env_var(ename, "#{root}/#{dir}")
|
52
68
|
else
|
53
69
|
msg = "$#{ename} was previously defined as #{ename_value}"
|
54
|
-
|
55
|
-
if Dir.exist?
|
70
|
+
dir2 = MslinnUtil.expand_env(ename_value)
|
71
|
+
if Dir.exist? dir2
|
56
72
|
warn msg.cyan
|
57
73
|
else
|
58
|
-
msg += ", but that directory does not exist
|
74
|
+
msg += ", but that directory does not exist,\n so redefining #{ename} as #{dir}."
|
59
75
|
warn msg.green
|
76
|
+
result << make_env_var(ename, "#{root}/#{dir}")
|
60
77
|
end
|
61
78
|
end
|
62
79
|
end
|
63
|
-
result.map { |x| "#{x}\n" }.join
|
80
|
+
result.map { |x| "#{x}\n" }.join + "\n"
|
64
81
|
end
|
65
82
|
end
|
data/lib/git_tree_replicate.rb
CHANGED
@@ -1,25 +1,43 @@
|
|
1
1
|
require_relative 'git_tree'
|
2
2
|
|
3
3
|
module GitTree
|
4
|
+
using Rainbow
|
5
|
+
|
4
6
|
# @param root might be "$envar" or a fully qualified directory name ("/a/b/c")
|
5
7
|
def self.command_replicate(root = ARGV[0])
|
6
|
-
|
7
|
-
|
8
|
+
help_replicate "Environment variable reference was missing. Please enclose it within single quotes." if root.to_s.empty?
|
9
|
+
help_replicate "Error: Environment variable reference must start with a dollar sign ($)" unless root.start_with? '$'
|
8
10
|
|
9
11
|
base = MslinnUtil.expand_env root
|
10
|
-
|
12
|
+
help_replicate "Environment variable '#{root}' is undefined." if base.strip.empty?
|
13
|
+
help_replicate "Environment variable '#{root}' points to a non-existant directory (#{base})." unless File.exist?(base)
|
14
|
+
help_replicate "Environment variable '#{root}' points to a file (#{base}), not a directory." unless Dir.exist?(base)
|
11
15
|
|
12
|
-
|
13
|
-
puts make_replicate_script
|
16
|
+
dirs = directories_to_process base
|
17
|
+
puts make_replicate_script(root, base, dirs)
|
14
18
|
end
|
15
19
|
|
16
20
|
def self.help_replicate(msg = nil)
|
17
|
-
|
21
|
+
prog_name = File.basename $PROGRAM_NAME
|
22
|
+
puts "Error: #{msg}\n".red if msg
|
18
23
|
puts <<~END_HELP
|
19
|
-
Replicates tree of git
|
20
|
-
|
24
|
+
#{prog_name} - Replicates a tree of git repositories and writes a bash script
|
25
|
+
to STDOUT that clones the repositories in the tree. Replicates any remotes
|
26
|
+
defined in the source repositories to the target repositories.
|
27
|
+
|
28
|
+
The environment variable must have been exported, for example:
|
29
|
+
|
30
|
+
$ export work=$HOME/work
|
21
31
|
|
22
32
|
Directories containing a file called .ignore are ignored.
|
33
|
+
|
34
|
+
Usage example:
|
35
|
+
Assuming that 'work' is an environment variable that contains the name of a
|
36
|
+
directory that contains a tree of git repositories:
|
37
|
+
|
38
|
+
$ #{prog_name} '$work'
|
39
|
+
|
40
|
+
The name of the environment variable must be preceded by a dollar sign and enclosed within single quotes.
|
23
41
|
END_HELP
|
24
42
|
exit 1
|
25
43
|
end
|
@@ -38,7 +56,7 @@ module GitTree
|
|
38
56
|
|
39
57
|
def self.replicate_one(dir)
|
40
58
|
output = []
|
41
|
-
project_dir = File.basename dir
|
59
|
+
# project_dir = File.basename dir
|
42
60
|
parent_dir = File.dirname dir
|
43
61
|
repo = Rugged::Repository.new dir
|
44
62
|
origin_url = repo.config['remote.origin.url']
|
@@ -61,7 +79,7 @@ module GitTree
|
|
61
79
|
# output << ' # Git project directory was renamed, renaming this copy to match original directory structure'
|
62
80
|
# output << " mv #{git_dir_name} #{project_dir}"
|
63
81
|
# end
|
64
|
-
output <<
|
82
|
+
output << 'fi'
|
65
83
|
output << ''
|
66
84
|
output
|
67
85
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_tree
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Slinn
|
8
8
|
autorequire:
|
9
9
|
bindir: bindir
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-05-
|
11
|
+
date: 2023-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rainbow
|
@@ -47,8 +47,8 @@ description: |
|
|
47
47
|
email:
|
48
48
|
- mslinn@mslinn.com
|
49
49
|
executables:
|
50
|
-
-
|
51
|
-
-
|
50
|
+
- git-tree-evars
|
51
|
+
- git-tree-replicate
|
52
52
|
extensions: []
|
53
53
|
extra_rdoc_files: []
|
54
54
|
files:
|
@@ -57,8 +57,8 @@ files:
|
|
57
57
|
- LICENSE.txt
|
58
58
|
- README.md
|
59
59
|
- Rakefile
|
60
|
-
- bindir/
|
61
|
-
- bindir/
|
60
|
+
- bindir/git-tree-evars
|
61
|
+
- bindir/git-tree-replicate
|
62
62
|
- git_tree.gemspec
|
63
63
|
- lib/git_tree.rb
|
64
64
|
- lib/git_tree/version.rb
|
File without changes
|
File without changes
|