guitr 0.0.5 → 0.0.6

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.
@@ -26,4 +26,13 @@
26
26
  === 0.0.5 2010-06-24
27
27
 
28
28
  * 1 major enhancements:
29
- * --unpushed operation was enhanced to be informative
29
+ * --unpushed operation was enhanced to be informative
30
+
31
+ === 0.0.6 2010-08-11
32
+
33
+ * 3 major enhancements:
34
+ * --status, --pull and --unpushed operations were made more silent
35
+ * OptionParser was integrated to handle arguments
36
+ * --exec operation to run given command against repository directory was added
37
+
38
+
@@ -18,11 +18,14 @@ Lets ensure that everything is under git control that should be.
18
18
  guitr [options] [path_to_repo if not specified current directory will be used]
19
19
 
20
20
  Options:
21
- --status # default command to invoke, echos result of the 'git status'
22
- --pull # performs 'git pull' against all found repositories
23
- --unpushed # checks whether there are commits need to be pushed
24
- --verbose # echos INFO level logs
25
- --trace # echos DEBUG level logs
21
+ -s --status # default command to invoke, echos result of the 'git status'
22
+ -p --pull # performs 'git pull' against all found repositories
23
+ -u --unpushed # checks whether there are commits need to be pushed
24
+ -e --exec CMD # operation to run given command (CMD) against repository directory was added
25
+ -v --verbose # echos INFO level logs
26
+ -t --trace # echos DEBUG level logs
27
+ -V --version # print guitr version
28
+ -h --help # print this help message
26
29
 
27
30
  == REQUIREMENTS:
28
31
 
data/Rakefile CHANGED
@@ -19,11 +19,14 @@ $hoe = Hoe.spec 'guitr' do
19
19
  guitr [options] [path_to_repo if not specified current directory will be used]
20
20
 
21
21
  Options:
22
- --status # default command to invoke, echos result of the 'git status'
23
- --pull # performs 'git pull' against all found repositories
24
- --unpushed # checks whether there are commits need to be pushed
25
- --verbose # echos INFO level logs
26
- --trace # echos DEBUG level logs
22
+ -s --status # default command to invoke, echos result of the 'git status'
23
+ -p --pull # performs 'git pull' against all found repositories
24
+ -u --unpushed # checks whether there are commits need to be pushed
25
+ -e --exec CMD # operation to run given command (CMD) against repository directory was added
26
+ -v --verbose # echos INFO level logs
27
+ -t --trace # echos DEBUG level logs
28
+ -V --version # print guitr version
29
+ -h --help # print this help message
27
30
 
28
31
  For details go to http://webdizz.name/posts/guitr
29
32
  "
data/bin/guitr CHANGED
@@ -3,15 +3,8 @@
3
3
  require 'rubygems' unless ENV['NO_RUBYGEMS']
4
4
  require 'guitr'
5
5
 
6
- if %w(-v --version).include? ARGV.first
7
- puts "#{File.basename($0)} #{Guitr::VERSION}"
8
- exit(0)
9
- end
10
-
11
- args = ARGV.clone
12
-
13
6
  begin
14
- Guitr::GuitrRunner.new.run args
7
+ Guitr::GuitrRunner.new.run
15
8
  rescue Guitr::SystemExitException => e
16
9
  exit e.exit_code
17
10
  end
@@ -2,7 +2,7 @@ $:.unshift(File.dirname(__FILE__)) unless
2
2
  $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
3
 
4
4
  module Guitr
5
- VERSION = '0.0.5'
5
+ VERSION = '0.0.6'
6
6
  end
7
7
 
8
8
  require 'guitr/guitr'
@@ -11,10 +11,13 @@ module Guitr
11
11
  def run(repo, options = {})
12
12
  @git = Git.open(repo, options)
13
13
  res = @git.lib.status
14
- puts
15
- puts "Status for #{repo}"
16
- puts res = res.gsub('??', ' U')
17
- puts
14
+ if !res.empty?
15
+ puts
16
+ res = "Status for #{repo}\n"+res
17
+ res = res.gsub('??', ' U')
18
+ puts res
19
+ puts
20
+ end
18
21
 
