git_tree 0.3.0 → 1.0.1

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.
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_tree
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Slinn
8
- bindir: bindir
8
+ bindir: exe
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
@@ -38,21 +38,27 @@ dependencies:
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  description: |
41
- Installs 3 commands that process a git directory tree.
41
+ Installs 5 commands that process a git directory tree.
42
42
  Directories containing a file called .ignore are ignored.
43
43
 
44
- The git-tree-replicate command writes a script that clones the repos in the tree,
45
- and adds any defined remotes.
44
+ The git-commitAll command commits all changes to each repository in the tree.
45
+
46
+ The git-evars command writes a script that defines environment variables pointing to git repos.
46
47
 
47
- The git-tree-evars command writes a script that defines environment variables pointing to git repos.
48
+ The git-exec command executes a bash expression on children of a directory, or a list of directories.
49
+
50
+ The git-replicate command writes a script that clones the repos in the tree,
51
+ and adds any defined remotes.
48
52
 
49
- The git-tree-exec command executes a bash expression on children of a directory, or a list of directories.
53
+ The git-update command updates each repository in the tree.
50
54
  email:
51
55
  - mslinn@mslinn.com
52
56
  executables:
53
- - git-tree-evars
54
- - git-tree-exec
55
- - git-tree-replicate
57
+ - git-commitAll
58
+ - git-evars
59
+ - git-exec
60
+ - git-replicate
61
+ - git-update
56
62
  extensions: []
57
63
  extra_rdoc_files: []
58
64
  files:
@@ -61,16 +67,28 @@ files:
61
67
  - LICENSE.txt
62
68
  - README.md
63
69
  - Rakefile
64
- - bindir/git-tree-evars
65
- - bindir/git-tree-exec
66
- - bindir/git-tree-replicate
70
+ - exe/git-commitAll
71
+ - exe/git-evars
72
+ - exe/git-exec
73
+ - exe/git-replicate
74
+ - exe/git-update
67
75
  - git_tree.gemspec
76
+ - lib/commands/abstract_command.rb
77
+ - lib/commands/git_commit_all.rb
78
+ - lib/commands/git_evars.rb
79
+ - lib/commands/git_exec.rb
80
+ - lib/commands/git_exec_spec.rb
81
+ - lib/commands/git_replicate.rb
82
+ - lib/commands/git_update.rb
68
83
  - lib/git_tree.rb
69
84
  - lib/git_tree/version.rb
70
- - lib/git_tree_evars.rb
71
- - lib/git_tree_exec.rb
72
- - lib/git_tree_replicate.rb
73
- - lib/util.rb
85
+ - lib/util/command_runner.rb
86
+ - lib/util/gem_support.rb
87
+ - lib/util/git_tree_walker.rb
88
+ - lib/util/git_tree_walker_private.rb
89
+ - lib/util/log.rb
90
+ - lib/util/thread_pool_manager.rb
91
+ - lib/util/zowee_optimizer.rb
74
92
  homepage: https://www.mslinn.com/git/1100-git-tree.html
75
93
  licenses:
76
94
  - MIT
@@ -91,16 +109,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
91
109
  requirements:
92
110
  - - ">="
93
111
  - !ruby/object:Gem::Version
94
- version: 2.6.0
112
+ version: 3.2.0
95
113
  required_rubygems_version: !ruby/object:Gem::Requirement
96
114
  requirements:
97
115
  - - ">="
98
116
  - !ruby/object:Gem::Version
99
117
  version: '0'
100
118
  requirements: []
101
- rubygems_version: 3.7.2
119
+ rubygems_version: 3.6.9
102
120
  specification_version: 4
103
- summary: Installs two commands that scan a git directory tree and write out scripts
104
- for replication.
121
+ summary: Installs five commands that walk a git directory tree and perform tasks.
105
122
  test_files: []
