falkorlib 0.3.14 → 0.4.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.
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Mar 2014-08-26 11:57 svarrette>
3
+ # Time-stamp: <Jeu 2015-01-22 22:51 svarrette>
4
4
  ################################################################################
5
5
  # Management of Git Flow operations
6
6
 
@@ -39,9 +39,35 @@ module FalkorLib
39
39
 
40
40
  module_function
41
41
 
42
+ ## OLD version
43
+ ## Check if git-flow is initialized
44
+ # def init?(path = Dir.pwd)
45
+ # res = FalkorLib::Git.init?(path)
46
+ # Dir.chdir(path) do
47
+ # gf_check = `git config --get-regexp 'gitflow*'`
48
+ # res &= ! gf_check.empty?
49
+ # end
50
+ # res
51
+ # end # init?(path = Dir.pwd)
52
+
53
+ ###### init? ######
54
+ # Check if gitflow has been initialized
55
+ ##
56
+ def init?(dir = Dir.pwd)
57
+ res = FalkorLib::Git.init?(dir)
58
+ if res
59
+ res &= !FalkorLib::Git.config('gitflow*', dir).empty?
60
+ end
61
+ res
62
+ end # init?
63
+
42
64
  ## Initialize a git-flow repository
43
- def init(path = Dir.pwd)
44
- exit_status = FalkorLib::Git.init(path)
65
+ # Supported options:
66
+ # :interactive [boolean] confirm Gitflow branch names
67
+ # :master [string] Branch name for production releases
68
+ # :develop [string] Branch name for development commits
69
+ def init(path = Dir.pwd, options = {})
70
+ exit_status = FalkorLib::Git.init(path, options)
45
71
  error "you shall install git-flow: see https://github.com/nvie/gitflow/wiki/Installation" unless command?('git-flow')
46
72
  remotes = FalkorLib::Git.remotes(path)
47
73
  git_root_dir = FalkorLib::Git.rootdir( path )
@@ -50,48 +76,62 @@ module FalkorLib
50
76
  warn "Not yet any commit detected in this repository."
51
77
  readme = 'README.md'
52
78
  unless File.exists?( readme )
53
- answer = ask(cyan("=> initialize a commit with a #{readme} file (Y|n)?"), 'Yes')
79
+ answer = ask(cyan("=> initialize a commit with an [empty] #{readme} file (Y|n)?"), 'Yes')
54
80
  exit 0 if answer =~ /n.*/i
55
81
  FileUtils.touch(readme)
56
- end
82
+ end
57
83
  FalkorLib::Git.add(readme, "Initiate the repository with a '#{readme}' file")
58
84
  end
59
85
  branches = FalkorLib::Git.list_branch(path)
86
+ gitflow_branches = FalkorLib.config.gitflow[:branches].clone
87
+ # correct eventually the considered branch from the options
88
+ gitflow_branches.each do |t,b|
89
+ gitflow_branches[t] = options[t.to_sym] if options[t.to_sym]
90
+ confs = FalkorLib::Git.config('gitflow*', path, :hash => true)
91
+ unless confs.empty?
92
+ gitflow_branches[t] = confs["gitflow.branch.#{t}"]
93
+ end
94
+ end
95
+ if options[:interactive]
96
+ gitflow_branches[:master] = ask("=> branch name for production releases", gitflow_branches[:master])
97
+ gitflow_branches[:develop] = ask("=> branch name for development commits", gitflow_branches[:develop])
98
+ end
99
+ ap gitflow_branches if options[:debug]
60
100
  if remotes.include?( 'origin' )
61
101
  info "=> configure remote (tracked) branches"
62
102
  exit_status = FalkorLib::Git.fetch(path)
63
- FalkorLib.config.gitflow[:branches].each do |type,branch|
103
+ gitflow_branches.each do |type,branch|
64
104
  if branches.include? "remotes/origin/#{branch}"
65
105
  exit_status = FalkorLib::Git.grab(branch, path)
66
106
  else
67
107
  unless branches.include? branch
68
- info "Creating the branch '#{branch}'"
108
+ info "=> creating the branch '#{branch}'"
69
109
  FalkorLib::Git.create_branch( branch, path )