19
22
  res
20
23
  end
@@ -43,7 +46,6 @@ module Guitr
43
46
  puts res
44
47
  puts
45
48
  end
46
- puts "There is no unpushed commits for #{repo}." if res.empty?
47
49
  rescue Git::GitExecuteError => e
48
50
  puts "Unable to check unpushed commits '#{repo}' #{e.message}"
49
51
  end
@@ -61,8 +63,9 @@ module Guitr
61
63
  @git = Git.open(repo, options)
62
64
  begin
63
65
  puts
64
- puts "Going to pull #{repo}"
65
66
  res = @git.lib.pull
67
+ res = "Going to pull #{repo}\n"+res if !res.empty?
68
+ res = '' if res.include?("up-to-date")
66
69
  puts res
67
70
  res
68
71
  rescue Git::GitExecuteError => e
@@ -3,6 +3,8 @@ require 'git'
3
3
  require 'find'
4
4
  require 'logger'
5
5
  require 'guitr/git'
6
+ require 'optparse'
7
+ require 'ostruct'
6
8
 
7
9
  module Guitr
8
10
 
@@ -12,81 +14,139 @@ module Guitr
12
14
 
13
15
  attr_reader :repo_paths, :operation, :log
14
16
 
15
- def initialize
16
- @operational_args = ['--status', '--pull', '--unpushed']
17
- @acceptable_args = [:verbose, :trace] << @operational_args
18
- @acceptable_args = @acceptable_args.flatten
17
+ def initialize
19
18
  @repo_paths = []
20
19
  @git_dir = '.git'
21
- @usage = '$ guitr --status|--pull path_to_git_repo(s) '
22
- @options = {}
23
20
  end
24
21
 
25
- def run(args)
26
- validate args
27
- res = ''
28
- @repo_paths.flatten.uniq.each do |repo|
29
- case @operation.to_sym
30
- when :pull
31
- res = GitPull.new.run(repo, @options)
32
- when :status
33
- res = GitStatus.new.run(repo, @options)
34
- when :unpushed
35
- res = GitUnpushed.new.run(repo, @options)
22
+ def run
23
+ @options = OpenStruct.new
24
+ @options.verbose = false
25
+ @options.trace = false
26
+ @options.operation = :status
27
+ @options.isOperationSet = false;
28
+ @options.log = nil
29
+ @options.command = nil
30
+
31
+ OptionParser.new do |opts|
32
+ opts.banner = "Usage: guitr [options] [repository]"
33
+ opts.separator ""
34
+
35
+ opts.on("-v", "--verbose", "Run verbosely") do |v|
36
+ @options.verbose = v
37
+ end
38
+
39
+ opts.on("-t", "--trace", "Run in trace mode") do |t|
40
+ @options.trace = t
41
+ end
42
+
43
+ # Run pull
44
+ opts.on("-p", "--pull", "Run --pull command to update all repositories") do |s|
45
+ setOperation :pull
46
+ end
47
+
48
+ # Run unpushed
49
+ opts.on("-u", "--unpushed", "Run --unpushed command to check commited but not pushed yet changes in repositories") do |s|
50
+ setOperation :unpushed
51
+ end
52
+
53
+ # Run status command
54
+ opts.on("-s", "--status", "Run --status command") do |s|
55
+ setOperation :status
56
+ end
57
+
58
+ # Run exec command
59
+ opts.on("-e", "--exec COMMAND", "Run COMMAND, for example guitr --exec date will output current date") do |c|
60
+ setOperation :exec
61
+ @options.command = c
36
62
  end
63
+
64
+ # Print an options summary.
65
+ opts.on_tail("-h", "--help", "Show this message") do
66
+ puts opts
67
+ exit
68
+ end
69
+
70
+ # Print the version.
71
+ opts.on_tail("-V", "--version", "Show version") do
72
+ puts Guitr::VERSION
73
+ exit
74
+ end
75
+
76
+ end.parse!
77
+
78
+ @operation = @options.operation
79
+ init_logger
80
+ validate ARGV
81
+ do_run
37
82
  end
