monos 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70c115bc6f5762608c35c75b05991cafa719485f
4
- data.tar.gz: f6c91d659878aacc2f5902b0525acbbd27a52106
3
+ metadata.gz: 5cafc90639b5bb02b8be04d5f993dd518a53db83
4
+ data.tar.gz: b3aba3dbae6d86e86d78eb53add58def4faa3844
5
5
  SHA512:
6
- metadata.gz: d7c3067d9f56f3b4888017540746ae118dae15cf3c9a46a86d47f5489ac07246105feccf608203c23628f5c15c3a11ff71fca8816f13226aa9e31f21ca6b0d97
7
- data.tar.gz: 2e19f6360434425c493ff6bbfbf72fef6b22e7e4d96ec7d99a5a28d7aa89c2599fb009bc8686ee725375b04bbce0ca11d4d9a5b6fed54838e73784feb4e9f479
6
+ metadata.gz: 9192d91ab18d06d5b167be39171f86d71daf40629c5cf5aeeff8de9e8cb9c5b681e33de16ef08e02ee2986c97b46e9c4bc2292e364d6dab94ee6f28ce98e93e0
7
+ data.tar.gz: a48bacb9f54bf48e6264c9ece66e030cdd3c8c900373d141cc4d430b913851b802b4cb8b8c6d4d3c7b9f458584dcc372fe4e7e0ea45585d6cfcc20ca6f5a6414
@@ -8,12 +8,12 @@ lib/mono.rb
8
8
  lib/mono/base.rb
9
9
  lib/mono/commands/env.rb
10
10
  lib/mono/commands/fetch.rb
11
+ lib/mono/commands/run.rb
11
12
  lib/mono/commands/status.rb
12
13
  lib/mono/commands/sync.rb
13
- lib/mono/git/base.rb
14
- lib/mono/sportdb.rb
15
14
  lib/mono/tool.rb
16
15
  lib/mono/version.rb
17
16
  lib/monos.rb
17
+ lib/sportdb/setup.rb
18
18
  test/helper.rb
19
19
  test/test_base.rb
data/README.md CHANGED
@@ -52,7 +52,7 @@ openfootball:
52
52
 
53
53
  ### Commands
54
54
 
55
- `status` • `fetch` • `sync` • `env`
55
+ `status` • `fetch` • `sync` • `run` •`env`
56
56
 
57
57
  ### `status` Command
58
58
 
@@ -114,6 +114,27 @@ $ mo get
114
114
  Note: `install` or `get` or `up` are all aliases that you can use for `sync`.
115
115
 
116
116
 
117
+ ### `run` Command
118
+
119
+ Use the `run` command to run any command in all repos. Example:
120
+
121
+ ```
122
+ $ mono run git ls-files
123
+ $ mono exec git ls-files # exec is an alias for run
124
+ $ mo run git ls-files # mo is a "shortcut" convenience alias for mono
125
+ $ mo exec git ls-files
126
+
127
+ # -or-
128
+
129
+ $ mono run tree
130
+ $ mono exec tree
131
+ $ mo run tree
132
+ $ mo exec tree
133
+ ```
134
+
135
+ Note: `exec` is an alias that you can use for `run`.
136
+
137
+
117
138
 
118
139
  ### `env` Command
119
140
 
data/Rakefile CHANGED
@@ -3,12 +3,11 @@ require './lib/mono/version.rb'
3
3
 
4
4
  Hoe.spec 'monos' do
5
5
 
6
- self.version = Mono::VERSION
6
+ self.version = MonoCore::VERSION
7
7
 
8
8
  self.summary = "monos - monorepo / mono source tree tools and (startup) scripts"
9
9
  self.description = summary
10
10
 
11
- # self.urls = ['https://github.com/sportdb/sport.db' ]
12
11
  self.urls = { home: 'https://github.com/sportdb/sport.db' }
13
12
 
14
13
  self.author = 'Gerald Bauer'
@@ -20,7 +19,9 @@ Hoe.spec 'monos' do
20
19
 
21
20
  self.licenses = ['Public Domain']
22
21
 
23
- self.extra_deps = []
22
+ self.extra_deps = [
23
+ ['gitti', '>= 0.4.0' ],
24
+ ]
24
25
 