70
110
  end
71
111
  exit_status = FalkorLib::Git.publish(branch, path )
72
112
  end
73
113
  end
74
114
  else
75
- FalkorLib.config.gitflow[:branches].each do |type, branch|
115
+ gitflow_branches.each do |type, branch|
76
116
  unless branches.include? branch
77
- info "creating the branch '#{branch}'"
117
+ info " => creating the branch '#{branch}'"
78
118
  exit_status = FalkorLib::Git.create_branch( branch, path )
79
119
  end
80
120
  end
81
121
  end
82
- info "Initialize git flow configs"
83
- FalkorLib.config.gitflow[:branches].each do |t,branch|
122
+ #info "initialize git flow configs"
123
+ gitflow_branches.each do |t,branch|
84
124
  exit_status = execute "git config gitflow.branch.#{t} #{branch}"
85
125
  end
86
126
  FalkorLib.config.gitflow[:prefix].each do |t,prefix|
87
127
  exit_status = execute "git config gitflow.prefix.#{t} #{prefix}"
88
128
  end
89
- devel_branch = FalkorLib.config.gitflow[:branches][:develop]
90
- info "Checkout to the main development branch '#{devel_branch}'"
129
+ devel_branch = gitflow_branches[:develop]
130
+ #info "checkout to the main development branch '#{devel_branch}'"
91
131
  exit_status = run %{
92
132
  git checkout #{devel_branch}
93
133
  }
94
- if branches.include?('master') && ! FalkorLib.config.gitflow[:branches].values.include?( 'master' )
134
+ if branches.include?('master') && ! gitflow_branches.values.include?( 'master' )
95
135
  warn "Your git-flow confuguration does not hold the 'master' branch any more"
96
136
  warn "You probably want to get rid of it asap by running 'git branch -d master'"
97
137
  end
@@ -106,17 +146,6 @@ module FalkorLib
106
146
  exit_status
107
147
  end
108
148
 
109
- ## Check if git-flow is initialized
110
- def init?(path = Dir.pwd)
111
- res = FalkorLib::Git.init?(path)
112
- Dir.chdir(path) do
113
- gf_check = `git config --get-regexp 'gitflow*'`
114
- res &= ! gf_check.empty?
115
- end
116
- res
117
- end # init?(path = Dir.pwd)
118
-
119
-
120
149
  ## generic function to run any of the gitflow commands
121
150
  def command(name, type = 'feature', action = 'start', path = Dir.pwd, optional_args = '')
122
151
  error "Invalid git-flow type '#{type}'" unless ['feature', 'release', 'hotfix', 'support'].include?(type)
@@ -142,6 +171,16 @@ module FalkorLib
142
171
  command(name, type, 'finish', path, optional_args)
143
172
  end
144
173
 
174
+ ###
175
+ # Return the Gitflow branch
176
+ # :master: Master Branch name for production releases
177
+ # :develop:
178
+ ##
179
+ def branches(type = :master, dir = Dir.pwd, options = {})
180
+ FalkorLib::Git.config("gitflow.branch.#{type}", dir)
181
+ #confs[type.to_sym]
182
+ end # master_branch
183
+
145
184
 
146
185
  end # module FalkorLib::GitFlow
147
186
 
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Lun 2014-08-25 21:04 svarrette>
3
+ # Time-stamp: <Jeu 2015-01-15 17:26 svarrette>
4
4
  ################################################################################
5
5
  # Place the component you wish to see loaded
6
6
 
@@ -9,4 +9,4 @@ require "falkorlib/common"
9
9
  require "falkorlib/git"
10
10
  require "falkorlib/versioning"
11
11
  require "falkorlib/puppet"
12
-
12
+ require "falkorlib/cli"
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Lun 2014-08-25 21:35 svarrette>
3
+ # Time-stamp: <Lun 2015-01-19 17:57 svarrette>
4
4
  ################################################################################
5
5
  # Management of [Puppet](http://puppetlabs.com/) operations
6
6
 
@@ -12,6 +12,4 @@ end # module FalkorLib
12
12
 
13
13
  require "falkorlib/puppet/base"