38
- res
39
- end
40
-
41
- def validate(args)
42
- init_logger(args)
43
83
 
44
- args.each do |arg|
45
- @operation = arg.gsub('--', '') if @operational_args.include?(arg) && @operation.nil?
46
- end
47
- @operation = :status if @operation.nil?
84
+ private
48
85
 
49
- start_directory = './'
50
- last = args.last
51
- if last.nil? || last.include?('--')
52
- @log.info 'Current directory will be used to start looking for git working copies.' if @log
53
- else
54
- start_directory = args.last
86
+ def do_run
87
+ res = ''
88
+ @repo_paths.flatten.uniq.each do |repo|
89
+ case @operation
90
+ when :pull
91
+ res = GitPull.new.run(repo)
92
+ when :status
93
+ res = GitStatus.new.run(repo)
94
+ when :unpushed
95
+ res = GitUnpushed.new.run(repo)
96
+ when :exec
97
+ current_dir = Dir.pwd
98
+ Dir.chdir repo
99
+ res = system @options.command
100
+ Dir.chdir current_dir
101
+ end
102
+ end
103
+ res
55
104
  end
56
105
 
57
- if !File.exist? start_directory
58
- puts "Directory '#{start_directory}' does not exist."
59
- exit()
106
+ def setOperation operation
107
+ if !@options.isOperationSet
108
+ @options.operation = operation
109
+ @options.isOperationSet = true
110
+ end
60
111
  end
61
112
 
62
- Find.find(start_directory) do |path|
63
- if path.include?(@git_dir) && !path.include?("#{@git_dir}/") && File.exist?(path) && File.directory?(path)
64
- @repo_paths << File.expand_path(path.gsub(@git_dir, ''))
113
+ def validate(args)
114
+ start_directory = './'
115
+ last = @operation==:exec ? args[-2] : args.last
116
+ if last.nil? || last.include?('--')
117
+ @log.info 'Current directory will be used to start looking for git working copies.' if @log
118
+ else
119
+ start_directory = args.last
120
+ end
121
+
122
+ if !File.exist? start_directory
123
+ puts "Directory '#{start_directory}' does not exist."
124
+ exit()
65
125
  end
126
+
127
+ Find.find(start_directory) do |path|
128
+ if path.include?(@git_dir) && !path.include?("#{@git_dir}/") && File.exist?(path) && File.directory?(path)
129
+ @repo_paths << File.expand_path(path.gsub(@git_dir, ''))
130
+ end
131
+ end
132
+
133
+ if @repo_paths.empty?
134
+ puts "There are no repositories within '#{start_directory}' directory."
135
+ exit()
136
+ end
137
+
66
138
  end
67
139
 
68
- if @repo_paths.empty?
69
- puts "There are no repositories within '#{start_directory}' directory."
70
- exit()
140
+ def init_logger
141
+ create_logger(Logger::INFO) if @options.verbose
142
+ create_logger(Logger::DEBUG) if @options.trace
71
143
  end
72
144
 
73
- end
74
-
75
- def init_logger args
76
- args.each do |arg|
77
- arg = arg.gsub('--', '')
78
- create_logger(Logger::INFO) if arg.to_sym == :verbose
79
- create_logger(Logger::DEBUG) if arg.to_sym == :trace
145
+ def create_logger level
146
+ @log = Logger.new STDOUT
147
+ @log.level = level
148
+ @options.log = @log
80
149
  end
150
+
81
151
  end
82
- private :init_logger
83
-
84
- def create_logger level
85
- @log = Logger.new STDOUT
86
- @log.level = level
87
- @options[:log] = @log
88
- end
89
- private :create_logger
90
-
91
152
  end
92
- end
@@ -5,12 +5,22 @@ include Guitr::GuitrGit
5
5
 
