git_remote_branch 0.2.6 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,18 @@
1
+ * Release 0.3.0 *
2
+
3
+ Housekeeping
4
+ - Support for a bunch of platforms has been added (Windows, Ubuntu, Ruby 1.9)
5
+ - git_remote_branch now has actual online documentation: grb.rubyforge.org
6
+ - give useful error message if grb can't find the git executable
7
+
8
+ Features
9
+ - track now works even if you already have a local branch of the same name
10
+ - it uses git config instead of branch --track in that case
11
+ - the difference can be seen by running
12
+ - grb explain track master
13
+ - grb explain track non_existent_branch
14
+ - Let you force the usage of a specific git executable by setting the environment variable GRB_GIT to point to it. It's pretty much undocumented for now, except for this mention :-) The tests for the useful error message use this feature. So it works.
15
+
1
16
  * Release 0.2.6 *
2
17
  Three new actual features
3
18
  - grb rename, contributed by Caio Chassot (caiochassot.com)
File without changes
data/README.rdoc ADDED
@@ -0,0 +1,184 @@
1
+ = Why git_remote_branch?
2
+
3
+ git_remote_branch is a simple command-line tool that makes it very easy to manipulate
4
+ branches published in shared repositories.
5
+
6
+ git_remote_branch achieves this goal by sticking to a few principles:
7
+ - keep grb's commands extremely regular (they all look alike)
8
+ - support aliases for commands
9
+ - print all commands it runs on your behalf in red, so you eventually learn them
10
+
11
+ Another nice thing about git_remote_branch: it can simply explain a command
12
+ (print out all the corresponding git commands) instead of running them on your behalf.
13
+
14
+ Note: git_remote_branch assumes that the local and remote branches have the
15
+ same name. Multiple remote repositories (or origins) are supported.
16
+
17
+
18
+ = Installation
19
+
20
+ sudo gem install git_remote_branch --include-dependencies
21
+
22
+ If you have an old version of Rubygems, you may have to manually install the "colored" gem.
23
+ sudo gem install colored
24
+
25
+ If you're on Windows, you must also install "win32console" manually (before or after installing git_remote_branch doesn't matter).
26
+ gem install win32console colored
27
+
28
+
29
+ See the "Bleeding edge and development" section the end of this document for more details about fiddling with the source of git_remote_branch or running it with Ruby 1.9 (yes, it works).
30
+
31
+ = Usage
32
+
33
+ Notes:
34
+ - parts between brackets are optional
35
+ - When 'origin_server' is not specified, the name 'origin' is assumed.
36
+
37
+ Available commands (with aliases):
38
+
39
+
40
+ === Help
41
+
42
+ $ grb [-h|help] #=> Displays help
43
+
44
+ === create (alias: new)
45
+
46
+ Create a new local branch as well as a corresponding remote branch based on the
47
+ branch you currently have checked out.
48
+ Track the new remote branch. Checkout the new branch.
49
+
50
+ $ grb create branch_name [origin_server]
51
+
52
+
53
+ === publish (aliases: remotize, share)
54
+
55
+ Publish an existing local branch to the remote server.
56
+ Set up the local branch to track the new remote branch.
57
+
58
+ $ grb publish branch_name [origin_server]
59
+
60
+
61
+ === delete (aliases: destroy, kill, remove, rm)
62
+
63
+ Delete the remote branch then delete the local branch.
64
+ The local branch is not deleted if there are pending changes.
65
+
66
+ $ grb delete branch_name [origin_server]
67
+
68
+
69
+ === track (aliases: follow grab fetch)
70
+
71
+ Track an existing remote branch locally and checkout the branch.
72
+
73
+ $ grb track branch_name [origin_server]
74
+
75
+
76
+ === rename (aliases: rn mv move)
77
+
78
+ Rename a remote branch and its local tracking branch.
79
+ The branch you want to rename must be checked out.
80
+
81
+ # On branch to be renamed
82
+ $ grb rename new_branch_name [origin_server]
83
+
84
+
85
+ === explain
86
+
87
+ All commands can be prepended by the word 'explain'. Instead of executing the
88
+ command, git_remote_branch will simply output the list of commands you need to
89
+ run to accomplish that goal.
90
+ Examples:
91
+
92
+ $ grb explain create
93
+ git_remote_branch version 0.3.0
94
+
95
+ List of operations to do to create a new remote branch and track it locally:
96
+
97
+ git push origin master:refs/heads/branch_to_create
98
+ git fetch origin
99
+ git branch --track branch_to_create origin/branch_to_create
100
+ git checkout branch_to_create
101
+
102
+ Explain your specific case:
103
+
104
+ $ grb explain create my_branch github
105
+ git_remote_branch version 0.3.0
106
+
107
+ List of operations to do to create a new remote branch and track it locally:
108
+
109
+ git push github master:refs/heads/my_branch
110
+ git fetch github
111
+ git branch --track my_branch github/my_branch
112
+ git checkout my_branch
113
+
114
+ This, of course, works for each of the grb commands.
115
+
116
+ = More on git_remote_branch
117
+
118
+ - Documentation: http://grb.rubyforge.org
119
+ - News: http://programblings.com/category/git/git_remote_branch/
120
+ - Bug tracker: http://git-remote-branch.lighthouseapp.com/projects/19198-git_remote_branch/overview
121
+ - Code: http://github.com/webmat/git_remote_branch
122
+ - Mailing list: http://groups.google.com/group/git_remote_branch
123
+
124
+
125
+ == History
126
+
127
+ git_remote_branch in its current form was inspired by a script created by Carl Mercier and made public on his blog: {No nonsense GIT, part 1: git-remote-branch}[http://blog.carlmercier.com/2008/01/25/no-nonsense-git-part-1-git-remote-branch/]
128
+
129
+
130
+ == Contributors
131
+
132
+ - Mathieu Martin webmat@gmail.com
133
+ - Caio Chassot dev@caiochassot.com
134
+ - Axelson github.com/axelson
135
+ - Carl Mercier github.com/cmer
136
+
137
+
138
+ == Legalese
139
+
140
+ git_remote_branch is licensed under the MIT License. See the file LICENSE for details.
141
+
142
+ == Bleeding edge and development
143
+
144
+ (Notice the keyword "bleeding")
145
+
146
+ === Getting the bleeding edge
147
+
148
+ Installing from GitHub
149
+ sudo gem install webmat-git_remote_branch --source=http://gems.github.com
150
+
151
+ Note that the only stable version of the gem you should trust is the one from Rubyforge. The GitHub gem is a development gem. The GitHub gem WILL be rebuilt with the same version number, and other horrible things like that. If you use the github version of the gem, children will die! You've been warned.
152
+
153
+ Cloning the repo and installing from your copy
154
+ git clone git://github.com/webmat/git_remote_branch.git
155
+ rake install
156
+
157
+ === Testing dependencies
158
+
159
+ Note that git_remote_branch uses a few more gems for tests. Running any rake task will try to load them due to the way Rake::TestTask works.
160
+
161
+ sudo gem install thoughtbot-shoulda --source http://gems.github.com
162
+ sudo gem install mocha
163
+
164
+ An attempt is made to require 2 more optional gems: redgreen and ruby-debug. If they're not present, only a whiny message will be displayed.
165
+
166
+ === Supported platforms
167
+
168
+ git_remote_branch has been tested with the following configurations:
169
+
170
+ - OS X Leopard / Ruby 1.8.6 / Git 1.5.4.3 and 1.6.0.2
171
+ - OS X Leopard / Ruby 1.9.1 / Git 1.5.4.3 and 1.6.0.2
172
+ - Ubuntu Intrepid Ibex / Ruby 1.8.7 / Git 1.5.6.3
173
+ - Windows XP / Ruby 1.8.6 / Git 1.6.0.2 (the msys version)
174
+
175
+ Let me know if you have problems running git_remote_branch with your platform.
176
+
177
+ To run the test suite using Ruby 1.9, simply set the RUBY environment variable to point to your 1.9 interpreter and then run the 1.9 version of Rake. In my case, everything 1.9 is suffixed with 1.9:
178
+
179
+ $ RUBY=ruby1.9 rake1.9 test
180
+
181
+ Or on Windows (Ruby 1.9 not tested on Windows)
182
+
183
+ > set RUBY=ruby1.9
184
+ > rake1.9 test
data/Rakefile CHANGED
@@ -2,11 +2,16 @@ require 'rubygems'
2
2
 
3
3
  require 'rake'
4
4
 
5
- HERE = File.dirname(__FILE__)
6
- windows = (RUBY_PLATFORM =~ /win32|cygwin/) rescue nil
7
- SUDO = windows ? "" : "sudo"
5
+ GRB_ROOT = File.dirname(__FILE__)
6
+
7
+ #So we can use GitRemoteBranch::NAME, VERSION and so on.
8
+ require "#{GRB_ROOT}/lib/git_remote_branch"
9
+
10
+ SUDO = WINDOWS ? "" : "sudo"
8
11
 
9
- require "#{HERE}/lib/git_remote_branch"
10
12
  Dir['tasks/**/*.rake'].each { |rake| load rake }
11
13
 
14
+ desc 'Default: run all tests.'
12
15
  task :default => :test
16
+
17
+ task :clean => [:clobber_package, :clobber_rdoc]
data/bin/grb CHANGED
@@ -7,11 +7,24 @@ require "#{File.dirname(THIS_FILE)}/../lib/git_remote_branch"
7
7
 
8
8
  include GitRemoteBranch
9
9
 
10
+ def crap_out(message)
11
+ puts message
12
+ exit 1
13
+ end
14
+
15
+ unless git_found?
16
+ crap_out <<-MSG
17
+ The git executable (#{GIT}) could not be found by git_remote_branch.
18
+ Make sure your PATH variable contains the path for git's binary.
19
+ Your PATH:
20
+ #{ENV['PATH'].split(/[:;]/) * "\n"}
21
+ MSG
22
+ end
23
+
10
24
  begin
11
25
  p = read_params(ARGV)
12
26
  rescue InvalidBranchError => ex
13
- puts ex.message
14
- exit 1
27
+ crap_out ex.message
15
28
  end
16
29
 
17
30
  $SILENT = p[:silent]
data/lib/constants.rb ADDED
@@ -0,0 +1,5 @@
1
+ module GitRemoteBranch
2
+ GIT = (ENV['GRB_GIT'] || 'git').freeze
3
+
4
+ LOCAL_BRANCH_LISTING_COMMAND = "#{GIT} branch -l".freeze
5
+ end
@@ -1,5 +1,18 @@
1
1
  require 'rubygems'
2
- require 'colored'
2
+
3
+ if RUBY_VERSION =~ /1\.8/
4
+ gem 'colored', '>= 1.1'
5
+ require 'colored'
6
+ else
7
+ class String
8
+ def red; self; end
9
+ end
10
+ end
11
+
12
+ begin
13
+ WINDOWS = !!(RUBY_PLATFORM =~ /win32|cygwin/)
14
+ rescue Exception
15
+ end
3
16
 
4
17
  grb_app_root = File.expand_path( File.dirname(__FILE__) + '/..' )
5
18
 
@@ -7,6 +20,9 @@ $LOAD_PATH.unshift( grb_app_root + '/vendor' )
7
20
  require 'capture_fu'
8
21
 
9
22
  $LOAD_PATH.unshift( grb_app_root + '/lib' )
23
+ require 'constants'
24
+ require 'string_ext'
25
+ require 'state'
10
26
  require 'param_reader'
11
27
  require 'version'
12
28
 
@@ -19,22 +35,22 @@ module GitRemoteBranch
19
35
  :description => 'create a new remote branch and track it locally',
20
36
  :aliases => %w{create new},
21
37
  :commands => [
22
- '"git push #{origin} #{current_branch}:refs/heads/#{branch_name}"',
23
- '"git fetch #{origin}"',
24
- '"git branch --track #{branch_name} #{origin}/#{branch_name}"',
25
- '"git checkout #{branch_name}"'
38
+ '"#{GIT} push #{origin} #{current_branch}:refs/heads/#{branch_name}"',
39
+ '"#{GIT} fetch #{origin}"',
40
+ '"#{GIT} branch --track #{branch_name} #{origin}/#{branch_name}"',
41
+ '"#{GIT} checkout #{branch_name}"'
26
42
  ]
27
43
  },
28
44
 
29
45
  :publish => {
30
46
  :description => 'publish an exiting local branch',
31
- :aliases => %w{publish remotize},
47
+ :aliases => %w{publish remotize share},
32
48
  :commands => [
33
- '"git push #{origin} #{branch_name}:refs/heads/#{branch_name}"',
34
- '"git fetch #{origin}"',
35
- '"git config branch.#{branch_name}.remote #{origin}"',
36
- '"git config branch.#{branch_name}.merge refs/heads/#{branch_name}"',
37
- '"git checkout #{branch_name}"'
49
+ '"#{GIT} push #{origin} #{branch_name}:refs/heads/#{branch_name}"',
50
+ '"#{GIT} fetch #{origin}"',
51
+ '"#{GIT} config branch.#{branch_name}.remote #{origin}"',
52
+ '"#{GIT} config branch.#{branch_name}.merge refs/heads/#{branch_name}"',
53
+ '"#{GIT} checkout #{branch_name}"'
38
54
  ]
39
55
  },
40
56
 
@@ -42,12 +58,12 @@ module GitRemoteBranch
42
58
  :description => 'rename a remote branch and its local tracking branch',
43
59
  :aliases => %w{rename rn mv move},
44
60
  :commands => [
45
- '"git push #{origin} #{current_branch}:refs/heads/#{branch_name}"',
46
- '"git fetch #{origin}"',
47
- '"git branch --track #{branch_name} #{origin}/#{branch_name}"',
48
- '"git checkout #{branch_name}"',
49
- '"git push #{origin} :refs/heads/#{current_branch}"',
50
- '"git branch -d #{current_branch}"',
61
+ '"#{GIT} push #{origin} #{current_branch}:refs/heads/#{branch_name}"',
62
+ '"#{GIT} fetch #{origin}"',
63
+ '"#{GIT} branch --track #{branch_name} #{origin}/#{branch_name}"',
64
+ '"#{GIT} checkout #{branch_name}"',
65
+ '"#{GIT} push #{origin} :refs/heads/#{current_branch}"',
66
+ '"#{GIT} branch -d #{current_branch}"',
51
67
  ]
52
68
  },