14
14
  require "falkorlib/puppet/modules"
15
-
16
-
17
15
 
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Lun 2014-08-25 21:34 svarrette>
3
+ # Time-stamp: <Lun 2015-01-19 17:56 svarrette>
4
4
  ################################################################################
5
5
  # Interface for the main Puppet operations
6
6
  #
@@ -17,9 +17,9 @@ module FalkorLib #:nodoc:
17
17
  # Puppet defaults for FalkorLib
18
18
  DEFAULTS = {
19
19
  :modulesdir => File.join(Dir.pwd, 'modules')
20
- }
21
- end
22
- end
20
+ }
21
+ end
22
+ end
23
23
 
24
24
  module Puppet #:nodoc
25
25
 
@@ -27,4 +27,4 @@ module FalkorLib #:nodoc:
27
27
 
28
28
 
29
29
 
30
- end
30
+ end
@@ -1,6 +1,6 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
- # Time-stamp: <Lun 2014-09-08 16:41 svarrette>
3
+ # Time-stamp: <Lun 2015-01-12 22:09 svarrette>
4
4
  ################################################################################
5
5
  # Interface for the main Puppet Module operations
6
6
  #
@@ -88,7 +88,7 @@ module FalkorLib #:nodoc:
88
88
  ##
89
89
  def init(rootdir = Dir.pwd, name = '', options = {})
90
90
  config = {}
91
- login = `whoami`.chomp
91
+ #login = `whoami`.chomp
92
92
  config[:name] = name unless name.empty?
93
93
  moduledir = name.empty? ? rootdir : File.join(rootdir, name)
94
94
  FalkorLib::Config::Puppet::Modules::DEFAULTS[:metadata].each do |k,v|
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  ################################################################################
3
3
  # gem.rake - Special tasks for the management of Gem operations
4
- # Time-stamp: <Dim 2014-08-31 22:59 svarrette>
4
+ # Time-stamp: <Lun 2015-01-12 21:14 svarrette>
5
5
  #
6
6
  # Copyright (c) 2014 Sebastien Varrette <Sebastien.Varrette@uni.lu>
7
7
  # http://varrette.gforge.uni.lu
@@ -54,13 +54,8 @@ namespace :gem do
54
54
  - Description: #{spec.description}
55
55
  eos
56
56
  end
57
-
58
-
59
-
60
57
  end # task info
61
58
 
62
-
63
-
64
59
  end # namespace gem
65
60
 
66
61
  # Until [Issue#13](https://github.com/postmodern/rubygems-tasks/issues/13) it solved,
@@ -72,7 +67,9 @@ Gem::Tasks::Sign::PGP.new
72
67
 
73
68
  # Enhance the build to sign the built gem
74
69
  Rake::Task['build'].enhance do
70
+ unless ENV['GIT_AUTHOR_NAME'].nil?
75
71
  Rake::Task["sign"].invoke if File.directory?(File.join(ENV['HOME'], '.gnupg') )
72
+ end
76
73
  end
77
74
 
78
75
  [ 'major', 'minor', 'patch' ].each do |level|
@@ -33,7 +33,9 @@ begin
33
33
  #t.pattern = "spec/**/common_*.rb"
34
34
  #t.pattern = "spec/**/versioning_*spec.rb"
35
35
  #t.pattern = "spec/**/puppet*spec.rb"
36
-
36
+ #t.pattern = "spec/**/bootstrap*spec.rb"
37
+ #t.pattern = "spec/**/gitf*spec.rb"
38
+
37
39
  # Whether or not to fail Rake when an error occurs (typically when
38
40
  # examples fail).
39
41
  t.fail_on_error = true
@@ -19,7 +19,7 @@ module FalkorLib #:nodoc:
19
19
  # MAJOR: Defines the major version
20
20
  # MINOR: Defines the minor version
21
21
  # PATCH: Defines the patch version
22
- MAJOR, MINOR, PATCH = 0, 3, 14
22
+ MAJOR, MINOR, PATCH = 0, 4, 0
23
23
 
24
24
  module_function
25
25
 
@@ -72,3 +72,4 @@ module FalkorLib #:nodoc:
72
72
  VERSION = Version.to_s
