falkorlib 0.6.19 → 0.7.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.
Files changed (72) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +88 -0
  4. data/.travis.yml +56 -4
  5. data/Gemfile +4 -4
  6. data/Gemfile.lock +55 -27
  7. data/Rakefile +12 -8
  8. data/Vagrantfile +68 -0
  9. data/completion/_falkor +55 -7
  10. data/falkorlib.gemspec +14 -12
  11. data/lib/falkorlib.rb +22 -21
  12. data/lib/falkorlib/bootstrap.rb +5 -1
  13. data/lib/falkorlib/bootstrap/base.rb +385 -693
  14. data/lib/falkorlib/bootstrap/git.rb +137 -0
  15. data/lib/falkorlib/bootstrap/latex.rb +186 -0
  16. data/lib/falkorlib/bootstrap/link.rb +108 -96
  17. data/lib/falkorlib/bootstrap/ruby.rb +102 -0
  18. data/lib/falkorlib/cli.rb +82 -26
  19. data/lib/falkorlib/cli/config.rb +8 -8
  20. data/lib/falkorlib/cli/link.rb +8 -9
  21. data/lib/falkorlib/cli/new.rb +25 -39
  22. data/lib/falkorlib/common.rb +425 -425
  23. data/lib/falkorlib/config.rb +114 -110
  24. data/lib/falkorlib/error.rb +27 -16
  25. data/lib/falkorlib/gem_tasks.rb +12 -11
  26. data/lib/falkorlib/git.rb +3 -4
  27. data/lib/falkorlib/git/base.rb +439 -396
  28. data/lib/falkorlib/git/flow.rb +163 -165
  29. data/lib/falkorlib/git_tasks.rb +31 -31
  30. data/lib/falkorlib/loader.rb +1 -1
  31. data/lib/falkorlib/puppet.rb +3 -5
  32. data/lib/falkorlib/puppet/base.rb +10 -15
  33. data/lib/falkorlib/puppet/modules.rb +367 -365
  34. data/lib/falkorlib/puppet_tasks.rb +11 -8
  35. data/lib/falkorlib/tasks.rb +51 -54
  36. data/lib/falkorlib/tasks/gem.rake +42 -43
  37. data/lib/falkorlib/tasks/gem.rb +12 -11
  38. data/lib/falkorlib/tasks/git.rake +101 -107
  39. data/lib/falkorlib/tasks/git.rb +31 -31
  40. data/lib/falkorlib/tasks/gitflow.rake +131 -141
  41. data/lib/falkorlib/tasks/puppet.rb +11 -8
  42. data/lib/falkorlib/tasks/puppet_modules.rake +143 -154
  43. data/lib/falkorlib/tasks/rspec.rake +94 -59
  44. data/lib/falkorlib/tasks/yard.rake +35 -39
  45. data/lib/falkorlib/version.rb +55 -55
  46. data/lib/falkorlib/versioning.rb +169 -167
  47. data/spec/falkorlib/bootstrap_helpers_spec.rb +106 -56
  48. data/spec/falkorlib/bootstrap_latex_spec.rb +145 -0
  49. data/spec/falkorlib/bootstrap_link_spec.rb +137 -0
  50. data/spec/falkorlib/bootstrap_ruby_spec.rb +118 -0
  51. data/spec/falkorlib/bootstrap_spec.rb +112 -129
  52. data/spec/falkorlib/git_spec.rb +94 -22
  53. data/spec/falkorlib/gitflow_spec.rb +54 -42
  54. data/spec/falkorlib/puppet_modules_spec.rb +35 -26
  55. data/spec/falkorlib/versioning_puppet_module_spec.rb +94 -90
  56. data/spec/falkorlib_spec.rb +5 -0
  57. data/spec/spec_helper.rb +88 -47
  58. data/templates/latex/article-ieee/main.tex.erb +509 -0
  59. data/templates/latex/article/_abstract.tex.erb +19 -0
  60. data/templates/latex/article/_acronyms.tex.erb +116 -0
  61. data/templates/latex/article/_conclusion.tex.erb +25 -0
  62. data/templates/latex/article/_context.tex.erb +17 -0
  63. data/templates/latex/article/_experiments.tex.erb +27 -0
  64. data/templates/latex/article/_implem.tex.erb +17 -0
  65. data/templates/latex/article/_introduction.tex.erb +39 -0
  66. data/templates/latex/article/_related_works.tex.erb +19 -0
  67. data/templates/latex/article/biblio.bib.erb +28 -0
  68. data/templates/latex/article/template.tex.erb +16 -0
  69. data/templates/latex/ieee/IEEEtran.bst +2409 -0
  70. data/templates/latex/ieee/IEEEtran.cls +6347 -0
  71. data/templates/motd/motd.erb +2 -1
  72. metadata +82 -2
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Lun 2015-03-09 12:02 svarrette>
3
+ # Time-stamp: <Fri 2016-11-11 14:21 svarrette>
4
4
  ################################################################################
5
5
  # FalkorLib Configuration
6
6
  #
@@ -15,120 +15,124 @@ require "deep_merge"
15
15
 
16
16
  module FalkorLib #:nodoc:
17
17
 
18
- class << self
19
- # Yields up a configuration object when given a block.
20
- # Without a block it just returns the configuration object.
21
- # Uses Configatron under the covers.
22
- #
23
- # Example:
24
- # FalkorLib.config do |c|
25
- # c.foo = :bar
26
- # end
27
- #
28
- # FalkorLib.config.foo # => :bar
29
- def config(&block)
30
- yield configuration if block_given?
31
- configuration
32
- end
18
+ class << self
33
19
 
34
- ## initiate the configuration (with default value) if needed
35
- def configuration
36
- @config ||= Configatron::Store.new(options = FalkorLib::Config.default)
37
- end
20
+ # Yields up a configuration object when given a block.
21
+ # Without a block it just returns the configuration object.
22
+ # Uses Configatron under the covers.
23
+ #
24
+ # Example:
25
+ # FalkorLib.config do |c|
26
+ # c.foo = :bar
27
+ # end
28
+ #
29
+ # FalkorLib.config.foo # => :bar
30
+ def config
31
+ yield configuration if block_given?
32
+ configuration
38
33
  end
39
34
 
35
+ ## initiate the configuration (with default value) if needed
36
+ def configuration
37
+ @config ||= Configatron::Store.new(FalkorLib::Config.default)
38
+ end
40
39
 