53
69
 
@@ -55,9 +71,9 @@ module GitRemoteBranch
55
71
  :description => 'delete a local and a remote branch',
56
72
  :aliases => %w{delete destroy kill remove rm},
57
73
  :commands => [
58
- '"git push #{origin} :refs/heads/#{branch_name}"',
59
- '"git checkout master" if current_branch == branch_name',
60
- '"git branch -d #{branch_name}"'
74
+ '"#{GIT} push #{origin} :refs/heads/#{branch_name}"',
75
+ '"#{GIT} checkout master" if current_branch == branch_name',
76
+ '"#{GIT} branch -d #{branch_name}"'
61
77
  ]
62
78
  },
63
79
 
@@ -65,9 +81,14 @@ module GitRemoteBranch
65
81
  :description => 'track an existing remote branch',
66
82
  :aliases => %w{track follow grab fetch},
67
83
  :commands => [
68
- '"git fetch #{origin}"',
69
- '"git checkout master" if current_branch == branch_name',
70
- '"git branch --track #{branch_name} #{origin}/#{branch_name}"'
84
+ # This string programming thing is getting old. Not flexible enough anymore.
85
+ '"#{GIT} fetch #{origin}"',
86
+ 'if local_branches.include?(branch_name)
87
+ "#{GIT} config branch.#{branch_name}.remote #{origin}\n" +
88
+ "#{GIT} config branch.#{branch_name}.merge refs/heads/#{branch_name}"
89
+ else
90
+ "#{GIT} branch --track #{branch_name} #{origin}/#{branch_name}"
91
+ end'
71
92
  ]