73
73
  end
74
74
 
75
+
@@ -0,0 +1,118 @@
1
+ #!/usr/bin/ruby
2
+ #########################################
3
+ # bootstrap_spec.rb
4
+ # @author Sebastien Varrette <Sebastien.Varrette@uni.lu>
5
+ # Time-stamp: <Jeu 2015-01-22 10:47 svarrette>
6
+ #
7
+ # @description Check the Bootstrapping operations
8
+ #
9
+ # Copyright (c) 2013 Sebastien Varrette <Sebastien.Varrette@uni.lu>
10
+ # . http://varrette.gforge.uni.lu
11
+ ##############################################################################
12
+
13
+ require 'spec_helper'
14
+ require 'tmpdir'
15
+ require 'FileUtils'
16
+
17
+ describe FalkorLib::Bootstrap do
18
+
19
+ include FalkorLib::Common
20
+
21
+ dirs = {
22
+ :without_git => Dir.mktmpdir,
23
+ :with_git => Dir.mktmpdir
24
+ }
25
+
26
+ before :all do
27
+ $stdout.sync = true
28
+ end
29
+
30
+ after :all do
31
+ dirs.each do |t,d|
32
+ FileUtils.remove_entry_secure d
33
+ end
34
+ end
35
+
36
+ [ :without_git, :with_git ].each do |ctx|
37
+ dir = dirs[ctx]
38
+ #############################################################
39
+ context "Test bootstrapping operations within (#{ctx}) temporary directory #{dir} " do
40
+
41
+ if ctx == :with_git
42
+ it "initialize Git in the temporary directory #{dir}" do
43
+ c = FalkorLib::Git.init(dir)
44
+ c.should == 0
45
+ t = FalkorLib::Git.init?(dir)
46
+ t.should be_true
47
+ end
48
+ end
49
+
50
+ ######### Trash creation #########
51
+ it "#trash" do
52
+ c = FalkorLib::Bootstrap.trash(dir)
53
+ t = File.exists?( File.join(dir, FalkorLib.config[:templates][:trashdir], '.gitignore'))
54
+ t.should be_true
55
+ c.should == 0
56
+ end
57
+
58
+ it "#trash - repeat on an existing trash dir" do
59
+ c = FalkorLib::Bootstrap.trash(dir)
60
+ c.should == 1
61
+ end
62
+
63
+ it "#trash - change target trash dir" do
64
+ newtrashname = 'tmp/mytrash'
65
+ c = FalkorLib::Bootstrap.trash(dir,newtrashname)
66
+ t = File.exists?( File.join(dir, newtrashname, '.gitignore'))
67
+ t.should be_true
68
+ c.should == 0
69
+ end
70
+
71
+ ######### RVM #########
72
+ it "#rvm" do
73
+ gemset = 'mygemset'
74
+ STDIN.should_receive(:gets).and_return('1')
75
+ STDIN.should_receive(:gets).and_return(gemset)
76
+ c = FalkorLib::Bootstrap.rvm(dir)
77
+ c.should == 0
78
+ content = {}
79
+ [:versionfile, :gemsetfile].each do |type|
80
+ f = File.join(dir, FalkorLib.config[:rvm][type.to_sym])
81
+ t = File.exists?(f)
82
+ t.should be_true
83
+ content[type.to_sym] = `cat #{f}`.chomp
84
+ end
85
+ content[:versionfile].should == FalkorLib.config[:rvm][:rubies][0]
86
+ content[:gemsetfile].should == gemset
87
+ end
88
+
89
+ it "#rvm -- repeat" do
90
+ c = FalkorLib::Bootstrap.rvm(dir)
91
+ c.should == 1
92
+ end
93
+
94
+ it "#rvm -- change targets" do
95
+ opts = {
96
+ :ruby => '1.2.3',
97
+ :versionfile => '.myversion',
98
+ :gemset => 'newgemset',
99
+ :gemsetfile => '.mygemset'
100
+ }
101
+ c = FalkorLib::Bootstrap.rvm(dir, opts)
102
+ c.should == 0
103
+ content = {}
104
+ [:versionfile, :gemsetfile].each do |type|
105
+ f = File.join(dir, opts[type.to_sym])
106
+ t = File.exists?(f)
107
+ t.should be_true
108
+ content[type.to_sym] = `cat #{f}`.chomp
109
+ end
110
+ content[:versionfile].should == opts[:ruby]
111
+ content[:gemsetfile].should == opts[:gemset]
112
+ end
113
+
114
+ end # context
115
+
116
+ end # each
117
+
118
+ end
@@ -2,7 +2,7 @@
2
2
  #########################################