6
6
  describe Guitr::GuitrGit do
7
7
 
8
- $RIGHT_REPO = File.expand_path(File.dirname(__FILE__)+'/../')
8
+ $RIGHT_REPO = File.expand_path(File.dirname(__FILE__)+'/../tmp')
9
+
10
+ before(:all) do
11
+ FileUtils.rm_rf $RIGHT_REPO
12
+ Dir.mkdir $RIGHT_REPO
13
+ Git::init($RIGHT_REPO)
14
+ end
15
+
16
+ after(:all) do
17
+ FileUtils.rm_rf $RIGHT_REPO
18
+ end
9
19
 
10
20
  describe GitStatus do
11
21
 
12
22
  before do
13
- @test_file_name = 'some_file'
23
+ @test_file_name = $RIGHT_REPO+'/some_file'
14
24
  @action = GitStatus.new
15
25
  end
16
26
 
@@ -23,7 +33,7 @@ describe Guitr::GuitrGit do
23
33
  begin
24
34
  file = open(@test_file_name, "w")
25
35
  res = @action.run $RIGHT_REPO, {}
26
- res.should include @test_file_name
36
+ res.should include File.basename @test_file_name
27
37
  ensure
28
38
  clean_test_file(file)
29
39
  end
@@ -40,11 +50,10 @@ describe Guitr::GuitrGit do
40
50
  end
41
51
  end
42
52
 
43
- def clean_test_file file
44
- file.close
45
- File.delete @test_file_name
53
+ it 'should silent for empty status' do
54
+ res = @action.run $RIGHT_REPO, {}
55
+ res.should be_empty
46
56
  end
47
- private :clean_test_file
48
57
 
49
58
  end
50
59
 
@@ -52,7 +61,7 @@ describe Guitr::GuitrGit do
52
61
 
53
62
  before do
54
63
  @action = GitUnpushed.new
55
- @test_file_name = 'some_file_2'
64
+ @test_file_name = $RIGHT_REPO+'/some_file_2'
56
65
  end
57
66
 
58
67
  it "should have a git instance if repo path is correct" do
@@ -63,11 +72,18 @@ describe Guitr::GuitrGit do
63
72
  it "should display unpushed items" do
64
73
  module Git
65
74
  class Lib
66
- def unpushed branch, remote_branch
67
- 'insertions'
75
+ def branch_current
76
+ 'master'
77
+ end
78
+ def remotes
79
+ 'master'
80
+ end
81
+ def unpushed current_branch, remote_branch
82
+ 'insertions some additional statistics'
68
83
  end
69
84
  end
70
85
  end
86
+
71
87
  res = @action.run $RIGHT_REPO, {}
72
88
  res.should include('insertions')
73
89
  end
@@ -91,7 +107,7 @@ describe Guitr::GuitrGit do
91
107
 
92
108
  before do
93
109
  @action = GitPull.new
94
- @test_file_name = 'some_file_2'
110
+ @test_file_name = $RIGHT_REPO+'/some_file_2'
95
111
  end
96
112
 
97
113
  it "should have a git instance if repo path is correct" do
@@ -99,11 +115,30 @@ describe Guitr::GuitrGit do
99
115
  @action.git.should_not be_nil
100
116
  end
101
117
 
102
- it "should display unpushed items or display nothing" do
118
+ it "should display pulling result" do
119
+ module Git
120
+ class Lib
121
+ def pull
122
+ 'Updating'
123
+ end
124
+ end
125
+ end
103
126
  res = @action.run $RIGHT_REPO, {}
104
127
  res.should include('Updating')
105
128
  end
106
129
 
130
+ it "should be silent if code base is up-to-date" do
131
+ module Git
132
+ class Lib
133
+ def pull
134
+ 'up-to-date'
135
+ end
136
+ end
137
+ end
138
+ res = @action.run $RIGHT_REPO, {}
139
+ res.should be_empty
140
+ end
141
+
107
142
  it "should report an error without interruption if error was occured on pull action" do