72
93
  }
73
94
  } unless defined?(COMMANDS)
data/lib/param_reader.rb CHANGED
@@ -1,5 +1,4 @@
1
1
  module GitRemoteBranch
2
- include ::CaptureFu
3
2
 
4
3
  private
5
4
  HELP_PARAMS = {:action => :help}
@@ -61,24 +60,4 @@ module GitRemoteBranch
61
60
  def get_origin(origin)
62
61
  return origin || 'origin'
63
62
  end
64
-
65
- private
66
- BRANCH_LISTING_COMMAND = 'git branch -l'.freeze
67
-
68
- public
69
- def get_current_branch
70
- #This is sensitive to checkouts of branches specified with wrong case
71
-
72
- listing = capture_process_output("#{BRANCH_LISTING_COMMAND}")[1]
73
- raise(NotOnGitRepositoryError, listing.chomp) if listing =~ /Not a git repository/i
74
-
75
- current_branch = listing.scan(/^\*\s+(.+)/).flatten.first
76
-
77
- if current_branch =~ /\(no branch\)/
78
- raise InvalidBranchError, ["Couldn't identify the current local branch. The branch listing was:",
79
- BRANCH_LISTING_COMMAND.red,
80
- listing].join("\n")
81
- end
82
- current_branch.strip
83
- end
84
63
  end
data/lib/state.rb ADDED
@@ -0,0 +1,42 @@
1
+ module GitRemoteBranch
2
+ include ::CaptureFu
3
+
4
+ public
5
+ def get_current_branch
6
+ local_branch_information[0]
7
+ end
8
+
9
+ def local_branches
10
+ local_branch_information[1]
11
+ end
12
+
13
+ def git_found?
14
+ ret, msg = capture_process_output "#{GIT} --version"
15
+ ret == 0
16
+ end
17
+
18
+ private
19
+ # Returns an array of 2 elements: [current_branch, [all local branches]]
20
+ def local_branch_information
21
+ #This is sensitive to checkouts of branches specified with wrong case
22
+
23
+ listing = capture_process_output("#{LOCAL_BRANCH_LISTING_COMMAND}")[1]
24
+
25
+ raise(NotOnGitRepositoryError, listing.chomp) if listing =~ /Not a git repository/i
26
+ if listing =~ /\(no branch\)/
27
+ raise InvalidBranchError, ["Couldn't identify the current local branch. The branch listing was:",
28
+ LOCAL_BRANCH_LISTING_COMMAND.red,
29
+ listing].join("\n")
30
+ end
31
+
32
+ current_branch = nil
33
+ branches = listing.split("\n").map do |line|
34
+ current = line.include? '*'
35
+ clean_line = line.gsub('*','').strip
36
+ current_branch = clean_line if current
37
+ clean_line
38
+ end
39
+
40
+ return current_branch, branches
41
+ end
42
+ end
data/lib/string_ext.rb ADDED
@@ -0,0 +1,5 @@
1
+ class String
2
+ def path_for_os
3
+ WINDOWS ? self.gsub('/', '\\') : self
4
+ end
5
+ end
data/lib/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module GitRemoteBranch
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 2
5
- TINY = 6
4
+ MINOR = 3
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.').freeze
8
8
  end