3
3
  # git_spec.rb
4
4
  # @author Sebastien Varrette <Sebastien.Varrette@uni.lu>
5
- # Time-stamp: <Sam 2014-08-23 15:26 svarrette>
5
+ # Time-stamp: <Jeu 2015-01-22 15:38 svarrette>
6
6
  #
7
7
  # @description Check the Git operations
8
8
  #
@@ -39,15 +39,15 @@ describe FalkorLib::Git do
39
39
 
40
40
  it "#init - initialize a git repository" do
41
41
  c = FalkorLib::Git.init(dir)
42
- c.should == 0
42
+ c.should == 0
43
43
  t = FalkorLib::Git.init?(dir)
44
44
  t.should be_true
45
45
  end
46
46
 
47
- it "#remotes? -- should be false" do
48
- t = FalkorLib::Git.remotes?(dir)
49
- t.should be_false
50
- end
47
+ it "#remotes? -- should be false" do
48
+ t = FalkorLib::Git.remotes?(dir)
49
+ t.should be_false
50
+ end
51
51
 
52
52
  it "#rootdir #gitdir - checks git dir and working tree" do
53
53
  subdir = File.join(dir, 'some_dir')
@@ -60,37 +60,37 @@ describe FalkorLib::Git do
60
60
  end
61
61
  end
62
62
 
63
- it "#has_commits? - not yet any commits" do
64
- b = FalkorLib::Git.has_commits?( dir )
65
- b.should be_false
66
- end
63
+ it "#has_commits? - not yet any commits" do
64
+ b = FalkorLib::Git.has_commits?( dir )
65
+ b.should be_false
66
+ end
67
67
 
68
68
  it "#branch? - check non-existing branch" do
69
69
  br = FalkorLib::Git.branch?( dir )
70
70
  br.should be_nil
71
71
  end
72
72
 
73
- it "#list_files -- should not list any files" do
74
- l = FalkorLib::Git.list_files( dir )
75
- l.should be_empty
76
- end
73
+ it "#list_files -- should not list any files" do
74
+ l = FalkorLib::Git.list_files( dir )
75
+ l.should be_empty
76
+ end
77
77
 
78
78
  it "#add - makes a first commit" do
79
79
  FileUtils.touch( afile )
80
80
  t = FalkorLib::Git.add(afile)
81
- t.should == 0
81
+ t.should == 0
82
82
  end
83
83
 
84
- it "#list_files -- should list a single files" do
85
- l = FalkorLib::Git.list_files( dir )
86
- l.should include 'a_file'
87
- end
84
+ it "#list_files -- should list a single files" do
85
+ l = FalkorLib::Git.list_files( dir )
86
+ l.should include 'a_file'
87
+ end
88
88
 
89
89
 
90
- it "#has_commits? - no some commits have been done" do
91
- b = FalkorLib::Git.has_commits?( dir )
92
- b.should be_true
93
- end
90
+ it "#has_commits? - no some commits have been done" do
91
+ b = FalkorLib::Git.has_commits?( dir )
92
+ b.should be_true
93
+ end
94
94
 
95
95
 
96
96
  it "#branch? - check existing branch" do
@@ -113,7 +113,7 @@ describe FalkorLib::Git do
113
113
 
114
114
  default_branches.each do |br|
115
115
  it "#delete_branch #list_branch - deletes branch #{br}" do
116
- FalkorLib::Git.delete_branch( br, dir) #, :force => true )
116
+ FalkorLib::Git.delete_branch( br, dir) #, :force => true )
117
117
  l = FalkorLib::Git.list_branch( dir )
118
118
  l.should_not include "#{br}"
