falkorlib 0.6.19 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.rubocop.yml +88 -0
- data/.travis.yml +56 -4
- data/Gemfile +4 -4
- data/Gemfile.lock +55 -27
- data/Rakefile +12 -8
- data/Vagrantfile +68 -0
- data/completion/_falkor +55 -7
- data/falkorlib.gemspec +14 -12
- data/lib/falkorlib.rb +22 -21
- data/lib/falkorlib/bootstrap.rb +5 -1
- data/lib/falkorlib/bootstrap/base.rb +385 -693
- data/lib/falkorlib/bootstrap/git.rb +137 -0
- data/lib/falkorlib/bootstrap/latex.rb +186 -0
- data/lib/falkorlib/bootstrap/link.rb +108 -96
- data/lib/falkorlib/bootstrap/ruby.rb +102 -0
- data/lib/falkorlib/cli.rb +82 -26
- data/lib/falkorlib/cli/config.rb +8 -8
- data/lib/falkorlib/cli/link.rb +8 -9
- data/lib/falkorlib/cli/new.rb +25 -39
- data/lib/falkorlib/common.rb +425 -425
- data/lib/falkorlib/config.rb +114 -110
- data/lib/falkorlib/error.rb +27 -16
- data/lib/falkorlib/gem_tasks.rb +12 -11
- data/lib/falkorlib/git.rb +3 -4
- data/lib/falkorlib/git/base.rb +439 -396
- data/lib/falkorlib/git/flow.rb +163 -165
- data/lib/falkorlib/git_tasks.rb +31 -31
- data/lib/falkorlib/loader.rb +1 -1
- data/lib/falkorlib/puppet.rb +3 -5
- data/lib/falkorlib/puppet/base.rb +10 -15
- data/lib/falkorlib/puppet/modules.rb +367 -365
- data/lib/falkorlib/puppet_tasks.rb +11 -8
- data/lib/falkorlib/tasks.rb +51 -54
- data/lib/falkorlib/tasks/gem.rake +42 -43
- data/lib/falkorlib/tasks/gem.rb +12 -11
- data/lib/falkorlib/tasks/git.rake +101 -107
- data/lib/falkorlib/tasks/git.rb +31 -31
- data/lib/falkorlib/tasks/gitflow.rake +131 -141
- data/lib/falkorlib/tasks/puppet.rb +11 -8
- data/lib/falkorlib/tasks/puppet_modules.rake +143 -154
- data/lib/falkorlib/tasks/rspec.rake +94 -59
- data/lib/falkorlib/tasks/yard.rake +35 -39
- data/lib/falkorlib/version.rb +55 -55
- data/lib/falkorlib/versioning.rb +169 -167
- data/spec/falkorlib/bootstrap_helpers_spec.rb +106 -56
- data/spec/falkorlib/bootstrap_latex_spec.rb +145 -0
- data/spec/falkorlib/bootstrap_link_spec.rb +137 -0
- data/spec/falkorlib/bootstrap_ruby_spec.rb +118 -0
- data/spec/falkorlib/bootstrap_spec.rb +112 -129
- data/spec/falkorlib/git_spec.rb +94 -22
- data/spec/falkorlib/gitflow_spec.rb +54 -42
- data/spec/falkorlib/puppet_modules_spec.rb +35 -26
- data/spec/falkorlib/versioning_puppet_module_spec.rb +94 -90
- data/spec/falkorlib_spec.rb +5 -0
- data/spec/spec_helper.rb +88 -47
- data/templates/latex/article-ieee/main.tex.erb +509 -0
- data/templates/latex/article/_abstract.tex.erb +19 -0
- data/templates/latex/article/_acronyms.tex.erb +116 -0
- data/templates/latex/article/_conclusion.tex.erb +25 -0
- data/templates/latex/article/_context.tex.erb +17 -0
- data/templates/latex/article/_experiments.tex.erb +27 -0
- data/templates/latex/article/_implem.tex.erb +17 -0
- data/templates/latex/article/_introduction.tex.erb +39 -0
- data/templates/latex/article/_related_works.tex.erb +19 -0
- data/templates/latex/article/biblio.bib.erb +28 -0
- data/templates/latex/article/template.tex.erb +16 -0
- data/templates/latex/ieee/IEEEtran.bst +2409 -0
- data/templates/latex/ieee/IEEEtran.cls +6347 -0
- data/templates/motd/motd.erb +2 -1
- metadata +82 -2
data/lib/falkorlib/config.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
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
|
-
|
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
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
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
|
-
|
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
|
data/lib/falkorlib/error.rb
CHANGED
@@ -1,28 +1,39 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
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
|
-
|
10
|
-
|
9
|
+
# Errors
|
10
|
+
class Error < ::StandardError
|
11
11
|
|
12
|
-
|
13
|
-
attr_accessor :status_code
|
14
|
-
end
|
12
|
+
class << self
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
attr_accessor :status_code
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def status_code
|
19
|
+
self.class.status_code
|
19
20
|
end
|
20
21
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
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
|
data/lib/falkorlib/gem_tasks.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
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
|
-
|
16
|
-
class GemTasks
|
17
|
-
include Rake::DSL if defined? Rake::DSL
|
17
|
+
include Rake::DSL if defined? Rake::DSL
|
18
18
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
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 ;)
|
data/lib/falkorlib/git.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
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
|
14
|
-
require
|
15
|
-
|
13
|
+
require 'falkorlib/git/base'
|
14
|
+
require 'falkorlib/git/flow'
|
data/lib/falkorlib/git/base.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
################################################################################
|
3
|
-
# Time-stamp: <
|
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
|
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
|
-
|
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
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
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
|
-
|
118
|
-
|
119
|
-
g = MiniGit.new
|
120
|
-
g.find_git_dir(path)[1]
|
121
|
-
end
|
34
|
+
# Management of Git operations
|
35
|
+
module Git
|
122
36
|
|
123
|
-
|
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
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
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
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
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
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
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
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
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
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
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
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
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
|
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
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
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
|
-
|
257
|
-
|
258
|
-
|
254
|
+
)
|
255
|
+
end
|
256
|
+
exit_status.to_i
|
257
|
+
end
|
259
258
|
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
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
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
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
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
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
|
-
|
317
|
-
end
|
318
|
-
end
|
319
|
-
exit_status
|
358
|
+
)
|
359
|
+
end
|
320
360
|
end
|
361
|
+
end
|
362
|
+
exit_status
|
363
|
+
end
|
321
364
|
|
322
|
-
|
323
|
-
|
324
|
-
|
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
|
-
|
371
|
+
))
|
372
|
+
end
|
331
373
|
|
332
|
-
|
333
|
-
|
334
|
-
|
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
|
-
|
379
|
+
})
|
380
|
+
end
|
339
381
|
|
340
382
|
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
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
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
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
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
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
|