data/tasks/gem.rake CHANGED
@@ -2,8 +2,6 @@ require 'yaml'
2
2
 
3
3
  require 'rake/gempackagetask'
4
4
 
5
- task :clean => :clobber_package
6
-
7
5
  spec = Gem::Specification.new do |s|
8
6
  s.name = GitRemoteBranch::NAME
9
7
  s.version = GitRemoteBranch::VERSION::STRING
@@ -16,10 +14,12 @@ spec = Gem::Specification.new do |s|
16
14
  s.homepage = "http://github.com/webmat/git_remote_branch"
17
15
  s.rubyforge_project = 'grb'
18
16
 
19
- s.has_rdoc = false
17
+ s.has_rdoc = true
18
+ s.extra_rdoc_files << 'README.rdoc'
19
+ s.rdoc_options << '--main' << 'README.rdoc' << '--exclude' << 'lib'
20
20
 
21
- s.test_files = Dir['test/**/*']
22
- s.files = Dir['**/*'].reject{|f| f =~ /\Apkg|\Acoverage|\.gemspec\Z/}
21
+ s.test_files = Dir['test/**/*'].reject{|f| f =~ /test_runs/}
22
+ s.files = Dir['**/*'].reject{|f| f =~ /\Apkg|\Acoverage|\Ardoc|test_runs|\.gemspec\Z/}
23
23
 
24
24
  s.executable = 'grb'
25
25
  s.bindir = "bin"
@@ -59,15 +59,30 @@ namespace :gem do
59
59
  desc 'Upload gem to rubyforge.org'
60
60
  task :rubyforge => :gem do
61
61
  sh 'rubyforge login'
62
- sh "rubyforge add_release grb grb 'release #{GitRemoteBranch::VERSION::STRING}' pkg/#{spec.full_name}.gem"
62
+ sh "rubyforge add_release grb grb '#{GitRemoteBranch::VERSION::STRING}' pkg/#{spec.full_name}.gem"
63
63
  sh "rubyforge add_file grb grb #{GitRemoteBranch::VERSION::STRING} pkg/#{spec.full_name}.gem"
64
64
  end
65
- end
66
-
67
- task :install => [:clean, :gem] do
68
- sh "#{SUDO} gem install pkg/#{spec.full_name}.gem"
69
- end
70
-
71
- task :uninstall do
72
- sh "#{SUDO} gem uninstall -v #{GitRemoteBranch::VERSION::STRING} -x #{GitRemoteBranch::NAME}"
65
+
66
+ desc 'Install the gem built locally'
67
+ task :install => [:clean, :gem] do
68
+ sh "#{SUDO} gem install pkg/#{spec.full_name}.gem"
69
+ end
70
+
71
+ desc "Uninstall version #{GitRemoteBranch::VERSION::STRING} of the gem"
72
+ task :uninstall do
73
+ sh "#{SUDO} gem uninstall -v #{GitRemoteBranch::VERSION::STRING} -x #{GitRemoteBranch::NAME}"
74
+ end
75
+
76
+ if WINDOWS
77
+ win_spec = spec.dup
78
+ win_spec.platform = Gem::Platform::CURRENT
79
+ win_spec.add_dependency( 'win32console', '~> 1.1' ) # Missing dependency in the 'colored' gem
80
+
81
+ desc "Generate the Windows version of the gem"
82
+ namespace :windows do
83
+ Rake::GemPackageTask.new(win_spec) do |p|
84
+ p.gem_spec = win_spec
85
+ end
86
+ end
87
+ end
73
88
  end
data/tasks/rdoc.rake ADDED
@@ -0,0 +1,15 @@
1
+ require 'rake/rdoctask'
2
+
3
+ desc 'Generate rdoc documentation'
4
+ Rake::RDocTask.new(:rdoc) do |rdoc|
5
+ rdoc.rdoc_dir = 'rdoc'
6
+ rdoc.title = GitRemoteBranch::NAME
7
+ rdoc.rdoc_files.include('README.rdoc')
8
+ end
9
+
10
+ namespace :rdoc do
11
+ desc 'Upload documentation to rubyforge'
12
+ task :upload => :rdoc do
13
+ sh "scp -r #{GRB_ROOT}/rdoc/* webmat@rubyforge.org:/var/www/gforge-projects/grb/"
14
+ end
15
+ end
data/tasks/test.rake CHANGED
@@ -1,10 +1,7 @@
1
1
  require 'rake/testtask'
2
2
 
3
3
  desc "Run all tests"
4
- Rake::TestTask.new(:test) do |t|
5
- t.pattern = 'test/**/*_test.rb'
6
- t.verbose = true
7
- end
4
+ task :test => ["test:unit", "test:functional"]
8
5
 
9
6
  namespace :test do
10
7
  desc "Run functional tests"
@@ -2,7 +2,7 @@ require File.join( File.dirname(__FILE__), '..', 'test_helper')
2
2
 
3
3
  class GRBTest < Test::Unit::TestCase
4
4
  include ShouldaFunctionalHelpers
5
-
5
+
6
6
  on_a_repository do
7
7
  context "creating a branch in a local clone" do
8
8
  setup do
@@ -20,13 +20,35 @@ class GRBTest < Test::Unit::TestCase
20
20
  should_have_branch 'new_branch', :local
21
21
  end
22
22
 
23
- context "the other local clone, tracking the new branch" do
23
+ context "the other local clone" do
24
24
  setup do
25
25
  in_directory_for :local2
26
- run_grb_with 'track new_branch'
27
26
  end
28
27
 