106
123
  ...
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'git_tree_evars'
4
-
5
- GitTree.command_evars
data/bindir/git-tree-exec DELETED
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'git_tree_exec'
4
-
5
- GitTree.command_exec
@@ -1,5 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'git_tree_replicate'
4
-
5
- GitTree.command_replicate
@@ -1,82 +0,0 @@
1
- require_relative 'git_tree'
2
-
3
- module GitTree
4
- using Rainbow
5
-
6
- # @param root might be "$envar" or a fully qualified directory name ("/a/b/c")
7
- def self.command_evars(root = ARGV[0])
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
-
11
- base = MslinnUtil.expand_env root
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)
15
-
16
- dirs = directories_to_process base
17
- puts make_env_vars(root, base, dirs)
18
- end
19
-
20
- def self.env_var_name(path)
21
- name = path.include?('/') ? File.basename(path) : path
22
- name.tr(' ', '_').tr('-', '_')
23
- end
24
-
25
- def self.help_evars(msg = nil)
26
- prog_name = File.basename $PROGRAM_NAME
27
- puts "Error: #{msg}\n".red if msg
28
- puts <<~END_HELP
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
38
-
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.
46
- END_HELP
47
- exit 1
48
- end
49
-
50
- def self.make_env_var(name, value)
51
- "export #{env_var_name(name)}=#{value}"
52
- end
53
-
54
- # @param root should be an "$envar" that points to the root of a directory tree containing git repos.
55
- # @param base a fully qualified directory name ("/a/b/c")
56
- # @param dirs directory list to process
57
- def self.make_env_vars(root, base, dirs)
58
- help_evars "Error: Please specify the subdirectory to traverse." if root.to_s.empty?
59
-
60
- result = []
61
- result << make_env_var(env_var_name(base), MslinnUtil.deref_symlink(base))
62
- dirs.each do |dir|
63
- ename = env_var_name dir
64
- ename_value = MslinnUtil.expand_env "$#{ename}"
65
- ename_value = ename_value.gsub(' ', '\\ ').delete_prefix('\\') unless ename_value.empty?
66
- if ename_value.to_s.strip.empty?
67
- result << make_env_var(ename, "#{root}/#{dir}")
68
- else
69
- msg = "$#{ename} was previously defined as #{ename_value}"
70
- dir2 = MslinnUtil.expand_env(ename_value)
71
- if Dir.exist? dir2
72
- warn msg.cyan
73
- else
74
- msg += ", but that directory does not exist,\n so redefining #{ename} as #{dir}."
75
- warn msg.green
76
- result << make_env_var(ename, "#{root}/#{dir}")
77
- end
78
- end
79
- end
80
- result.map { |x| "#{x}\n" }.join + "\n"
81
- end
82
- end
data/lib/git_tree_exec.rb DELETED
@@ -1,94 +0,0 @@
1
- require 'pathname'
2
- require 'shellwords'
3
- require_relative 'git_tree'
4
-
5
- module GitTree
6
- using Rainbow
7
-
8
- # @param root might be:
9
- # - '$envar'
10
- # - A fully qualified directory name ("/a/b/c")
11
- # - A list of either of the above
12
- def self.command_exec(args = ARGV)
13
- root = args[0]
14
- command = args[1]
15
-
16
- help_exec "A directory specification and a command must be specified." if args.empty?
17
- help_exec "A command must be specified." if args.length == 1
18
-
19
- base = MslinnUtil.expand_env root
20
- help_exec "Environment variable '#{root}' is undefined." if base.empty?
21
- base.shellsplit.each do |top|
22
- dirs = directories_to_process(top)
23
- dirs.each do |dir|
24
- dir = File.join(base, dir) if Pathname.new(dir).relative?
25
- execute dir, command
26
- end
27
- end
28
- end
29
-
30
- # @return array containing status code and result of running command in the given directory
31
- # @param command [String] Shell command to execute
32
- def self.execute(dir, command)
33
- Dir.chdir(dir) do
34
- unless File.exist? dir
35
- warn "Warning: directory '#{dir}' does not exist.".yellow
36
- return
37
- end
38
- unless Dir.exist? dir
39
- warn "Warning: #{dir} is a file, not a directory.".yellow
40
- return
41
- end
42
- result = `#{command}`.rstrip
43
- puts result unless result.empty?
44
- end
45
- rescue StandardError => e
46
- warn "Error: #{e.message} from executing '#{command}' in #{dir}".red
47
- end
48
-
49
- def self.help_exec(msg = nil)
50
- prog_name = File.basename $PROGRAM_NAME
51
- puts "Error: #{msg}\n".red if msg
52
- puts <<~END_HELP
53
- #{prog_name} - requires only one parameter,
54
- which points to the top-level directory to process.
55
- 3 forms are accepted.
56
- Only direct child directories are processed; infinite recursion is not supported.
57
- 1. A directory name, which may be relative or absolute.
58
- 2. An environment variable reference,
59
- which must be preceded by a dollar sign and enclosed within single quotes
60
- to prevent expansion by the shell.
61
- 3. A list of directory names, which may be relative or absolute,
62
- and may contain environment variables.
63
-
64
- The environment variable must have been exported, for example:
65
-
66
- $ export work=$HOME/work
67
-
68
- Directories containing a file called .ignore are ignored.
69
-
70
- Usage examples:
71
-
72
- 1) For all subdirectories of the current directory,
73
- update `Gemfile.lock` and install a local copy of the gem:
74
-
75
- $ #{prog_name} . 'bundle && bundle update && rake install'
76
-
77
-
78
- 2) For all subdirectories of the directory pointed to by `$work`,
79
- run git commit and push changes.
80
-
81
- $ #{prog_name} '$work' 'git commit -am "-" && git push'
82
-
83
-
84
- 3) For all subdirectories of the specified directories,
85
- list the projects that have a demo/ subdirectory.
86
-
87
- The specified directories are . (the current directory),
88
- ~ (the home directory) and the directory pointed to by $my_plugins
89
-
90
- $ #{prog_name} '. ~ $my_plugins' 'if [ -d demo]; then realpath demo; fi'
91
- END_HELP
92
- exit 1
93
- end
94
- end
@@ -1,86 +0,0 @@
1
- require_relative 'git_tree'
2
-
3
- module GitTree
4
- using Rainbow
5
-
6
- # @param root might be "$envar" or a fully qualified directory name ("/a/b/c")
7
- def self.command_replicate(root = ARGV[0])
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? '$'
10
-
11
- base = MslinnUtil.expand_env root
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)
15
-
16
- dirs = directories_to_process base
17
- puts make_replicate_script(root, base, dirs)
18
- end
19
-
20
- def self.help_replicate(msg = nil)
21
- prog_name = File.basename $PROGRAM_NAME
22
- puts "Error: #{msg}\n".red if msg
23
- puts <<~END_HELP
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
31
-
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.
41
- END_HELP
42
- exit 1
43
- end
44
-
45
- # @param root should be an "$envar" that points to the root of a directory tree containing git repos.
46
- # @param base a fully qualified directory name ("/a/b/c")
47
- # @param dirs directory list to process
48
- def self.make_replicate_script(root, base, dirs)
49
- help_replicate "Error: Please specify the subdirectory to traverse.\n\n" if root.to_s.empty?
50
-
51
- Dir.chdir(base) do
52
- result = dirs.map { |dir| replicate_one(dir) }
53
- result.join "\n"
54
- end
55
- end
56
-
57
- def self.replicate_one(dir)
58
- output = []
59
- # project_dir = File.basename dir
60
- parent_dir = File.dirname dir
61
- repo = Rugged::Repository.new dir
62
- origin_url = repo.config['remote.origin.url']
63
-
64
- output << "if [ ! -d \"#{dir}/.git\" ]; then"
65
- output << " mkdir -p '#{parent_dir}'"
66
- output << " pushd '#{parent_dir}' > /dev/null"
67
- output << " git clone #{origin_url}"
68
-
69
- repo.remotes.each do |remote|
70
- next if remote.name == 'origin' || remote.url == 'no_push'
71
-
72
- output << " git remote add #{remote.name} '#{remote.url}'"
73
- end
74
-
75
- output << ' popd > /dev/null'
76
-
77
- # git_dir_name = File.basename Dir.pwd
78
- # if git_dir_name != project_dir
79
- # output << ' # Git project directory was renamed, renaming this copy to match original directory structure'
80
- # output << " mv #{git_dir_name} #{project_dir}"
81
- # end
82
- output << 'fi'
83
- output << ''
84
- output
85
- end
86
- end