41
- module Config #:nodoc:
42
- # Defaults global settings
43
- DEFAULTS = {
44
- :debug => false,
45
- :verbose => false,
46
- :no_interaction => false,
47
- :root => Dir.pwd,
48
- :config_files => {
49
- :local => '.falkor/config',
50
- :private => '.falkor/private',
51
- #:project => '.falkor/project',
52
- },
53
- #:custom_cfg => '.falkorlib.yaml',
54
- :rvm => {
55
- :rubies => [ '1.9.3', '2.0.0', '2.1.0'],
56
- :version => '1.9.3',
57
- :versionfile => '.ruby-version',
58
- :gemsetfile => '.ruby-gemset'
59
- },
60
- :templates => {
61
- :trashdir => '.Trash',
62
- :puppet => {}
63
- },
64
- :tokens => { :code_climate => '' },
65
- :project => {}
66
- }
67
-
68
- module_function
69
-
70
- ## Build the default configuration hash, to be used to initiate the default.
71
- # The hash is built depending on the loaded files.
72
- def default
73
- res = FalkorLib::Config::DEFAULTS.clone
74
- $LOADED_FEATURES.each do |path|
75
- res[:git] = FalkorLib::Config::Git::DEFAULTS if path.include?('lib/falkorlib/git.rb')
76
- res[:gitflow] = FalkorLib::Config::GitFlow::DEFAULTS if path.include?('lib/falkorlib/git.rb')
77
- res[:versioning] = FalkorLib::Config::Versioning::DEFAULTS if path.include?('lib/falkorlib/versioning.rb')
78
- if path.include?('lib/falkorlib/puppet.rb')
79
- res[:puppet] = FalkorLib::Config::Puppet::DEFAULTS
80
- res[:templates][:puppet][:modules] = FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata]
81
- end
82
- end
83
- # Check the potential local customizations
84
- [:local, :private].each do |type|
85
- custom_cfg = File.join( res[:root], res[:config_files][type.to_sym])
86
- if File.exists?( custom_cfg )
87
- res.deep_merge!( load_config( custom_cfg ) )
88
- end
89
- end
90
- res
91
- end
40
+ end
92
41
 
93
- ###### get ######
94
- # Return the { local | private } FalkorLib configuration
95
- # Supported options:
96
- # * :file [string] filename for the local configuration
97
- ##
98
- def get(dir = Dir.pwd, type = :local, options = {})
99
- conffile = config_file(dir,type,options)
100
- res = {}
101
- res = load_config( conffile ) if File.exists?( conffile )
102
- res
103
- end # get
104
-
105
- ###### get_or_save ######
106
- # wrapper for get and save operations
107
- ##
108
- def config_file(dir = Dir.pwd, type = :local, options = {})
109
- path = normalized_path(dir)
110
- path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
111
- raise FalkorLib::Error, "Wrong FalkorLib configuration type" unless FalkorLib.config[:config_files].keys.include?( type.to_sym)
112
- return options[:file] ? options[:file] : File.join(path, FalkorLib.config[:config_files][type.to_sym])
113
- end # get_or_save
114
-
115
-
116
- ###### save ######
117
- # save the { local | private } configuration on YAML format
118
- # Supported options:
119
- # * :file [string] filename for the saved configuration
120
- # * :no_interaction [boolean]: do not interact
121
- ##
122
- def save(dir = Dir.pwd, config = {}, type = :local, options = {})
123
- conffile = config_file(dir,type,options)
124
- confdir = File.dirname( conffile )
125
- unless File.directory?( confdir )
126
- warning "about to create the configuration directory #{confdir}"
127
- really_continue? unless options[:no_interaction]
128
- run %{ mkdir -p #{confdir} }
129
- end
130
- store_config(conffile, config, options)
131
- end # save
132
42
 
43
+ module Config #:nodoc:
44
+
45
+ # Defaults global settings
46
+ DEFAULTS = {
47
+ :debug => false,
48
+ :verbose => false,
49
+ :no_interaction => false,
50
+ :root => Dir.pwd,
51
+ :config_files => {
52
+ :local => '.falkor/config',
53
+ :private => '.falkor/private',
54
+ #:project => '.falkor/project',
55
+ },
56
+ #:custom_cfg => '.falkorlib.yaml',
57
+ :rvm => {
58
+ :rubies => [ '2.3.1', '2.2.5', '2.1.10', '2.0.0', '1.9.3' ],
59
+ :version => '2.1.10',
60
+ :versionfile => '.ruby-version',
61
+ :gemsetfile => '.ruby-gemset'
62
+ },
63
+ :templates => {
64
+ :trashdir => '.Trash',
65
+ :puppet => {}
66
+ },
67
+ :tokens => { :code_climate => '' },
68
+ :project => {}
69
+ }
70
+
71
+ module_function
72
+
73
+ ## Build the default configuration hash, to be used to initiate the default.
74
+ # The hash is built depending on the loaded files.
75
+ def default
76
+ res = FalkorLib::Config::DEFAULTS.clone
77
+ $LOADED_FEATURES.each do |path|
78
+ res[:git] = FalkorLib::Config::Git::DEFAULTS if path.include?('lib/falkorlib/git.rb')
79
+ res[:gitflow] = FalkorLib::Config::GitFlow::DEFAULTS if path.include?('lib/falkorlib/git.rb')
80
+ res[:versioning] = FalkorLib::Config::Versioning::DEFAULTS if path.include?('lib/falkorlib/versioning.rb')
81
+ if path.include?('lib/falkorlib/puppet.rb')
82
+ res[:puppet] = FalkorLib::Config::Puppet::DEFAULTS
83
+ res[:templates][:puppet][:modules] = FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata]
84
+ end
85
+ end
86
+ # Check the potential local customizations
87
+ [:local, :private].each do |type|
88
+ custom_cfg = File.join( res[:root], res[:config_files][type.to_sym])
89
+ if File.exist?( custom_cfg )
90
+ res.deep_merge!( load_config( custom_cfg ) )
91
+ end
92
+ end
93
+ res
133
94
  end