119
119
  end
@@ -129,6 +129,50 @@ describe FalkorLib::Git do
129
129
  c.should be_true
130
130
  end
131
131
 
132
+ it "#config -- check existing key" do
133
+ c = FalkorLib::Git.config('user.name', dir)
134
+ c.should_not be_empty
135
+ t = c.is_a? String
136
+ t.should be_true
137
+ end
138
+
139
+ it "#config -- check non-existing key" do
140
+ c = FalkorLib::Git.config('user.nam', dir)
141
+ c.should be_nil
142
+ end
143
+
144
+ it "#config -- check all keys" do
145
+ c = FalkorLib::Git.config('*', dir)
146
+ c.should_not be_empty
147
+ t = c.is_a? Array
148
+ t.should be_true
149
+ end
150
+
151
+ it "#config -- check pattern" do
152
+ c = FalkorLib::Git.config('user*', dir)
153
+ c.should_not be_empty
154
+ t = c.is_a? Array
155
+ t.should be_true
156
+ c.length.should == 2
157
+ end
158
+
159
+ it "#config -- check pattern 2" do
160
+ c = FalkorLib::Git.config(/.*name=/, dir)
161
+ c.should_not be_empty
162
+ t = c.is_a? Array
163
+ t.should be_true
164
+ c.length.should == 1
165
+ end
166
+
167
+ it "#config -- return hash" do
168
+ c = FalkorLib::Git.config('user*', dir, :hash => true)
169
+ c.should_not be_empty
170
+ t = c.is_a? Hash
171
+ t.should be_true
172
+ c.keys.length.should == 2
173
+ end
174
+
175
+
132
176
  # ---------- Submodules ---------------
133
177
  it "#submodules_init" do
134
178
  FalkorLib.config.git do |c|
@@ -153,32 +197,32 @@ describe FalkorLib::Git do
153
197
  b.should == 0
154
198
  end
155
199
 
156
- # ---------- Subtrees ---------------
200
+ # ---------- Subtrees ---------------
157
201
  if FalkorLib::Git.command? 'subtree'
158
- FalkorLib.config.git do |c|
159
- c[:subtrees] = {
160
- 'falkor/lib' => {
161
- :url => 'https://github.com/Falkor/falkorlib.git',
162
- :branch => 'devel'
163
- },
164
- }
165
- end
166
-
167
- it "#subtree_init? -- should check that the subtree(s) have not been initialized" do
168
- b = FalkorLib::Git.subtree_init?( dir )
202
+ FalkorLib.config.git do |c|
203
+ c[:subtrees] = {
204
+ 'falkor/lib' => {
205
+ :url => 'https://github.com/Falkor/falkorlib.git',
206
+ :branch => 'devel'
207
+ },
208
+ }
209
+ end
210
+
211
+ it "#subtree_init? -- should check that the subtree(s) have not been initialized" do
212
+ b = FalkorLib::Git.subtree_init?( dir )
169
213
  b.should be_false
170
- end
214
+ end
171
215
 
172
216
  it "#subtree_init - initialize some Git Subtrees" do
173
-
217
+
174
218
  b = FalkorLib::Git.subtree_init( dir )
175
219
  b.should == 0
176
220
  end
177
221
 
178
- it "#subtree_init? -- should check that the subtree(s) have been initialized" do
179
- b = FalkorLib::Git.subtree_init?( dir )
180
- b.should be_true
181
- end
222
+ it "#subtree_init? -- should check that the subtree(s) have been initialized" do
223
+ b = FalkorLib::Git.subtree_init?( dir )
224
+ b.should be_true
225
+ end
182
226
 
183
227
  it "#subtree_up" do
184
228
  b = FalkorLib::Git.subtree_up( dir )
@@ -197,7 +241,7 @@ describe FalkorLib::Git do
197
241
 
198
242
  # shall be the last check
199
243
  it "#dirty? - check dirty git directory" do
200
- execute "echo 'toto' > #{afile}"
244
+ execute "echo 'toto' > #{afile}"
201
245
  b = FalkorLib::Git.dirty?( dir )
202
246
  b.should be_true
203
247
  end