29
- should_have_branch 'new_branch', :local, :remote
28
+ context "not already having a branch of the same name" do
29
+ setup do
30
+ @output = run_grb_with 'track new_branch'
31
+ end
32
+
33
+ should_have_branch 'new_branch', :local, :remote
34
+
35
+ should "use the branch --track command" do
36
+ assert_match %r{branch --track}, @output
37
+ end
38
+ end
39
+
40
+ context "having a branch of the same name" do
41
+ setup do
42
+ execute "git branch new_branch"
43
+ @output = run_grb_with 'track new_branch'
44
+ end
45
+
46
+ should_have_branch 'new_branch', :local, :remote
47
+
48
+ should "use git config to connect the branches" do
49
+ assert_match %r{git\sconfig}, @output
50
+ end
51
+ end
30
52
  end
31
53
 
32
54
  context "then deleting the branch" do
@@ -106,6 +128,18 @@ class GRBTest < Test::Unit::TestCase
106
128
  end
107
129
 
108
130
  in_a_non_git_directory do
131
+ with_env_var :GRB_GIT, 'unknown_git_executable_name' do
132
+ context "when git is not in the path" do
133
+ setup do
134
+ @text = run_grb_with ''
135
+ end
136
+ should "complain about git not being in the path" do
137
+ assert_match %r{unknown_git_executable_name}, @text
138
+ assert_match %r{PATH}, @text
139
+ end
140
+ end
141
+ end
142
+
109
143
  context "displaying help" do
110
144
  setup do
111
145
  @text = run_grb_with 'help'
@@ -0,0 +1,15 @@
1
+ REGULAR_BRANCH_LISTING = <<-STR
2
+ other_user/master
3
+ * stubbed_current_branch
4
+ rubyforge
5
+ STR
6
+
7
+ BRANCH_LISTING_WHEN_NOT_ON_BRANCH = <<-STR
8
+ * (no branch)
9
+ other_user/master
10
+ master
11
+ rubyforge
12
+ STR
13
+
14
+ WHEN_NOT_ON_GIT_REPOSITORY = "fatal: Not a git repository\n"
15
+
@@ -1,5 +1,4 @@
1
- require 'fileutils'
2
- require 'tmpdir'
1
+ require File.dirname(__FILE__) + '/in_dir'
3
2
  require File.dirname(__FILE__) + '/temp_dir_helper'
4
3
 
5
4
  # Instantiating a GitHelper object creates a temp directory containing 3 repos.
@@ -8,12 +7,13 @@ require File.dirname(__FILE__) + '/temp_dir_helper'
8
7
  # Once instantiated you can access the 3 full repo locations through attribute readers
9
8
  # remote, local1 and local2.
10
9
  class GitHelper < TempDirHelper
11
-
10
+ include InDir
11
+ GIT = GitRemoteBranch::GIT
12
+
12
13
  attr_reader :remote, :local1, :local2
13
14
 
14
15
  def initialize
15
- super('grb_test')
16
-
16
+ super("#{TEST_DIR}/test_runs")
17
17
  @remote = init_repo(directory, 'remote')
18
18
  @local1 = clone_repo(@remote, directory, 'local1')
19
19
  @local2 = clone_repo(@remote, directory, 'local2')
@@ -22,12 +22,19 @@ class GitHelper < TempDirHelper
22
22
  protected
23
23
  def init_repo(path, name)
24
24
  repo_dir = File.join(path, name)
25
- `mkdir #{repo_dir}; cd $_; git init; touch file.txt; git add .; git commit -a -m "dummy file"`
25
+ mkdir_p repo_dir
26
+
27
+ in_dir repo_dir do
28
+ `#{GIT} init && echo "foo" > file.txt && #{GIT} add . && #{GIT} commit -a -m "dummy file"`
29
+ end
30
+ raise "Error setting up repository #{name}" unless $?.exitstatus == 0
26
31
  repo_dir
27
32
  end
28
33
 
29
34
  def clone_repo(origin_path, clone_path, name)
30
- `cd #{clone_path}; git clone #{File.join(origin_path, '.git')} #{name}`
35
+ in_dir clone_path do
36
+ `#{GIT} clone #{File.join(origin_path, '.git').path_for_os} #{name}`
37
+ end
31
38
  return File.join(clone_path, name)
32
39
  end
33
40
  end
@@ -0,0 +1,10 @@
1
+ module InDir
2
+ def in_dir(dir, &block)
3
+ prev_dir = Dir.pwd
4
+ Dir.chdir dir
5
+
6
+ yield
7
+ ensure
8
+ Dir.chdir prev_dir
9
+ end
10
+ end
@@ -1,6 +1,23 @@
1
1
  module ShouldaFunctionalHelpers
2
2
  include CaptureFu
3
- GRB_COMMAND = File.expand_path(File.dirname(__FILE__) + '/../../bin/grb') unless defined?(GRB_COMMAND)
3
+ include InDir
4
+
5
+ GIT = GitRemoteBranch::GIT
6
+
7
+ def self.ruby_prefix
8
+ if ENV['RUBY']
9
+ warn " Forcing execution of grb with ruby interpreter #{ENV['RUBY']}"
10
+ ENV['RUBY'] + ' '
11
+ elsif WINDOWS
12
+ 'ruby '
13
+ else
14
+ ''
15
+ end
16
+ end
17
+
18
+ # Here we're only prepending with 'ruby'.
19
+ # When run as a gem, RubyGems takes care of generating a batch file that does this stuff.
20
+ GRB_COMMAND = ruby_prefix + File.expand_path(File.dirname(__FILE__) + '/../../bin/grb') unless defined?(GRB_COMMAND)
4
21
 
5
22
  def self.included(base)
6
23
  base.extend ClassMethods
@@ -29,7 +46,7 @@ module ShouldaFunctionalHelpers
29
46
  end
30
47
 
31
48
  def in_branch(branch)
32
- execute "git checkout #{branch}"
49
+ execute "#{GIT} checkout #{branch}"
33
50
  end
34
51
 
35
52
 
@@ -38,8 +55,10 @@ module ShouldaFunctionalHelpers
38
55
  end
39
56
 
40
57
  def execute(command)
41
- errno, returned_string = capture_process_output("cd #{current_dir} ; #{command}")
42
- returned_string
58
+ in_dir current_dir do
59
+ errno, returned_string = capture_process_output(command)
60
+ returned_string
61
+ end
43
62
  end
44
63
 
45
64
  private
@@ -60,7 +79,7 @@ module ShouldaFunctionalHelpers
60
79
  wheres.flatten.each do |where|