95
+
96
+ ###### get ######
97
+ # Return the { local | private } FalkorLib configuration
98
+ # Supported options:
99
+ # * :file [string] filename for the local configuration
100
+ ##
101
+ def get(dir = Dir.pwd, type = :local, options = {})
102
+ conffile = config_file(dir, type, options)
103
+ res = {}
104
+ res = load_config( conffile ) if File.exist?( conffile )
105
+ res
106
+ end # get
107
+
108
+ ###### get_or_save ######
109
+ # wrapper for get and save operations
110
+ ##
111
+ def config_file(dir = Dir.pwd, type = :local, options = {})
112
+ path = normalized_path(dir)
113
+ path = FalkorLib::Git.rootdir(path) if FalkorLib::Git.init?(path)
114
+ raise FalkorLib::Error, "Wrong FalkorLib configuration type" unless FalkorLib.config[:config_files].keys.include?( type.to_sym)
115
+ (options[:file]) ? options[:file] : File.join(path, FalkorLib.config[:config_files][type.to_sym])
116
+ end # get_or_save
117
+
118
+
119
+ ###### save ######
120
+ # save the { local | private } configuration on YAML format
121
+ # Supported options:
122
+ # * :file [string] filename for the saved configuration
123
+ # * :no_interaction [boolean]: do not interact
124
+ ##
125
+ def save(dir = Dir.pwd, config = {}, type = :local, options = {})
126
+ conffile = config_file(dir, type, options)
127
+ confdir = File.dirname( conffile )
128
+ unless File.directory?( confdir )
129
+ warning "about to create the configuration directory #{confdir}"
130
+ really_continue? unless options[:no_interaction]
131
+ run %( mkdir -p #{confdir} )
132
+ end
133
+ store_config(conffile, config, options)
134
+ end # save
135
+
136
+ end
137
+
134
138
  end # module FalkorLib
@@ -1,28 +1,39 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Sam 2015-01-31 21:07 svarrette>
3
+ # Time-stamp: <Fri 2016-11-11 14:25 svarrette>
4
4
  ################################################################################
5
5
  # Falkorlib errors
6
6
 
7
7
  module FalkorLib
8
8
 
9
- # Errors
10
- class Error < ::StandardError
9
+ # Errors
10
+ class Error < ::StandardError
11
11
 
12
- class << self
13
- attr_accessor :status_code
14
- end
12
+ class << self
15
13
 
16
- def status_code
17
- self.class.status_code
18
- end
14
+ attr_accessor :status_code
15
+
16
+ end
17
+
18
+ def status_code
19
+ self.class.status_code
19
20
  end
20
21
 
21
- class Exit < Error; self.status_code = 0; end
22
- class FalkorError < Error; self.status_code = 1; end
23
- class ExecError < Error; self.status_code = 2; end
24
- class InternalError < Error; self.status_code = 3; end
25
- class ArgumentError < Error; self.status_code = 4; end
26
- class AbortError < Error; self.status_code = 5; end
27
- class TemplateNotFound < Error; self.status_code = 6; end
22
+ end
23
+
24
+ # default Exit
25
+ class Exit < Error; self.status_code = 0; end
26
+ # regular error
27
+ class FalkorError < Error; self.status_code = 1; end
28
+ # execution error
29
+ class ExecError < Error; self.status_code = 2; end
30
+ # internal management error
31
+ class InternalError < Error; self.status_code = 3; end
32
+ # argument error
33
+ class ArgumentError < Error; self.status_code = 4; end
34
+ # abording
35
+ class AbortError < Error; self.status_code = 5; end
36
+ # template not found
37
+ class TemplateNotFound < Error; self.status_code = 6; end
38
+
28
39
  end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Ven 2014-06-20 00:10 svarrette>
3
+ # Time-stamp: <Fri 2016-11-11 14:28 svarrette>
4
4
  ################################################################################
5
5
  #
6
6
  # FalkorLib rake tasks to pilot Gem operations
@@ -11,18 +11,19 @@ require 'falkorlib'
11
11
  require 'falkorlib/tasks'
12
12
 
13
13
  module FalkorLib #:nodoc:
14
+ # Rake tasks to pilot Gem operations
15
+ class GemTasks
14
16
 
15
- # Rake tasks to pilot Gem operations
16
- class GemTasks
17
- include Rake::DSL if defined? Rake::DSL
17
+ include Rake::DSL if defined? Rake::DSL
18
18
 
19
- # Install the gem tasks for Rake
20
- def install_tasks
21
- load 'falkorlib/tasks/gem.rake'
22
- load 'falkorlib/tasks/yard.rake'
23
- load 'falkorlib/tasks/rspec.rake'
24
- end
25
- end # class FalkorLib::GemTasks
19
+ # Install the gem tasks for Rake
20
+ def install_tasks
21
+ load 'falkorlib/tasks/gem.rake'
22
+ load 'falkorlib/tasks/yard.rake'
23
+ load 'falkorlib/tasks/rspec.rake'
24
+ end
25
+
26
+ end # class FalkorLib::GemTasks
26
27
  end # module FalkorLib
27
28
 
28
29
  # Now install them ;)
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Ven 2014-06-06 13:12 svarrette>
3
+ # Time-stamp: <Wed 2016-11-09 09:15 svarrette>
4
4
  ################################################################################
5
5
  # Management of Git [flow] operations
6
6
 
@@ -10,6 +10,5 @@ module FalkorLib #:nodoc:
10
10
 
11
11
  end # module FalkorLib
12
12
 
13
- require "falkorlib/git/base"
14
- require "falkorlib/git/flow"
15
-
13
+ require 'falkorlib/git/base'
14
+ require 'falkorlib/git/flow'
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Tue 2016-02-02 20:58 svarrette>
3
+ # Time-stamp: <Sat 2016-11-12 12:27 svarrette>
4
4
  ################################################################################
5
5
  # Interface for the main Git operations
6
6
  #
@@ -15,441 +15,484 @@ require "pathname"
15
15
 
16
16
  include FalkorLib::Common
17
17
 
18
- module FalkorLib #:nodoc:
19
- module Config
20
-
21
- # Default configuration for Git
22
- module Git
23
- # Git defaults for FalkorLib
24
- DEFAULTS = {
25
- :submodulesdir => '.submodules',
26
- :submodules => {},
27
- :subtrees => {}
28
- }
29
- end
30
- end
18
+ module FalkorLib #:nodoc:
31
19
 
32
- # Management of Git operations
20
+ module Config
21
+ # Default configuration for Git
33
22
  module Git
34
- module_function
35
-
36
- ## Check if a git directory has been initialized
37
- def init?(path = Dir.pwd)
38
- begin
39
- g = MiniGit.new(path)
40
- rescue Exception
41
- return false
42
- end
43
- return true
44
- end
45
23
 
46
- ## Check if the repositories already holds some commits
47
- def has_commits?(path)
48
- res = false
49
- Dir.chdir(path) do
50
- stdout, stderr, exit_status = Open3.capture3( "git rev-parse HEAD" )
51
- res = (exit_status == 0)
52
- end
53
- res
54
- end
55
-
56
- ## Check the availability of a given git command
57
- def command?(cmd)
58
- cg = MiniGit::Capturing.new()
59
- cmd_list = cg.help :a => true
60
- # typical run:
61
- # usage: git [--version] [--help] [-C <path>] [-c name=value]
62
- # [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
63
- # [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
64
- # [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
65
- # <command> [<args>]
66
- #
67
- # available git commands in '/usr/local/Cellar/git/1.8.5.2/libexec/git-core'
68
- #
69
- # add [...] \
70
- # [...] | The part we are interested in, delimited by '\n\n' sequence
71
- # [...] /
72
- #
73
- # 'git help -a' and 'git help -g' lists available subcommands and some
74
- # concept guides. See 'git help <command>' or 'git help <concept>'
75
- # to read about a specific subcommand or concept
76
- l = cmd_list.split("\n\n")
77
- l.shift # useless first part
78
- #ap l
79
- subl = l.each_index.select{|i| l[i] =~ /^\s\s+/ } # find sublines that starts with at least two whitespaces
80
- #ap subl
81
- return false if subl.empty?
82
- subl.any? { |i| l[i].split.include?(cmd) }
83
- end
24
+ # Git defaults for FalkorLib
25
+ DEFAULTS = {
26
+ :submodulesdir => '.submodules',
27
+ :submodules => {},
28
+ :subtrees => {}
29
+ }
84
30
 
85
- ###
86
- # Initialize a git repository
87
- ##
88
- def init(path = Dir.pwd, options = {})
89
- # FIXME for travis test: ensure the global git configurations
90
- # 'user.email' and 'user.name' are set
91
- [ 'user.name', 'user.email' ].each do |userconf|
92
- if MiniGit[userconf].nil?
93
- warn "The Git global configuration '#{userconf}' is not set so"
94
- warn "you should *seriously* consider setting them by running\n\t git config --global #{userconf} 'your_#{userconf.sub(/\./, '_')}'"
95
- default_val = ENV['USER']
96
- default_val += '@domain.org' if userconf =~ /email/
97
- warn "Now putting a default value '#{default_val}' you could change later on"
98
- run %{
99
- git config --global #{userconf} "#{default_val}"
100
- }
101
- #MiniGit[userconf] = default_val
102
- end
103
- end
104
- exit_status = 1
105
- Dir.mkdir( path ) unless Dir.exist?( path )
106
- Dir.chdir( path ) do
107
- execute "git init" unless FalkorLib.config.debug
108
- exit_status = $?.to_i
109
- end
110
- # #puts "#init #{path}"
111
- # Dir.chdir( "#{path}" ) do
112
- # %x[ pwd && git init ] unless FalkorLib.config.debug
113
- # end
114
- exit_status
115
- end
31
+ end
32
+ end
116
33
 
117
- # Return the Git working tree from the proposed path (current directory by default)
118
- def rootdir(path = Dir.pwd)
119
- g = MiniGit.new
120
- g.find_git_dir(path)[1]
121
- end
34
+ # Management of Git operations
35
+ module Git
122
36
 
123
- # Return the git root directory for the path (current directory by default)
124
- def gitdir(path = Dir.pwd)
125
- g = MiniGit.new
126
- g.find_git_dir(path)[0]
127
- end
37
+ module_function
128
38
 
129
- # Create a new branch
130
- def create_branch(branch, path = Dir.pwd)
131
- #ap method(__method__).parameters.map { |arg| arg[1] }
132
- g = MiniGit.new(path)
133
- error "not yet any commit performed -- You shall do one" unless has_commits?(path)
134
- g.branch "#{branch}"
135
- end
39
+ ## Check if a git directory has been initialized
40
+ def init?(path = Dir.pwd)
41
+ begin
42
+ MiniGit.new(path)
43
+ rescue Exception
44
+ return false
45
+ end
46
+ true
47
+ end
136
48
 
137
- # Delete a branch.
138
- def delete_branch(branch, path = Dir.pwd, opts = { :force => false })
139
- g = MiniGit.new(path)
140
- error "'#{branch}' is not a valid existing branch" unless list_branch(path).include?( branch )
141
- g.branch (opts[:force] ? :D : :d) => "#{branch}"
142
- end
49
+ ## Check if the repositories already holds some commits
50
+ def commits?(path)
51
+ res = false
52
+ Dir.chdir(path) do
53
+ _stdout, _stderr, exit_status = Open3.capture3( "git rev-parse HEAD" )
54
+ res = (exit_status.to_i.zero?)
55
+ end
56
+ res
57
+ end
143
58
 
144
- ###### config ######
145
- # Retrieve the Git configuration
146
- # You can propose a pattern as key
147
- # Supported options:
148
- # * :list [boolean] list all configutations
149
- # * :hash [boolean] return a Hash
150
- ##
151
- def config(key, dir = Dir.pwd, options = {})
152
- #info "Retrieve the Git configuration"
153
- res = nil
154
- if (options[:list] or (key.is_a? Regexp) or (key =~ /\*/))
155
- cg = MiniGit::Capturing.new(dir)
156
- res = (cg.config :list => true).split("\n")
157
- res.select! { |e| e.match(key) } unless key =='*'
158
- #res = res.map { |e| e.split('=') }.to_h if options[:hash]
159
- res = Hash[ res.map { |e| e.split('=') } ] if options[:hash]
160
- else
161
- g = MiniGit.new(dir)
162
- res = g[key]
163
- res = { key => g[key] } if options[:hash]
164
- end
165
- #ap res
166
- res
167
- end
59
+ ## Check the availability of a given git command
60
+ def command?(cmd)
61
+ cg = MiniGit::Capturing.new
62
+ cmd_list = cg.help :a => true
63
+ # typical run:
64
+ # usage: git [--version] [--help] [-C <path>] [-c name=value]
65
+ # [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
66
+ # [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
67
+ # [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
68
+ # <command> [<args>]
69
+ #
70
+ # available git commands in '/usr/local/Cellar/git/1.8.5.2/libexec/git-core'
71
+ #
72
+ # add [...] \
73
+ # [...] | The part we are interested in, delimited by '\n\n' sequence
74
+ # [...] /
75
+ #
76
+ # 'git help -a' and 'git help -g' lists available subcommands and some
77
+ # concept guides. See 'git help <command>' or 'git help <concept>'
78
+ # to read about a specific subcommand or concept
79
+ l = cmd_list.split("\n\n")
80
+ l.shift # useless first part
81
+ #ap l
82
+ subl = l.each_index.select { |i| l[i] =~ /^\s\s+/ } # find sublines that starts with at least two whitespaces
83
+ #ap subl
84
+ return false if subl.empty?
85
+ subl.any? { |i| l[i].split.include?(cmd) }
86
+ end
168
87
 
169
-
170
- ## Fetch the latest changes
171
- def fetch(path = Dir.pwd)
172
- Dir.chdir( path ) do
173
- execute "git fetch --all -v"
174
- end
175
- end
88
+ ###
89
+ # Initialize a git repository
90
+ ##
91
+ def init(path = Dir.pwd, _options = {})
92
+ # FIXME: for travis test: ensure the global git configurations
93
+ # 'user.email' and 'user.name' are set
94
+ [ 'user.name', 'user.email' ].each do |userconf|
95
+ next unless MiniGit[userconf].nil?
96
+ warn "The Git global configuration '#{userconf}' is not set so"
97
+ warn "you should *seriously* consider setting them by running\n\t git config --global #{userconf} 'your_#{userconf.sub(/\./, '_')}'"
98
+ default_val = ENV['USER']
99
+ default_val += '@domain.org' if userconf =~ /email/
100
+ warn "Now putting a default value '#{default_val}' you could change later on"
101
+ run %(
102
+ git config --global #{userconf} "#{default_val}"
103
+ )
104
+ #MiniGit[userconf] = default_val
105
+ end
106
+ exit_status = 1
107
+ Dir.mkdir( path ) unless Dir.exist?( path )
108
+ Dir.chdir( path ) do
109
+ execute "git init" unless FalkorLib.config.debug
110
+ exit_status = $?.to_i
111
+ end
112
+ # #puts "#init #{path}"
113
+ # Dir.chdir( "#{path}" ) do
114
+ # %x[ pwd && git init ] unless FalkorLib.config.debug
115
+ # end
116
+ exit_status
117
+ end
176
118
 
177
- ## Get an array of the local branches present (first element is always the
178
- ## current branch)
179
- def list_branch(path = Dir.pwd)
180
- cg = MiniGit::Capturing.new(path)
181
- res = cg.branch :a => true
182
- res = res.split("\n")
183
- # Eventually reorder to make the first element of the array the current branch
184
- i = res.find_index { |e| e =~ /^\*\s/ }
185
- unless (i.nil? || i == 0)
186
- res[0], res[i] = res[i], res[0]
187
- end
188
- res.each { |e| e.sub!(/^\*?\s+/, '') }
189
- res
190
- end
119
+ # Return the Git working tree from the proposed path (current directory by default)
120
+ def rootdir(path = Dir.pwd)
121
+ g = MiniGit.new
122
+ g.find_git_dir(path)[1]
123
+ end
191
124
 
192
- ## Get the current git branch
193
- def branch?(path = Dir.pwd)
194
- list_branch(path)[0]
195
- end
125
+ # Return the git root directory for the path (current directory by default)
126
+ def gitdir(path = Dir.pwd)
127
+ g = MiniGit.new
128
+ g.find_git_dir(path)[0]
129
+ end
196
130
 
197
- ## Grab a remote branch
198
- def grab(branch, path = Dir.pwd, remote = 'origin')
199
- exit_status = 1
200
- error "no branch provided" if branch.nil?
201
- remotes = FalkorLib::Git.remotes(path)
202
- branches = FalkorLib::Git.list_branch(path)
203
- Dir.chdir(FalkorLib::Git.rootdir( path ) ) do
204
- if branches.include? "remotes/#{remote}/#{branch}"
205
- info "Grab the branch '#{remote}/#{branch}'"
206
- exit_status = execute "git branch --set-upstream #{branch} #{remote}/#{branch}"
207
- else
208
- warning "the remote branch '#{remote}/#{branch}' cannot be found"
209
- end
210
- end
211
- exit_status
212
- end
131
+ # Create a new branch
132
+ def create_branch(branch, path = Dir.pwd)
133
+ #ap method(__method__).parameters.map { |arg| arg[1] }
134
+ g = MiniGit.new(path)
135
+ error "not yet any commit performed -- You shall do one" unless commits?(path)
136
+ g.branch branch.to_s
137
+ end
138
+
139
+ # Delete a branch.
140
+ def delete_branch(branch, path = Dir.pwd, opts = { :force => false })
141
+ g = MiniGit.new(path)
142
+ error "'#{branch}' is not a valid existing branch" unless list_branch(path).include?( branch )
143
+ g.branch ((opts[:force]) ? :D : :d) => branch.to_s
144
+ end
213
145
 
214
- ## Publish a branch on the remote
215
- def publish(branch, path = Dir.pwd, remote = 'origin')
216
- exit_status = 1
217
- error "no branch provided" if branch.nil?
218
- remotes = FalkorLib::Git.remotes(path)
219
- branches = FalkorLib::Git.list_branch(path)
220
- Dir.chdir(FalkorLib::Git.rootdir( path ) ) do
221
- if branches.include? "remotes/#{remote}/#{branch}"
222
- warning "the remote branch '#{remote}/#{branch}' already exists"
223
- else
224
- info "Publish the branch '#{branch}' on the remote '#{remote}'"
225
- exit_status = run %{
146
+ ###### config ######
147
+ # Retrieve the Git configuration
148
+ # You can propose a pattern as key
149
+ # Supported options:
150
+ # * :list [boolean] list all configurations
151
+ # * :hash [boolean] return a Hash
152
+ ##
153
+ def config(key, dir = Dir.pwd, options = {})
154
+ #info "Retrieve the Git configuration"
155
+ res = nil
156
+ if (options[:list] || (key.is_a? Regexp) || (key =~ /\*/))
157
+ cg = MiniGit::Capturing.new(dir)
158
+ res = (cg.config :list => true).split("\n")
159
+ res.select! { |e| e.match(key) } unless key == '*'
160
+ #res = res.map { |e| e.split('=') }.to_h if options[:hash]
161
+ res = Hash[ res.map { |e| e.split('=') } ] if options[:hash]
162
+ else
163
+ g = MiniGit.new(dir)
164
+ res = g[key]
165
+ res = { key => g[key] } if options[:hash]
166
+ end
167
+ #ap res
168
+ res
169
+ end
170
+
171
+
172
+ ## Fetch the latest changes
173
+ def fetch(path = Dir.pwd)
174
+ Dir.chdir( path ) do
175
+ execute "git fetch --all -v"
176
+ end
177
+ end
178
+
179
+ ## Get an array of the local branches present (first element is always the
180
+ ## current branch)
181
+ def list_branch(path = Dir.pwd)
182
+ cg = MiniGit::Capturing.new(path)
183
+ res = cg.branch :a => true
184
+ res = res.split("\n")
185
+ # Eventually reorder to make the first element of the array the current branch
186
+ i = res.find_index { |e| e =~ /^\*\s/ }
187
+ res[0], res[i] = res[i], res[0] unless (i.nil? || i.zero?)
188
+ res.each { |e| e.sub!(/^\*?\s+/, '') }
189
+ res
190
+ end
191
+
192
+
193
+ ## Get the current git branch
194
+ def branch?(path = Dir.pwd)
195
+ list_branch(path)[0]
196
+ end
197
+
198
+ ## Grab a remote branch
199
+ def grab(branch, path = Dir.pwd, remote = 'origin')
200
+ exit_status = 1
201
+ error "no branch provided" if branch.nil?
202
+ #remotes = FalkorLib::Git.remotes(path)
203
+ branches = FalkorLib::Git.list_branch(path)
204
+ if branches.include? "remotes/#{remote}/#{branch}"
205
+ info "Grab the branch '#{remote}/#{branch}'"
206
+ exit_status = execute_in_dir(FalkorLib::Git.rootdir( path ), "git branch --track #{branch} #{remote}/#{branch}")
207
+ else
208
+ warning "the remote branch '#{remote}/#{branch}' cannot be found"
209
+ end
210
+ exit_status
211
+ end
212
+
213
+ ## Publish a branch on the remote
214
+ def publish(branch, path = Dir.pwd, remote = 'origin')
215
+ exit_status = 1
216
+ error "no branch provided" if branch.nil?
217
+ #remotes = FalkorLib::Git.remotes(path)
218
+ branches = FalkorLib::Git.list_branch(path)
219
+ Dir.chdir(FalkorLib::Git.rootdir( path ) ) do
220
+ if branches.include? "remotes/#{remote}/#{branch}"
221
+ warning "the remote branch '#{remote}/#{branch}' already exists"
222
+ else
223
+ info "Publish the branch '#{branch}' on the remote '#{remote}'"
224
+ exit_status = run %(
226
225
  git push #{remote} #{branch}:refs/heads/#{branch}
227
226
  git fetch #{remote}
228
- git branch --set-upstream-to #{remote}/#{branch} #{branch}
229
- }
230
- end
231
- end
232
- exit_status
227
+ git branch -u #{remote}/#{branch} #{branch}
228
+ )
233
229
  end
230
+ end
231
+ exit_status
232
+ end
234
233
 
235
- ## List the files currently under version
236
- def list_files(path = Dir.pwd)
237
- g = MiniGit.new(path)
238
- g.capturing.ls_files.split
239
- end
240
-
241
- ## Add a file/whatever to Git and commit it
242
- # Supported options:
243
- # * :force [boolean]: force the add
244
- def add(path, msg = "", options = {})
245
- exit_status = 0
246
- dir = File.realpath File.dirname(path)
247
- root = rootdir(path)
248
- relative_path_to_root = Pathname.new( File.realpath(path) ).relative_path_from Pathname.new(root)
249
- real_msg = (msg.empty? ? "add '#{relative_path_to_root}'" : msg)
250
- opts = '-f' if options[:force]
251
- Dir.chdir( dir ) do
252
- exit_status = run %{
234
+ ## List the files currently under version
235
+ def list_files(path = Dir.pwd)
236
+ g = MiniGit.new(path)
237
+ g.capturing.ls_files.split
238
+ end
239
+
240
+ ## Add a file/whatever to Git and commit it
241
+ # Supported options:
242
+ # * :force [boolean]: force the add
243
+ def add(path, msg = "", options = {})
244
+ exit_status = 0
245
+ dir = File.realpath(File.dirname(path))
246
+ root = rootdir(path)
247
+ relative_path_to_root = Pathname.new( File.realpath(path) ).relative_path_from Pathname.new(root)
248
+ real_msg = ((msg.empty?) ? "add '#{relative_path_to_root}'" : msg)
249
+ opts = '-f' if options[:force]
250
+ Dir.chdir( dir ) do
251
+ exit_status = run %(
253
252
  git add #{opts} #{path}
254
253
  git commit -s -m "#{real_msg}" #{path}
255
- }
256
- end
257
- exit_status.to_i
258
- end
254
+ )
255
+ end
256
+ exit_status.to_i
257
+ end
259
258
 
260
- ## Check if a git directory is in dirty mode
261
- # git diff --shortstat 2> /dev/null | tail -n1
262
- def dirty?(path = Dir.pwd)
263
- g = MiniGit.new(path)
264
- a = g.capturing.diff :shortstat => true
265
- #ap a
266
- ! a.empty?
267
- end
259
+ ## Check if a git directory is in dirty mode
260
+ # git diff --shortstat 2> /dev/null | tail -n1
261
+ def dirty?(path = Dir.pwd)
262
+ g = MiniGit.new(path)
263
+ a = g.capturing.diff :shortstat => true
264
+ #ap a
265
+ !a.empty?
266
+ end
268
267
 
269
- ## Get the last tag commit, or nil if no tag can be found
270
- def last_tag_commit(path = Dir.pwd)
271
- res = nil
272
- g = MiniGit.new(path)
273
- # git rev-list --tags --max-count=1)
274
- a = g.capturing.rev_list :tags => true, :max_count => 1
275
- a
276
- end # last_tag_commit
277
-
278
- ## List of Git remotes
279
- def remotes(path = Dir.pwd)
280
- g = MiniGit.new(path)
281
- g.capturing.remote.split()
282
- end
268
+ ## Get a hash table of tags under the format
269
+ # { <tag> => <commit> }
270
+ def list_tag(path = Dir.pwd)
271
+ res = {}
272
+ cg = MiniGit::Capturing.new(path)
273
+ unless (cg.tag :list => true).empty?
274
+ # git show-ref --tags
275
+ a = (cg.show_ref :tags => true).split("\n")
276
+ res = Hash[ a.collect { |item| item.split(' refs/tags/') } ].invert
277
+ end
278
+ res
279
+ end # list_tag
280
+
281
+ ## Get the last tag commit, or nil if no tag can be found
282
+ def last_tag_commit(path = Dir.pwd)
283
+ res = ""
284
+ g = MiniGit.new(path)
285
+ unless (g.capturing.tag :list => true).empty?
286
+ # git rev-list --tags --max-count=1
287
+ res = (g.capturing.rev_list :tags => true, :max_count => 1).chomp
288
+ end
289
+ res
290
+ end # last_tag_commit
291
+
292
+ ## Create a new tag
293
+ # You can add extra options to the git tag command through the opts hash.
294
+ # Ex:
295
+ # FalkorLib::Git.tag('name', dir, { :delete => true } )
296
+ #
297
+ def tag(name, path = Dir.pwd, opts = {})
298
+ g = MiniGit.new(path)
299
+ g.tag opts, name
300
+ end # tag
301
+
302
+ ## List of Git remotes
303
+ def remotes(path = Dir.pwd)
304
+ g = MiniGit.new(path)
305
+ g.capturing.remote.split
306
+ end
307
+
308
+ ## Check existence of remotes
309
+ def remotes?(path = Dir.pwd)
310
+ !remotes(path).empty?
311
+ end
312
+
313
+ # Create a new remote <name> targeting url <url>
314
+ # You can pass additional options expected by git remote add in <opts>,
315
+ # for instance as follows:
316
+ #
317
+ # create_remote('origin', url, dir, { :fetch => true })
318
+ #
319
+ def create_remote(name, url, path = Dir.pwd, opts = {})
320
+ g = MiniGit.new(path)
321
+ g.remote :add, opts, name, url.to_s
322
+ end
283
323
 
284
- ## remotes?(path = Dir.pw)
285
- def remotes?(path = Dir.pwd)
286
- return ! remotes(path).empty?
287
- end
288
-
289
- ###
290
- # Initialize git submodule from the configuration
291
- ##
292
- def submodule_init(path = Dir.pwd, submodules = FalkorLib.config.git[:submodules], options = {})
293
- exit_status = 1
294
- git_root_dir = rootdir(path)
295
- if File.exists?("#{git_root_dir}/.gitmodules")
296
- unless submodules.empty?
297
- # TODO: Check if it contains all submodules of the configuration
298
- end
299
- end
300
- #ap FalkorLib.config.git
301
- Dir.chdir(git_root_dir) do
302
- exit_status = FalkorLib::Git.submodule_update( git_root_dir )
303
- submodules.each do |subdir,conf|
304
- next if conf[:url].nil?
305
- url = conf[:url]
306
- dir = "#{FalkorLib.config.git[:submodulesdir]}/#{subdir}"
307
- branch = conf[:branch].nil? ? 'master' : conf[:branch]
308
- if File.directory?( dir )
309
- puts " ... the git submodule '#{subdir}' is already setup."
310
- else
311
- info "adding Git submodule '#{dir}' from '#{url}'"
312
- exit_status = run %{
324
+ # Delete a branch.
325
+ # def delete_branch(branch, path = Dir.pwd, opts = { :force => false })
326
+ # g = MiniGit.new(path)
327
+ # error "'#{branch}' is not a valid existing branch" unless list_branch(path).include?( branch )
328
+ # g.branch (opts[:force] ? :D : :d) => "#{branch}"
329
+ # end
330
+
331
+
332
+ ###
333
+ # Initialize git submodule from the configuration
334
+ ##
335
+ def submodule_init(path = Dir.pwd, submodules = FalkorLib.config.git[:submodules], _options = {})
336
+ exit_status = 1
337
+ git_root_dir = rootdir(path)
338
+ if File.exist?("#{git_root_dir}/.gitmodules")
339
+ unless submodules.empty?
340
+ # TODO: Check if it contains all submodules of the configuration
341
+ end
342
+ end
343
+ #ap FalkorLib.config.git
344
+ Dir.chdir(git_root_dir) do
345
+ exit_status = FalkorLib::Git.submodule_update( git_root_dir )
346
+ submodules.each do |subdir, conf|
347
+ next if conf[:url].nil?
348
+ url = conf[:url]
349
+ dir = "#{FalkorLib.config.git[:submodulesdir]}/#{subdir}"
350
+ branch = (conf[:branch].nil?) ? 'master' : conf[:branch]
351
+ if File.directory?( dir )
352
+ puts " ... the git submodule '#{subdir}' is already setup."
353
+ else
354
+ info "adding Git submodule '#{dir}' from '#{url}'"
355
+ exit_status = run %(
313
356
  git submodule add -b #{branch} #{url} #{dir}
314
357
  git commit -s -m "Add Git submodule '#{dir}' from '#{url}'" .gitmodules #{dir}
315
- }
316
- end
317
- end
318
- end
319
- exit_status
358
+ )
359
+ end
320
360
  end
361
+ end
362
+ exit_status
363
+ end
321
364
 
322
- ## Update the Git submodules to the **local** registered version
323
- def submodule_update(path = Dir.pwd)
324
- execute_in_dir(rootdir(path),
325
- %{
365
+ ## Update the Git submodules to the **local** registered version
366
+ def submodule_update(path = Dir.pwd)
367
+ execute_in_dir(rootdir(path),
368
+ %(
326
369
  git submodule init
327
- git submodule foreach git fetch
328
370
  git submodule update
329
- })
330
- end
371
+ ))
372
+ end
331
373
 
332
- ## Upgrade the Git submodules to the latest HEAD version from the remote
333
- def submodule_upgrade(path = Dir.pwd)
334
- execute_in_dir(rootdir(path),
335
- %{
374
+ ## Upgrade the Git submodules to the latest HEAD version from the remote
375
+ def submodule_upgrade(path = Dir.pwd)
376
+ execute_in_dir(rootdir(path),
377
+ %{
336
378
  git submodule foreach 'git fetch origin; git checkout $(git rev-parse --abbrev-ref HEAD); git reset --hard origin/$(git rev-parse --abbrev-ref HEAD); git submodule update --recursive; git clean -dfx'
337
- })
338
- end
379
+ })
380
+ end
339
381
 
340
382
 
341
- ## Initialize git subtrees from the configuration
342
- def subtree_init(path = Dir.pwd)
343
- raise ArgumentError, "Git 'subtree' command is not available" unless FalkorLib::Git.command? "subtree"
344
- if FalkorLib.config.git[:subtrees].empty?
345
- FalkorLib::Git.config_warn(:subtrees)
346
- return 1
347
- end
348
- exit_status = 0
349
- git_root_dir = rootdir(path)
350
- Dir.chdir(git_root_dir) do
351
- FalkorLib.config.git[:subtrees].each do |dir,conf|
352
- next if conf[:url].nil?
353
- url = conf[:url]
354
- remote = dir.gsub(/\//, '-')
355
- branch = conf[:branch].nil? ? 'master' : conf[:branch]
356
- remotes = FalkorLib::Git.remotes
357
- unless remotes.include?( remote )
358
- info "Initialize Git remote '#{remote}' from URL '#{url}'"
359
- exit_status = execute "git remote add -f #{remote} #{url}"
360
- end
361
- unless File.directory?( File.join(git_root_dir, dir) )
362
- info "initialize Git subtree '#{dir}'"
363
- exit_status = execute "git subtree add --prefix #{dir} --squash #{remote}/#{branch}"
364
- end
365
- end
366
-
367
- end
368
- exit_status
383
+ ## Initialize git subtrees from the configuration
384
+ def subtree_init(path = Dir.pwd)
385
+ raise ArgumentError, "Git 'subtree' command is not available" unless FalkorLib::Git.command? "subtree"
386
+ if FalkorLib.config.git[:subtrees].empty?
387
+ FalkorLib::Git.config_warn(:subtrees)
388
+ return 1
389
+ end
390
+ exit_status = 0
391
+ git_root_dir = rootdir(path)
392
+ Dir.chdir(git_root_dir) do
393
+ FalkorLib.config.git[:subtrees].each do |dir, conf|
394
+ next if conf[:url].nil?
395
+ url = conf[:url]
396
+ remote = dir.gsub(/\//, '-')
397
+ branch = (conf[:branch].nil?) ? 'master' : conf[:branch]
398
+ remotes = FalkorLib::Git.remotes
399
+ unless remotes.include?( remote )
400
+ info "Initialize Git remote '#{remote}' from URL '#{url}'"
401
+ exit_status = execute "git remote add -f #{remote} #{url}"
402
+ end
403
+ unless File.directory?( File.join(git_root_dir, dir) )
404
+ info "initialize Git subtree '#{dir}'"
405
+ exit_status = execute "git subtree add --prefix #{dir} --squash #{remote}/#{branch}"
406
+ end
369
407
  end
408
+ end
409
+ exit_status
410
+ end
370
411
 
371
- ## Check if the subtrees have been initialized.
372
- ## Actually based on a naive check of sub-directory existence
373
- def subtree_init?(path = Dir.pwd)
374
- res = true
375
- FalkorLib.config.git[:subtrees].keys.each do |dir|
376
- res = res && File.directory?(File.join(path, dir))
377
- end
378
- res
379
- end # subtree_init?
380
-
381
-
382
- ## Show difference between local subtree(s) and their remotes"
383
- def subtree_diff(path = Dir.pwd)
384
- raise ArgumentError, "Git 'subtree' command is not available" unless FalkorLib::Git.command? "subtree"
385
- if FalkorLib.config.git[:subtrees].empty?
386
- FalkorLib::Git.config_warn(:subtrees)
387
- return 1
388
- end
389
- exit_status = 0
390
- git_root_dir = rootdir(path)
391
- Dir.chdir(git_root_dir) do
392
- FalkorLib.config.git[:subtrees].each do |dir,conf|
393
- next if conf[:url].nil?
394
- url = conf[:url]
395
- remote = dir.gsub(/\//, '-')
396
- branch = conf[:branch].nil? ? 'master' : conf[:branch]
397
- remotes = FalkorLib::Git.remotes
398
- raise IOError, "The git remote '#{remote}' is not configured" unless remotes.include?( remote )
399
- raise IOError, "The git subtree directory '#{dir}' does not exists" unless File.directory? ( File.join(git_root_dir, dir) )
400
- info "Git diff on subtree '#{dir}' with remote '#{remote}/#{branch}'"
401
- exit_status = execute "git diff #{remote}/#{branch} #{FalkorLib::Git.branch?( git_root_dir )}:#{dir}"
402
- end
403
- end
404
- exit_status
412
+ ## Check if the subtrees have been initialized.
413
+ ## Actually based on a naive check of sub-directory existence
414
+ def subtree_init?(path = Dir.pwd)
415
+ res = true
416
+ FalkorLib.config.git[:subtrees].keys.each do |dir|
417
+ res &&= File.directory?(File.join(path, dir))
418
+ end
419
+ res
420
+ end # subtree_init?
421
+
422
+
423
+ ## Show difference between local subtree(s) and their remotes"
424
+ def subtree_diff(path = Dir.pwd)
425
+ raise ArgumentError, "Git 'subtree' command is not available" unless FalkorLib::Git.command? "subtree"
426
+ if FalkorLib.config.git[:subtrees].empty?
427
+ FalkorLib::Git.config_warn(:subtrees)
428
+ return 1
429
+ end
430
+ exit_status = 0
431
+ git_root_dir = rootdir(path)
432
+ Dir.chdir(git_root_dir) do
433
+ FalkorLib.config.git[:subtrees].each do |dir, conf|
434
+ next if conf[:url].nil?
435
+ #url = conf[:url]
436
+ remote = dir.gsub(/\//, '-')
437
+ branch = (conf[:branch].nil?) ? 'master' : conf[:branch]
438
+ remotes = FalkorLib::Git.remotes
439
+ raise IOError, "The git remote '#{remote}' is not configured" unless remotes.include?( remote )
440
+ raise IOError, "The git subtree directory '#{dir}' does not exists" unless File.directory?( File.join(git_root_dir, dir) )
441
+ info "Git diff on subtree '#{dir}' with remote '#{remote}/#{branch}'"
442
+ exit_status = execute "git diff #{remote}/#{branch} #{FalkorLib::Git.branch?( git_root_dir )}:#{dir}"
405
443
  end
444
+ end
445
+ exit_status
446
+ end
406
447
 
407
- # Pull the latest changes, assuming the git repository is not dirty
408
- def subtree_up(path = Dir.pwd)
409
- error "Unable to pull subtree(s): Dirty Git repository" if FalkorLib::Git.dirty?( path )
410
- exit_status = 0
411
- git_root_dir = rootdir(path)
412
- Dir.chdir(git_root_dir) do
413
- FalkorLib.config.git[:subtrees].each do |dir,conf|
414
- next if conf[:url].nil?
415
- url = conf[:url]
416
- remote = dir.gsub(/\//, '-')
417
- branch = conf[:branch].nil? ? 'master' : conf[:branch]
418
- remotes = FalkorLib::Git.remotes
419
- info "Pulling changes into subtree '#{dir}' using remote '#{remote}/#{branch}'"
420
- raise IOError, "The git remote '#{remote}' is not configured" unless remotes.include?( remote )
421
- info "\t\\__ fetching remote '#{remotes.join(',')}'"
422
- FalkorLib::Git.fetch( git_root_dir )
423
- raise IOError, "The git subtree directory '#{dir}' does not exists" unless File.directory? ( File.join(git_root_dir, dir) )
424
- info "\t\\__ pulling changes"
425
- exit_status = execute "git subtree pull --prefix #{dir} --squash #{remote} #{branch}"
426
- #exit_status = puts "git subtree pull --prefix #{dir} --squash #{remote} #{branch}"
427
- end
428
- end
429
- exit_status
430
- end
431
- alias :subtree_pull :subtree_up
432
-
433
- # Raise a warning message if subtree/submodule section is not present
434
- def config_warn(type = :subtrees)
435
- warn "You shall setup 'FalkorLib.config.git[#{type.to_sym}]' to configure #{type} as follows:"
436
- warn " FalkorLib.config.git do |c|"
437
- warn " c[#{type.to_sym}] = {"
438
- warn " '<subdir>' => {"
439
- warn " :url => '<giturl>',"
440
- warn " :branch => 'develop' # if different from master"
441
- warn " },"
442
- warn " }"
443
- warn " end"
444
- if type == :submodules
445
- warn "This will configure the Git submodule into FalkorLib.config.git.submodulesdir i.e. '#{ FalkorLib.config.git.submodulesdir}'"
446
- end
448
+ # Pull the latest changes, assuming the git repository is not dirty
449
+ def subtree_up(path = Dir.pwd)
450
+ error "Unable to pull subtree(s): Dirty Git repository" if FalkorLib::Git.dirty?( path )
451
+ exit_status = 0
452
+ git_root_dir = rootdir(path)
453
+ Dir.chdir(git_root_dir) do
454
+ FalkorLib.config.git[:subtrees].each do |dir, conf|
455
+ next if conf[:url].nil?
456
+ #url = conf[:url]
457
+ remote = dir.gsub(/\//, '-')
458
+ branch = (conf[:branch].nil?) ? 'master' : conf[:branch]
459
+ remotes = FalkorLib::Git.remotes
460
+ info "Pulling changes into subtree '#{dir}' using remote '#{remote}/#{branch}'"
461
+ raise IOError, "The git remote '#{remote}' is not configured" unless remotes.include?( remote )
462
+ info "\t\\__ fetching remote '#{remotes.join(',')}'"
463
+ FalkorLib::Git.fetch( git_root_dir )
464
+ raise IOError, "The git subtree directory '#{dir}' does not exists" unless File.directory?( File.join(git_root_dir, dir) )
465
+ info "\t\\__ pulling changes"
466
+ exit_status = execute "git subtree pull --prefix #{dir} --squash #{remote} #{branch}"
467
+ #exit_status = puts "git subtree pull --prefix #{dir} --squash #{remote} #{branch}"
447
468
  end
469
+ end
470
+ exit_status
471
+ end
472
+ alias_method :subtree_pull, :subtree_up
473
+
474
+ # Raise a warning message if subtree/submodule section is not present
475
+ def config_warn(type = :subtrees)
476
+ warn "You shall setup 'Falkorlib.config.git[#{type.to_sym}]' to configure #{type} as follows:"
477
+ warn " FalkorLib.config.git do |c|"
478
+ warn " c[#{type.to_sym}] = {"
479
+ warn " '<subdir>' => {"
480
+ warn " :url => '<giturl>',"
481
+ warn " :branch => 'develop' # if different from master"
482
+ warn " },"
483
+ warn " }"
484
+ warn " end"
485
+ if type == :submodules
486
+ warn "This will configure the Git submodule into FalkorLib.config.git.submodulesdir"
487
+ warn "i.e. '#{FalkorLib.config.git[:submodulesdir]}'" if FalkorLib.config.git[:submodulesdir]
488
+ end
489
+ end
490
+
491
+
492
+
448
493
 
449
-
450
-
451
494
 
452
495
 
496
+ end # module FalkorLib::Git
453
497
 
454
- end # module FalkorLib::Git
455
498
  end # module FalkorLib