25
26
  self.spec_extras = {
26
27
  required_ruby_version: '>= 2.2.2'
@@ -1,24 +1,31 @@
1
- require 'pp'
2
- require 'time'
3
- require 'date'
4
- require 'yaml'
5
- require 'open3'
6
- require 'fileutils'
7
- require 'optparse'
1
+ ## first add git support
2
+ ## note: use the "modular" version WITHOUT auto-include gitti,
3
+ ## thus, require 'gitti/base' (and NOT 'gitti')
4
+ require 'gitti/base'
5
+
6
+ module Mono
7
+ ## note: make Git, GitProject, GitRepoSet, etc. available without Gitti::
8
+ include Gitti
9
+ end
10
+
11
+
12
+ ## some more stdlibs
13
+ # require 'optparse'
14
+
8
15
 
9
16
 
10
17
  ###
11
18
  # our own code
12
19
  require 'mono/version' # let version always go first
13
20
  require 'mono/base'
14
- require 'mono/git/base'
15
21
 
16
22
  require 'mono/commands/status'
17
23
  require 'mono/commands/fetch'
18
24
  require 'mono/commands/sync'
19
25
  require 'mono/commands/env'
26
+ require 'mono/commands/run'
20
27
  require 'mono/tool'
21
28
 
22
29
 
23
30
 
24
- puts Mono::Module.banner # say hello
31
+ puts MonoCore.banner # say hello
@@ -29,9 +29,9 @@ module Mono
29
29
  end
30
30
 
31
31
  if path
32
- YAML.load_file( path )
32
+ GitRepoSet.read( path )
33
33
  else
34
- {}
34
+ GitRepoSet.new( {} ) ## return empty set -todo/check: return nil - why? why not?
35
35
  end
36
36
  end
37
37
 
@@ -2,9 +2,22 @@ module Mono
2
2
 
3
3
  def self.env ## check environment setup
4
4
  puts "Mono.root (MOPATH): >#{Mono.root}<"
5
- puts "Mono::Module.root: >#{Mono::Module.root}<"
5
+ puts "MonoCore.root: >#{MonoCore.root}<"
6
+ puts
7
+
8
+ ## add ruby version and path - why? why not? e.g.
9
+ ## ruby:
10
+ ## bin: C:/ri330/Ruby2.0.0/bin/ruby.exe
11
+ ## version: ruby 2.3.3p222 (2016-11-21 revision 56859) [i386-mingw32]
12
+
6
13
  puts "git version:"
7
14
  Git.version
15
+ ## Git.config( 'user.name' )
16
+ ## Git.config( 'user.email', show_origin: true )
17
+
18
+ ## dump/print all user.* settings e.g. user.name, user.email
19
+ Git.config( /user/, show_origin: true )
20
+
8
21
  puts
9
22
  puts "monorepo.yml:"
10
23
  pp Mono.monofile
@@ -1,21 +1,16 @@
1
1
  module Mono
2
2
 
3
3
  ## pass along hash of repos (e.g. monorepo.yml or repos.yml )
4
- def self.fetch( h=Mono.monofile )
4
+ def self.fetch
5
+ repos = Mono.monofile
6
+
5
7
  count_orgs = 0
6
8
  count_repos = 0
7
9
 
8
- ## sum up total number of repos
9
- total_repos = h.reduce(0) {|sum,(_,names)| sum+= names.size; sum }
10
-
10
+ total_repos = repos.size
11
11
 
12
- h.each do |org_with_counter,names|
13
12
 
14
- ## remove optional number from key e.g.
15
- ## mrhydescripts (3) => mrhydescripts
16
- ## footballjs (4) => footballjs
17
- ## etc.
18
- org = org_with_counter.sub( /\([0-9]+\)/, '' ).strip
13
+ repos.each do |org,names|
19
14
 
20
15
  org_path = "#{Mono.root}/#{org}"
21
16
 
@@ -26,8 +21,8 @@ module Mono
26
21
 
27
22
  Dir.chdir( org_path ) do
28
23
  if Dir.exist?( repo.name )
29
- GitProject.open( repo.name ) do |git|
30
- git.fetch
24
+ GitProject.open( repo.name ) do |proj|
25
+ proj.fetch
31
26
  end
32
27
  else
33
28
  puts "!! repo not found / missing"
@@ -0,0 +1,47 @@
1
+ module Mono
2
+
3
+ def self.run( *args )
4
+ ## todo/fix: use a "standard" argument to pass along hash of repos
5
+ ## (e.g. monorepo.yml or repos.yml ) how? - why? why not?
6
+ repos = Mono.monofile
7
+
8
+
9
+ cmd = args.join( ' ' )
10
+
11
+ count_orgs = 0
12
+ count_repos = 0
13
+
14
+ total_repos = repos.size
15
+
16
+ repos.each do |org,names|
17
+
18
+ org_path = "#{Mono.root}/#{org}"
19
+
20
+ names.each do |name|
21
+ puts "[#{count_repos+1}/#{total_repos}] #{org}@#{name}..."
22
+
23
+ repo = GitHubRepo.new( org, name ) ## owner, name e.g. rubylibs/webservice
24
+
25
+ Dir.chdir( org_path ) do
26
+ if Dir.exist?( repo.name )
27
+ GitProject.open( repo.name ) do |proj|
28
+ proj.run( cmd )
29
+ end
30
+ else
31
+ puts "!! repo not found / missing"
32
+ end
33
+ end
34
+
35
+ count_repos += 1
36
+ end
37
+ count_orgs += 1
38
+ end
39
+
40
+
41
+ ## print stats & changes summary
42
+ puts
43
+ print "#{count_repos} repo(s) @ #{count_orgs} org(s)"
44
+ print "\n"
45
+ end # method run
46
+
47
+ end # module Mono
@@ -1,23 +1,17 @@
1
1
  module Mono
2
2
 
3
3
  ## pass along hash of repos (e.g. monorepo.yml or repos.yml )
4
- def self.status( h=Mono.monofile )
4
+ def self.status
5
+ repos = Mono.monofile
6
+
5
7
  changes = [] ## track changes
6
8
 
7
9
  count_orgs = 0
8
10
  count_repos = 0
9
11
 
10
- ## sum up total number of repos
11
- total_repos = h.reduce(0) {|sum,(_,names)| sum+= names.size; sum }
12
-
13
-
14
- h.each do |org_with_counter,names|
12
+ total_repos = repos.size
15
13
 
16
- ## remove optional number from key e.g.
17
- ## mrhydescripts (3) => mrhydescripts
18
- ## footballjs (4) => footballjs
19
- ## etc.
20
- org = org_with_counter.sub( /\([0-9]+\)/, '' ).strip
14
+ repos.each do |org,names|
21
15
 
22
16
  org_path = "#{Mono.root}/#{org}"
23
17
 
@@ -28,8 +22,8 @@ module Mono
28
22
 
29
23
  Dir.chdir( org_path ) do
30
24
  if Dir.exist?( repo.name )
31
- GitProject.open( repo.name ) do |git|
32
- output = git.changes
25
+ GitProject.open( repo.name ) do |proj|
26
+ output = proj.changes
33
27
  if output.empty?
34
28
  puts " - no changes -"
35
29
  else
@@ -1,21 +1,15 @@
1
1
  module Mono
2
2
 
3
3
  ## pass along hash of repos (e.g. monorepo.yml or repos.yml )
4
- def self.sync( h=Mono.monofile )
4
+ def self.sync
5
+ repos = Mono.monofile
6
+
5
7
  count_orgs = 0
6
8
  count_repos = 0
7
9
 
8
- ## sum up total number of repos
9
- total_repos = h.reduce(0) {|sum,(_,names)| sum+= names.size; sum }
10
-
11
- h.each do |org_with_counter,names|
12
-
13
- ## remove optional number from key e.g.
14
- ## mrhydescripts (3) => mrhydescripts
15
- ## footballjs (4) => footballjs
16
- ## etc.
17
- org = org_with_counter.sub( /\([0-9]+\)/, '' ).strip
10
+ total_repos = repos.size
18
11
 
12
+ repos.each do |org,names|
19
13
  org_path = "#{Mono.root}/#{org}"
20
14
  FileUtils.mkdir_p( org_path ) unless Dir.exist?( org_path ) ## make sure path exists
21
15
 
@@ -26,11 +20,11 @@ module Mono
26
20
 
27
21
  Dir.chdir( org_path ) do
28
22
  if Dir.exist?( repo.name )
29
- GitProject.open( repo.name ) do |git|
30
- if git.changes?
23
+ GitProject.open( repo.name ) do |proj|
24
+ if proj.changes?
31
25
  puts "!! WARN - local changes in workdir; skipping fast forward (remote) sync / merge"
32
26
  else
33
- git.fast_forward ## note: use git pull --ff-only (fast forward only - do NOT merge)
27
+ proj.fast_forward ## note: use git pull --ff-only (fast forward only - do NOT merge)
34
28
  end
35
29
  end
36
30
  else
@@ -26,6 +26,8 @@ class Tool
26
26
  Mono.fetch
27
27
  when 'env', 'e'
28
28
  Mono.env
29
+ when 'run', 'r', 'exec'
30
+ Mono.run( args )
29
31
  else
30
32
  puts "!! ERROR: unknown command >#{cmd}<"
31
33
  exit 1
@@ -1,28 +1,33 @@
1
1
  ## note: use a different module/namespace
2
- ## for the gem version info e.g. Mono::Module vs Mono
2
+ ## for the gem version info e.g. MonoCore vs Mono
3
3
 
4
- module Mono
4
+ module MonoCore ## todo/check: rename to MonoMeta, MonoModule or such - why? why not?
5
+
6
+ ## note: move root to its own namespace to avoid
7
+ ## conflict with Mono.root!!!!
5
8
  MAJOR = 0 ## todo: namespace inside version or something - why? why not??
6
- MINOR = 2
7
- PATCH = 1
9
+ MINOR = 3
10
+ PATCH = 0
8
11
  VERSION = [MAJOR,MINOR,PATCH].join('.')
9
12
 
10
13
  def self.version
11
14
  VERSION
12
15
  end
13
16
 
17
+ def self.banner
18
+ "monos/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
19
+ end
20
+
21
+ def self.root
22
+ File.expand_path( File.dirname(File.dirname(__FILE__) ))
23
+ end
14
24
 
15
- module Module
16
- ## note: move root to its own namespace to avoid
17
- ## conflict with Mono.root!!!!
25
+ end # module MonoCore
18
26
 
19
- def self.banner
20
- "monos/#{VERSION} on Ruby #{RUBY_VERSION} (#{RUBY_RELEASE_DATE}) [#{RUBY_PLATFORM}]"
21
- end
22
27
 
23
- def self.root
24
- File.expand_path( File.dirname(File.dirname(__FILE__) ))
25
- end
28
+ ##################################
29
+ # add a convenience shortcut for now - why? why not?
30
+ module Mono
31
+ VERSION = MonoCore::VERSION
32
+ end
26
33
 
27
- end # module Module
28
- end # module Mono
@@ -13,7 +13,7 @@
13
13
 
14
14
 
15
15
  ## todo/fix: move later app/gem-family/-specific configs
16
- ## to its own gem e.g. mono-sportdb or such - why? why not?
16
+ ## to its own gem e.g. mono-sportdb or sportdb-boot/starter/startup or such - why? why not?
17
17
 
18
18
 
19
19
 
@@ -40,30 +40,22 @@ require_relative '../mono'
40
40
 
41
41
 
42
42
 
43
-
44
- SPORTDB_DIR = "#{Mono.root}/sportdb" # path to libs
45
- OPENFOOTBALL_DIR = "#{Mono.root}/openfootball"
46
- ## add more "standard" dirs - why? why not? - why? why not?
47
- ## use
48
- ## module SportDb::Source / Code / Boot or such????
49
- ##
50
- ## use module SportDb::Boot - yes, yes, yes - why? why not?
51
-
52
-
53
-
54
43
  ## convenience pre-configured/pre-built shortcut - lets you use
55
- ## require 'mono/sportdb'
56
- ## Mono.setup
44
+ ## require 'sportdb/setup'
45
+ ## SportDb::Boot.setup
46
+
57
47
 
58
- ## use SportDb::Boot.setup (setup_load_path) or such??? - why? why not?
48
+ module SportDb
49
+ module Boot
50
+ def self.root() Mono.root; end
59
51
 
60
- module Mono
61
- def self.setup ## setup load path
52
+ def self.setup ## setup load path
62
53
  ### note: for now always assume dev/development
63
54
  ### add ENV check later or pass in as args or such
64
55
 
65
- puts "Mono.root: >#{root}<"
56
+ puts "SportDb::Boot.root: >#{root}<"
66
57
 
58
+ ### todo/fix: use an inline Gemfile and bundler's setup? why? why not?
67
59
  $LOAD_PATH.unshift( "#{root}/yorobot/sport.db.more/sportdb-exporters/lib" )
68
60
  $LOAD_PATH.unshift( "#{root}/yorobot/sport.db.more/sportdb-writers/lib" )
69
61
  $LOAD_PATH.unshift( "#{root}/yorobot/sport.db.more/sportdb-linters/lib" )
@@ -90,20 +82,25 @@ module Mono
90
82
  $LOAD_PATH.unshift( "#{root}/sportdb/sport.db/alphabets/lib" )
91
83
 
92
84
  pp $: # print load path
93
- end
94
- end # module Mono
85
+ end # method setup
86
+ end # module Boot
87
+ end # module Sportdb
88
+
95
89
 
90
+ ### use something like SportDb::Path[:sportdb]
91
+ ## SportDb.path( :sportdb )
92
+ ## SportDb::Boot.sportdb_path or sportdb_dir or such???
93
+ ## SportDb::Env.path( 'sportdb' ) ???
94
+ ## SportDb::Env::SPORTDB_DIR ???
95
+ ## or such - why? why not?
96
+ ##
97
+ ## check rails path setup / style ???
96
98
 
97
- ## todo/fix:
99
+ SPORTDB_DIR = "#{SportDb::Boot.root}/sportdb" # path to libs
100
+ OPENFOOTBALL_DIR = "#{SportDb::Boot.root}/openfootball"
101
+ ## add more "standard" dirs - why? why not? - why? why not?
98
102
  ## use
99
- ## module Starter
100
- ## module SportDb
101
- ## def setup ...
102
- ## end
103
- ## end
103
+ ## module SportDb::Source / Code / Boot or such????
104
104
  ##
105
- ## or such? and use Mono.extend - why? why not?
106
- ## module Mono
107
- ## extend Starter::SportDb
108
- ## end
105
+ ## use module SportDb::Boot - yes, yes, yes - why? why not?
109
106
 
@@ -6,10 +6,14 @@ require 'helper'
6
6
 
7
7
  class TestBase < MiniTest::Test
8
8
 
9
+ Git = Mono::Git
10
+
9
11
  def test_version
12
+ puts MonoCore::VERSION
13
+ puts MonoCore.banner
14
+ puts MonoCore.root
15
+
10
16
  puts Mono::VERSION
11
- puts Mono::Module.banner
12
- puts Mono::Module.root
13
17
  end
14
18
 
15
19
  def test_root
@@ -20,5 +24,28 @@ class TestBase < MiniTest::Test
20
24
  puts Mono.env
21
25
  end
22
26
 
27
+
28
+ def test_git_config
29
+ puts "---"
30
+ Git.config( 'user.name' )
31
+ Git.config( 'user.name', show_origin: true )
32
+ # Git.config( 'user.name', show_scope: true )
33
+
34
+ puts "---"
35
+ Git.config( /user/ ) ## note: pass in regex for regex match/search
36
+ Git.config( /user/, show_origin: true )
37
+ # Git.config( /user/, show_scope: true )
38
+
39
+ puts "---"
40
+ Git.config( /user\./ ) ## note: pass in regex for regex match/search
41
+
42
+ puts "---"
43
+ ## note: if NOT found Mono::Git.config will exit(1) !!!
44
+ ## Mono::Git.config( /proxy/, show_origin: true )
45
+ ## Mono::Git.config( /http/, show_origin: true )
46
+
47
+ puts "---"
48
+ end
49
+
23
50
  end # class TestBase
24
51
 
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: monos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerald Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-04 00:00:00.000000000 Z
11
+ date: 2020-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gitti
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.4.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.4.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rdoc
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -59,13 +73,13 @@ files:
59
73
  - lib/mono/base.rb
60
74
  - lib/mono/commands/env.rb
61
75
  - lib/mono/commands/fetch.rb
76
+ - lib/mono/commands/run.rb
62
77
  - lib/mono/commands/status.rb
63
78
  - lib/mono/commands/sync.rb
64
- - lib/mono/git/base.rb
65
- - lib/mono/sportdb.rb
66
79
  - lib/mono/tool.rb
67
80
  - lib/mono/version.rb
68
81
  - lib/monos.rb
82
+ - lib/sportdb/setup.rb
69
83
  - test/helper.rb
70
84
  - test/test_base.rb
71
85
  homepage: https://github.com/sportdb/sport.db
@@ -1,226 +0,0 @@
1
-
2
- class GitError < StandardError
3
- end
4
-
5
- class Git ## make Git a module - why? why not?
6
-
7
- ###
8
- ## todo/fix: change opts=nil to *args or such - why? why not?
9
-
10
-
11
- ###############
12
- ## "setup" starter git commands
13
-
14
- def self.clone( repo, name=nil )
15
- cmd = "git clone #{repo}"
16
- cmd << " #{name}" unless name.nil? || name.empty?
17
- Shell.run( cmd )
18
- end
19
-
20
- def self.mirror( repo )
21
- cmd = "git clone --mirror #{repo}"
22
- Shell.run( cmd )
23
- end
24
-
25
-
26
- #################
27
- ## standard git commands
28
-
29
- def self.version
30
- cmd = 'git --version'
31
- Shell.run( cmd )
32
- end
33
-
34
- def self.status( short: false )
35
- cmd = 'git status'
36
- cmd << " --short" if short
37
- Shell.run( cmd )
38
- end
39
-
40
- def self.changes ## same as git status --short - keep shortcut / alias - why? why not?
41
- ## returns changed files - one per line or empty if no changes
42
- cmd = 'git status --short'
43
- Shell.run( cmd )
44
- end
45
-
46
- #####################
47
- ## status helpers
48
-
49
- ## git status --short returns empty stdout/list
50
- def self.clean?() changes.empty?; end
51
-
52
- def self.changes?() clean? == false; end ## reverse of clean?
53
- class << self
54
- alias_method :dirty?, :changes? ## add alias
55
- end
56
-
57
-
58
- #######
59
- ## more (major) git commands
60
-
61
- def self.fetch
62
- cmd = 'git fetch'
63
- Shell.run( cmd )
64
- end
65
-
66
- def self.pull
67
- cmd = 'git pull'
68
- Shell.run( cmd )
69
- end
70
-
71
- def self.fast_forward
72
- cmd = 'git pull --ff-only'
73
- Shell.run( cmd )
74
- end
75
- class << self
76
- alias_method :ff, :fast_forward ## add alias
77
- end
78
-
79
-
80
- def self.push
81
- cmd = 'git push'
82
- Shell.run( cmd )
83
- end
84
-
85
- def self.add( pathspec=nil ) ## e.g. git add . or git add *.rb or such
86
- cmd = 'git add'
87
- cmd << " #{pathspec}" unless pathspec.nil? || pathspec.empty?
88
- Shell.run( cmd )
89
- end
90
-
91
- def self.add_all
92
- cmd = 'git add --all'
93
- Shell.run( cmd )
94
- end
95
-
96
- def self.commit( message: )
97
- cmd = 'git commit'
98
- cmd << %Q{ -m "#{message}"} unless message.nil? || message.empty?
99
- Shell.run( cmd )
100
- end
101
-
102
-
103
- #############
104
- # change git ls-files to git ls-tree ... - why? why not?
105
- #
106
- # git ls-tree --full-tree --name-only -r HEAD
107
- # --full-tree makes the command run as if you were in the repo's root directory.
108
- # -r recurses into subdirectories. Combined with --full-tree, this gives you all committed, tracked files.
109
- # --name-only removes SHA / permission info for when you just want the file paths.
110
- # HEAD specifies which branch you want the list of tracked, committed files for.
111
- # You could change this to master or any other branch name, but HEAD is the commit you have checked out right now.
112
- #
113
- # see https://stackoverflow.com/questions/15606955/how-can-i-make-git-show-a-list-of-the-files-that-are-being-tracked
114
- #
115
- # was:
116
-
117
- def self.files ## was: e.g. git ls-files . or git ls-files *.rb or such
118
- cmd = 'git ls-tree --full-tree --name-only -r HEAD' # was: 'git ls-files'
119
- Shell.run( cmd )
120
- end
121
- ## add list_files or ls_files alias - why? why not?
122
-
123
-
124
- ###
125
- # use nested class for "base" for running commands - why? why not?
126
- class Shell
127
- def self.run( cmd )
128
- print "cmd exec >#{cmd}<..."
129
- stdout, stderr, status = Open3.capture3( cmd )
130
-
131
- if status.success?
132
- print " OK"
133
- print "\n"
134
- else
135
- print " FAIL (#{status.exitstatus})"
136
- print "\n"
137
- end
138
-
139
- unless stdout.empty?
140
- puts stdout
141
- end
142
-
143
- unless stderr.empty?
144
- ## todo/check: or use >2: or &2: or such
145
- ## stderr output not always an error (that is, exit status might be 0)
146
- puts "STDERR:"
147
- puts stderr
148
- end
149
-
150
- if status.success?
151
- stdout # return stdout string
152
- else
153
- puts "!! ERROR: cmd exec >#{cmd}< failed with exit status #{status.exitstatus}:"
154
- puts stderr
155
- raise GitError, "git cmd exec >#{cmd}< failed with exit status #{status.exitstatus}<: #{stderr}"
156
- end
157
- end
158
- end # class Shell
159
-
160
- end # class Git
161
-
162
-
163
-
164
- class GitProject
165
- def self.open( path, &blk )
166
- new( path ).open( &blk )
167
- end
168
-
169
- def initialize( path )
170
- raise ArgumentError, "dir >#{path}< not found; dir MUST already exist for GitProject class - sorry" unless Dir.exist?( path )
171
- raise ArgumentError, "dir >#{path}/.git< not found; dir MUST already be initialized with git for GitProject class - sorry" unless Dir.exist?( "#{path}/.git" )
172
- @path = path
173
- end
174
-
175
-
176
- def open( &blk )
177
- ## puts "Dir.getwd: #{Dir.getwd}"
178
- Dir.chdir( @path ) do
179
- blk.call( self )
180
- end
181
- ## puts "Dir.getwd: #{Dir.getwd}"
182
- end
183
-
184
-
185
- def status( short: false ) Git.status( short: short ); end
186
- def changes() Git.changes; end
187
- def clean?() Git.clean?; end
188
- def changes?() Git.changes?; end
189
- alias_method :dirty?, :changes?
190
-
191
-
192
- def fetch() Git.fetch; end
193
- def pull() Git.pull; end
194
- def fast_forward() Git.fast_forward; end
195
- alias_method :ff, :fast_forward
196
-
197
- def push() Git.push; end
198
-
199
- def add( pathspec ) Git.add( pathspec ); end
200
- def add_all() Git.add_all; end
201
- def commit( message: ) Git.commit( message: message ); end
202
-
203
- def files() Git.files; end
204
-
205
- end # class GitProject
206
-
207
-
208
-
209
-
210
- ## todo: change to GitHubRepoRef or GitHubProject
211
- ## or Git::GitHub or Git::Source::GitHub or such - why? why not?
212
- class GitHubRepo
213
- attr_reader :owner, :name
214
-
215
- def initialize( owner, name )
216
- @owner = owner ## use/rename to login or something - why? why not??
217
- @name = name # e.g. "rubylibs/webservice"
218
- end
219
-
220
- def ssh_clone_url
221
- ## check: use https: as default? for github - http:// still supported? or redirected?
222
- ## "http://github.com/#{@owner}/#{@name}"
223
- "git@github.com:#{@owner}/#{@name}.git"
224
- end
225
- end ## class GitHubRepo
226
-