61
80
  should "have the branch '#{what_branch}' #{where == :local ? 'locally' : 'remotely'}" do
62
81
  args = get_branch_location(where)
63
- assert_match(/#{what_branch}/, execute("git branch #{args}"))
82
+ assert_match(/#{what_branch}/, execute("#{GIT} branch #{args}"))
64
83
  end
65
84
  end
66
85
  end
@@ -69,7 +88,7 @@ module ShouldaFunctionalHelpers
69
88
  wheres.flatten.each do |where|
70
89
  should "not have the branch '#{what_branch}' #{where == :local ? 'locally' : 'remotely'}" do
71
90
  args = get_branch_location(where)
72
- assert_no_match(/#{what_branch}/, execute("git branch #{args}"))
91
+ assert_no_match(/#{what_branch}/, execute("#{GIT} branch #{args}"))
73
92
  end
74
93
  end
75
94
  end
@@ -84,7 +103,9 @@ module ShouldaFunctionalHelpers
84
103
  @gh.cleanup
85
104
  end
86
105
 
87
- yield
106
+ context '' do
107
+ yield
108
+ end
88
109
  end
89
110
  end
90
111
 
@@ -99,7 +120,32 @@ module ShouldaFunctionalHelpers
99
120
  @temp_dir.cleanup
100
121
  end
101
122
 
102
- yield
123
+ context '' do
124
+ yield
125
+ end
126
+ end
127
+ end
128
+
129
+ def with_env_var(name, value)
130
+ name = name.to_s
131
+
132
+ context "with environment variable '#{name}' set to '#{value}'" do
133
+ setup do
134
+ @env_previous_value = ENV[name] if ENV.keys.include?(name)
135
+ ENV[name] = value
136
+ end
137
+
138
+ teardown do
139
+ if @env_previous_value
140
+ ENV[name] = @env_previous_value
141
+ else
142
+ ENV.delete(name)
143
+ end
144
+ end
145
+
146
+ context '' do
147
+ yield
148
+ end
103
149
  end
104
150
  end
105
151
  end
@@ -6,8 +6,8 @@ class TempDirHelper
6
6
 
7
7
  attr_reader :directory
8
8
 
9
- def initialize(namespace='temp_dir_helper')
10
- @directory = get_temp_dir!(namespace)
9
+ def initialize(force_temp_dir=nil)
10
+ @directory = get_temp_dir!(force_temp_dir)
11
11
  end
12
12
 
13
13
  def cleanup
@@ -19,14 +19,14 @@ class TempDirHelper
19
19
  end
20
20
 
21
21
  private
22
- def get_temp_dir!(namespace='')
23
- wd = File.expand_path( File.join( Dir::tmpdir, namespace) )
24
- mkdir wd unless File.exists? wd
22
+ def get_temp_dir!(parent_dir=nil)
23
+ temp_root = File.expand_path( File.join( parent_dir || Dir::tmpdir) )
24
+ mkdir_p temp_root
25
25
 
26
26
  #Create new subdir with a random name
27
27
  new_dir=''
28
28
  begin
29
- new_dir = File.join( wd, "#{rand(10000)}" )
29
+ new_dir = File.join( temp_root, "#{rand(10000)}" )
30
30
  mkdir new_dir
31
31
 
32
32
  rescue
data/test/test_helper.rb CHANGED
@@ -1,22 +1,30 @@
1
1
  require 'rubygems'
2
2
  require 'test/unit'
3
3
 
4
- test_dir = File.dirname(__FILE__)
4
+ TEST_DIR = File.dirname(__FILE__)
5
5
 
6
- # Install the non-Rails shoulda gem with 'gem install Shoulda'
7
- # Notice the capitalization in the name.
6
+ # Install version 2 the shoulda gem with
7
+ # gem install thoughtbot-shoulda --source http://gems.github.com
8
+ # Shoulda depends on ActiveSupport 2.0, so if you don't have Rails 2.x installed, install ActiveSupport before Shoulda:
9
+ # gem install activesupport
10
+ gem 'thoughtbot-shoulda', '~> 2.0'
8
11
  require 'shoulda'
12
+ gem 'mocha', '~> 0.5'
9
13
  require 'mocha'
10
14
 
11
15
  # Just load redgreen if not running tests from TextMate
12
16
  IN_TM = !ENV['TM_DIRECTORY'].nil? unless defined?(IN_TM)
13
- require 'redgreen' unless IN_TM
14
-
15
- require 'ruby-debug'
17
+ begin
18
+ require 'redgreen' unless IN_TM
19
+ require 'ruby-debug'
20
+ rescue LoadError => ex
21
+ puts "Couldn't load optional test dependencies.\n #{ex.inspect}"
22
+ end
16
23
 
17
- require File.join( [test_dir] + %w{ .. lib git_remote_branch} )
24
+ require File.join( [TEST_DIR] + %w{ .. lib git_remote_branch} )
18
25
 
19
- Dir[test_dir+'/helpers/**/*.rb'].each{|f| require f}
26
+ require "#{TEST_DIR}/helpers/in_dir"
27
+ Dir[TEST_DIR+'/helpers/**/*.rb'].each{|f| require f}
20
28
 
21
29
  class Test::Unit::TestCase
22
30
  include MoreAssertions
@@ -1,19 +1,5 @@
1
1
  require File.join( File.dirname(__FILE__), '..', 'test_helper')
2
-
3
- REGULAR_BRANCH_LISTING = <<-STR
4
- other_user/master
5
- * stubbed_current_branch
6
- rubyforge
7
- STR
8
-
9
- BRANCH_LISTING_WHEN_NOT_ON_BRANCH = <<-STR
10
- * (no branch)
11
- other_user/master
12
- master
13
- rubyforge
14
- STR
15
-
16
- WHEN_NOT_ON_GIT_REPOSITORY = "fatal: Not a git repository\n"
2
+ require "#{TEST_DIR}/helpers/constants"
17
3
 
18
4
  class ParamReaderTest < Test::Unit::TestCase
19
5
  include ShouldaUnitHelpers
@@ -168,38 +154,6 @@ class ParamReaderTest < Test::Unit::TestCase
168
154
  end
169
155
  end
170
156
 
171
- context 'get_current_branch' do
172
- context "when not on a git repository" do
173
- setup do
174
- grb.stubs(:capture_process_output).returns([128, WHEN_NOT_ON_GIT_REPOSITORY])
175
- end
176
-
177
- should "raise an exception" do
178
- assert_raise(GitRemoteBranch::NotOnGitRepositoryError) { grb.get_current_branch }
179
- end
180
- end
181
-
182
- context "when on an invalid branch" do
183
- setup do
184
- grb.stubs(:capture_process_output).returns([0, BRANCH_LISTING_WHEN_NOT_ON_BRANCH])
185
- end
186
-
187
- should "raise an exception" do
188
- assert_raise(GitRemoteBranch::InvalidBranchError) { grb.get_current_branch }
189
- end
190
- end
191
-
192
- context "when on a valid branch" do
193
- setup do
194
- grb.stubs(:capture_process_output).returns([0, REGULAR_BRANCH_LISTING])
195
- end
196
-
197
- should "return the current branch name" do
198
- assert_equal 'stubbed_current_branch', grb.get_current_branch
199
- end
200
- end
201
- end
202
-
203
157
  context 'explain_mode!' do
204
158
  context "when it receives an array beginning with 'explain'" do
205
159
  setup do
@@ -0,0 +1,56 @@
1
+ require File.join( File.dirname(__FILE__), '..', 'test_helper')
2
+ require "#{TEST_DIR}/helpers/constants"
3
+
4
+ class ParamReaderTest < Test::Unit::TestCase
5
+ include ShouldaUnitHelpers
6
+
7
+ def self.craps_out_in_invalid_situations
8
+ context "when not on a git repository" do
9
+ setup do
10
+ grb.stubs(:capture_process_output).returns([128, WHEN_NOT_ON_GIT_REPOSITORY])
11
+ end
12
+
13
+ should "raise an exception" do
14
+ assert_raise(GitRemoteBranch::NotOnGitRepositoryError) { grb.get_current_branch }
15
+ end
16
+ end
17
+
18
+ context "when on an invalid branch" do
19
+ setup do
20
+ grb.stubs(:capture_process_output).returns([0, BRANCH_LISTING_WHEN_NOT_ON_BRANCH])
21
+ end
22
+
23
+ should "raise an exception" do
24
+ assert_raise(GitRemoteBranch::InvalidBranchError) { grb.get_current_branch }
25
+ end
26
+ end
27
+ end
28
+
29
+ context 'get_current_branch' do
30
+ craps_out_in_invalid_situations
31
+
32
+ context "when on a valid branch" do
33
+ setup do
34
+ grb.stubs(:capture_process_output).returns([0, REGULAR_BRANCH_LISTING])
35
+ end
36
+
37
+ should "return the current branch name" do
38
+ assert_equal 'stubbed_current_branch', grb.get_current_branch
39
+ end
40
+ end
41
+ end
42
+
43
+ context 'local_branches' do
44
+ craps_out_in_invalid_situations
45
+
46
+ context "when on a valid branch" do
47
+ setup do
48
+ grb.stubs(:capture_process_output).returns([0, REGULAR_BRANCH_LISTING])
49
+ end
50
+
51
+ should "return all the local branch names" do
52
+ assert_array_content %w{stubbed_current_branch other_user/master rubyforge}, grb.local_branches
53
+ end
54
+ end
55
+ end
56
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_remote_branch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.6
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu Martin
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2008-08-06 00:00:00 -04:00
13
+ date: 2008-11-14 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -29,30 +29,35 @@ executables:
29
29
  - grb
30
30
  extensions: []
31
31
 
32
- extra_rdoc_files: []
33
-
32
+ extra_rdoc_files:
33
+ - README.rdoc
34
34
  files:
35
35
  - bin
36
36
  - bin/grb
37
37
  - CHANGELOG
38
- - COPYING
39
38
  - lib
39
+ - lib/constants.rb
40
40
  - lib/git_remote_branch.rb
41
41
  - lib/param_reader.rb
42
+ - lib/state.rb
43
+ - lib/string_ext.rb
42
44
  - lib/version.rb
45
+ - LICENSE
43
46
  - Rakefile
44
- - README
47
+ - README.rdoc
45
48
  - tasks
46
49
  - tasks/gem.rake
50
+ - tasks/rdoc.rake
47
51
  - tasks/test.rake
48
52
  - test
49
53
  - test/functional
50
54
  - test/functional/grb_test.rb
51
55
  - test/helpers
52
56
  - test/helpers/array_extensions.rb
53
- - test/helpers/dir_stack.rb
57
+ - test/helpers/constants.rb
54
58
  - test/helpers/extractable.rb
55
59
  - test/helpers/git_helper.rb
60
+ - test/helpers/in_dir.rb
56
61
  - test/helpers/more_assertions.rb
57
62
  - test/helpers/shoulda_functional_helpers.rb
58
63
  - test/helpers/shoulda_unit_helpers.rb
@@ -62,14 +67,17 @@ files:
62
67
  - test/unit/git_helper_test.rb
63
68
  - test/unit/git_remote_branch_test.rb
64
69
  - test/unit/param_reader_test.rb
65
- - TODO
70
+ - test/unit/state_test.rb
66
71
  - vendor
67
72
  - vendor/capture_fu.rb
68
- has_rdoc: false
73
+ has_rdoc: true
69
74
  homepage: http://github.com/webmat/git_remote_branch
70
75
  post_install_message:
71
- rdoc_options: []
72
-
76
+ rdoc_options:
77
+ - --main
78
+ - README.rdoc
79
+ - --exclude
80
+ - lib
73
81
  require_paths:
74
82
  - lib
75
83
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -87,7 +95,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
95
  requirements: []
88
96
 
89
97
  rubyforge_project: grb
90
- rubygems_version: 1.2.0
98
+ rubygems_version: 1.3.0
91
99
  signing_key:
92
100
  specification_version: 2
93
101
  summary: git_remote_branch eases the interaction with remote branches
@@ -96,9 +104,10 @@ test_files:
96
104
  - test/functional/grb_test.rb
97
105
  - test/helpers
98
106
  - test/helpers/array_extensions.rb
99
- - test/helpers/dir_stack.rb
107
+ - test/helpers/constants.rb
100
108
  - test/helpers/extractable.rb
101
109
  - test/helpers/git_helper.rb
110
+ - test/helpers/in_dir.rb
102
111
  - test/helpers/more_assertions.rb
103
112
  - test/helpers/shoulda_functional_helpers.rb
104
113
  - test/helpers/shoulda_unit_helpers.rb
@@ -108,3 +117,4 @@ test_files:
108
117
  - test/unit/git_helper_test.rb
109
118
  - test/unit/git_remote_branch_test.rb
110
119
  - test/unit/param_reader_test.rb
120
+ - test/unit/state_test.rb
data/README DELETED
@@ -1,140 +0,0 @@
1
- ==== Why git_remote_branch? ====
2
-
3
- The basic idea for git_remote_branch is to trivialize the interaction with
4
- remote branches in simple situations.
5
-
6
- For now git_remote_branch assumes that the local and remote branches have the
7
- same name. Multiple origins are supported.
8
-
9
- Another goal of git_remote_branch is to help teach the real underlying git
10
- commands. Each operation done on your behalf is displayed at the console.
11
-
12
-
13
-
14
- ==== Installation ====
15
-
16
- sudo gem install grb
17
-
18
-
19
- Or if you want the bleeding edge from GitHub
20
- You may try
21
- sudo gem install webmat-git_remote_branch --source=http://gems.github.com
22
-
23
- But you're probably better off with
24
- git clone git://github.com/webmat/git_remote_branch.git
25
- rake install
26
-
27
-
28
-
29
- ==== Usage ====
30
-
31
- Notes:
32
- - parts between brackets are optional
33
- - When 'origin_server' is not specified, the name 'origin' is assumed.
34
-
35
- Available commands (with aliases):
36
-
37
-
38
- == Help ==
39
-
40
- $ grb [-h|help] #=> Displays help
41
-
42
- == create (alias: new) ==
43
- Create a new local branch as well as a corresponding remote branch from the
44
- branch you are currently on.
45
- Automatically track the new remote branch (useful for pulling and merging).
46
- Switch to the new branch.
47
-
48
- $ grb create branch_name [origin_server]
49
-
50
-
51
- == publish (aliases: remotize) ==
52
- Publish an existing local branch to the remote server.
53
- Set up the local branch to track the new remote branch.
54
- Switch to the new branch.
55
-
56
- $ grb publish branch_name [origin_server]
57
-
58
-
59
- == delete (aliases: destroy, kill, remove) ==
60
- Delete the remote branch then delete the local branch.
61
- The local branch is not deleted if there are pending changes.
62
-
63
- $ grb delete branch_name [origin_server]
64
-
65
-
66
- == track (aliases: follow grab fetch) ==
67
- Track an existing remote branch locally.
68
-
69
- $ grb track branch_name [origin_server]
70
-
71
-
72
- == rename (aliases: rn, mv, move) ==
73
- To rename the branch you're currently on.
74
- Rename the remote branch by copying then deleting the old name.
75
- Checkout a new local tracking branch with the new name and delete the local
76
- branch with the old name.
77
-
78
- $ grb rename branch_name [origin_server]
79
-
80
-
81
- == explain ==
82
-
83
- All commands can be prepended by the word 'explain'. Instead of executing the
84
- command, git_remote_branch will simply output the list of commands you need to
85
- run to accomplish that goal.
86
- Examples:
87
-
88
- $ grb explain create
89
- git_remote_branch version 0.2.6
90
-
91
- List of operations to do to create a new remote branch and track it locally:
92
-
93
- git push origin master:refs/heads/branch_to_create
94
- git fetch origin
95
- git branch --track branch_to_create origin/branch_to_create
96
- git checkout branch_to_create
97
-
98
-
99
- $ grb explain create my_branch github
100
- git_remote_branch version 0.2.6
101
-
102
- List of operations to do to create a new remote branch and track it locally:
103
-
104
- git push github master:refs/heads/my_branch
105
- git fetch github
106
- git branch --track my_branch github/my_branch
107
- git checkout my_branch
108
-
109
-
110
-
111
- ==== More on git_remote_branch ====
112
-
113
- Site: http://github.com/webmat/git_remote_branch
114
- Mailing list: http://groups.google.com/group/git_remote_branch
115
-
116
-
117
-
118
- ==== History ====
119
-
120
- This script was originally created by Carl Mercier and made public on his blog
121
- here:
122
-
123
- No nonsense GIT, part 1: git-remote-branch
124
- http://blog.carlmercier.com/2008/01/25/no-nonsense-git-part-1-git-remote-branch/
125
-
126
-
127
- I'm using it as a starting point to make it even easier to interact with remote
128
- repositories.
129
-
130
-
131
- == Contributors ==
132
-
133
- - Mathieu Martin webmat@gmail.com
134
- - Carl Mercier (Carl: want your email here?)
135
- - Caio Chassot dev@caiochassot.com
136
-
137
-
138
- == Legalese ==
139
-
140
- git_remote_branch is licensed under the MIT License. See the file COPYING for details.
data/TODO DELETED
@@ -1,16 +0,0 @@
1
- - tests :-)
2
- - offer help when branch -d fails
3
- - connect (new remote repo)
4
- - Make remotize work when not specifying the local branch (and use this one by default)
5
- - avoid deleting local branches when tracking with the help of git-config ?
6
-
7
- - drop assumption that master can be treated differently than other branches (e.g. considered as a safe checkout)
8
- - reliance on current_branch
9
- - is it even necessary to be on a branch per se? I think not...
10
- - survive checkouts with wrong case
11
- e.g.: branch "Bob" checked out branch 'bob'. git branch -l won't correctly flag branch Bob as current.
12
-
13
- - better exit status behavior
14
- - Add verification if remote delete didn't work
15
- - add support for different remote name (--remote-name)
16
-
@@ -1,25 +0,0 @@
1
- class DirStack
2
- attr_reader :dir_stack
3
-
4
- def current_dir
5
- dir_stack.size == 0 ? Dir.pwd : dir_stack.last
6
- end
7
-
8
- def pushd(dirname)
9
- dir_stack.push(File.expand_path(dirname))
10
- end
11
-
12
- def popd
13
- return [] if dir_stack.size==0
14
- dir_stack.pop
15
- dir_stack
16
- end
17
-
18
- def to_s
19
- dir_stack.inspect
20
- end
21
-
22
- def initialize
23
- @dir_stack = []
24
- end
25
- end