108
143
  lambda{
109
144
  module Git
@@ -119,15 +154,11 @@ describe Guitr::GuitrGit do
119
154
 
120
155
  end
121
156
 
157
+ def clean_test_file file
158
+ file.close
159
+ File.delete @test_file_name
160
+ end
161
+ private :clean_test_file
162
+
122
163
  end
123
164
 
124
- module Git
125
-
126
- class Lib
127
-
128
- def pull
129
- 'Updating'
130
- end
131
-
132
- end
133
- end
@@ -1,5 +1,6 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
  require 'logger'
3
+ require 'optparse'
3
4
 
4
5
  describe Guitr::GuitrRunner do
5
6
 
@@ -7,72 +8,83 @@ describe Guitr::GuitrRunner do
7
8
  $RIGHT_REPO_PATH = File.expand_path(File.dirname(__FILE__)+'/../')
8
9
 
9
10
  before(:each) do
11
+ ARGV.clear
10
12
  @guitr_runner = Guitr::GuitrRunner.new
11
13
  end
12
14
 
13
15
  it "should continue if no args were specified" do
14
- args = [];
15
- @guitr_runner.validate args
16
+ @guitr_runner.run
16
17
  @guitr_runner.operation.should eql(:status)
17
18
  end
18
19
 
19
20
  it "should use current directory if no path specified" do
20
- args = [];
21
- @guitr_runner.validate args
21
+ @guitr_runner.run
22
22
  @guitr_runner.repo_paths.size.should eql(1)
23
23
  end
24
24
 
25
25
  it "should fail if specified directory does not exist" do
26
- args = ['some_path'];
27
- lambda { @guitr_runner.validate(args)}.should raise_exception SystemExit
26
+ ARGV << 'some_path'
27
+ lambda { @guitr_runner.run}.should raise_exception SystemExit
28
28
  end
29
29
 
30
30
  it "should use specified directory if exist" do
31
- args = [$RIGHT_REPO_PATH];
32
- lambda { @guitr_runner.validate(args)}.should_not raise_exception SystemExit
31
+ ARGV << $RIGHT_REPO_PATH
32
+ lambda { @guitr_runner.run}.should_not raise_exception SystemExit
33
33
  end
34
34
 
35
35
  it "should fail if there is are no repositories within specified directory" do
36
- args = [$CURRENT_DIR_PATH];
37
- lambda { @guitr_runner.validate(args)}.should raise_exception SystemExit
36
+ ARGV << $CURRENT_DIR_PATH
37
+ lambda { @guitr_runner.run}.should raise_exception SystemExit
38
38
  end
39
39
 
40
40
  it "should operate verbosely if --verbose was specified" do
41
- args = ['--verbose', $RIGHT_REPO_PATH]
42
- @guitr_runner.validate args
41
+ ARGV << '--verbose'
42
+ ARGV << $RIGHT_REPO_PATH
43
+ @guitr_runner.run
43
44
  @guitr_runner.log.should_not be_nil
44
45
  end
45
46
 
46
47
  it "should use INFO logger if --verbose was specified" do
47
- args = ['--verbose', $RIGHT_REPO_PATH]
48
- @guitr_runner.validate args
48
+ ARGV << '--verbose'
49
+ ARGV << $RIGHT_REPO_PATH
50
+ @guitr_runner.run
49
51
  @guitr_runner.log.level.should eql(Logger::INFO)
50
52
  end
51
53
 
52
54
  it "should operate in debug mode if --trace was specified" do
53
- args = ['--trace', $RIGHT_REPO_PATH]
54
- @guitr_runner.validate args
55
+ ARGV << '--trace'
56
+ ARGV << $RIGHT_REPO_PATH
57
+ @guitr_runner.run
55
58
  @guitr_runner.log.level.should eql(Logger::DEBUG)
56
59
  end
57
60
 
58
61
  it "should use first operation argument to operate with" do
59
- args = ['--trace', '--status', '--pull', $RIGHT_REPO_PATH]
60
- @guitr_runner.validate args
61
- @guitr_runner.operation.should eql(:status.to_s)
62
+ ARGV << '--trace'
63
+ ARGV << '--status'
64
+ ARGV << '--pull'
65
+ ARGV << $RIGHT_REPO_PATH
66
+ @guitr_runner.run
67
+ @guitr_runner.operation.should eql(:status)
62
68
  end
63
69
 
64
70
  it "should have unpushed operation" do
65
- args = ['--unpushed'];
66
- @guitr_runner.validate args
67
- @guitr_runner.operation.should eql(:unpushed.to_s)
71
+ ARGV << '--unpushed'
72
+ @guitr_runner.run
73
+ @guitr_runner.operation.should eql(:unpushed)
68
74
  end
69
75
 
70
- it "should have empty or some satistic of unpushed changes" do
71
- args = ['--unpushed', $RIGHT_REPO_PATH];
72
- res = @guitr_runner.run args
73
- res.should be_empty if res.empty?
74
- res.should include('insertions') if !res.empty?
75
- res.should_not include('nothing to do')
76
+ it 'should run specified command' do
77
+ ARGV << '--exec'
78
+ ARGV << 'date'
79
+ @guitr_runner.run
80
+ @guitr_runner.operation.should eql(:exec)
76
81
  end
77
82
 
83
+ it 'should fail to run specified command' do
84
+ lambda {
85
+ ARGV << '--exec'
86
+ @guitr_runner.run
87
+ }.should raise_exception OptionParser::ParseError
88
+ end
89
+
78
90
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: guitr
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - webdizz
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-24 00:00:00 +03:00
18
+ date: 2010-08-11 00:00:00 +03:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -42,12 +42,12 @@ dependencies:
42
42
  requirements:
43
43
  - - ">="
44
44
  - !ruby/object:Gem::Version
45
- hash: 23
45
+ hash: 21
46
46
  segments:
47
47
  - 2
48
48
  - 6
49
- - 0
50
- version: 2.6.0
49
+ - 1
50
+ version: 2.6.1
51
51
  type: :runtime
52
52
  version_requirements: *id002
53
53
  - !ruby/object:Gem::Dependency
@@ -74,12 +74,12 @@ dependencies:
74
74
  requirements:
75
75
  - - ">="
76
76
  - !ruby/object:Gem::Version
77
- hash: 23
77
+ hash: 21
78
78
  segments:
79
79
  - 2
80
80
  - 6
81
- - 0
82
- version: 2.6.0
81
+ - 1
82
+ version: 2.6.1
83
83
  type: :development
84
84
  version_requirements: *id004
85
85
  description: |-
@@ -117,7 +117,7 @@ has_rdoc: true
117
117
  homepage: http://webdizz.name/posts/guitr
118
118
  licenses: []
119
119
 
120
- post_install_message: "\n Usage: \n guitr [options] [path_to_repo if not specified current directory will be used]\n \n Options:\n --status # default command to invoke, echos result of the 'git status'\n --pull # performs 'git pull' against all found repositories\n --unpushed # checks whether there are commits need to be pushed\n --verbose # echos INFO level logs\n --trace # echos DEBUG level logs\n \n For details go to http://webdizz.name/posts/guitr\n "
120
+ post_install_message: "\n Usage: \n guitr [options] [path_to_repo if not specified current directory will be used]\n \n Options:\n -s --status # default command to invoke, echos result of the 'git status'\n -p --pull # performs 'git pull' against all found repositories\n -u --unpushed # checks whether there are commits need to be pushed\n -e --exec CMD # operation to run given command (CMD) against repository directory was added \n -v --verbose # echos INFO level logs\n -t --trace # echos DEBUG level logs\n -V --version # print guitr version\n -h --help # print this help message \n \n For details go to http://webdizz.name/posts/guitr\n "
121
121
  rdoc_options:
122
122
  - --main
123
123
  - README.rdoc