webmat-git_remote_branch 0.2.7 → 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
@@ -1,28 +1,32 @@
1
1
  = Why git_remote_branch?
2
2
 
3
- The basic idea for git_remote_branch is to trivialize the interaction with
4
- remote branches in simple situations.
3
+ git_remote_branch is a simple command-line tool that makes it very easy to manipulate
4
+ branches published in shared repositories.
5
5
 
6
- For now git_remote_branch assumes that the local and remote branches have the
7
- same name. Multiple origins are supported.
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
8
10
 
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
+ 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.
11
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.
12
16
 
13
17
 
14
18
  = Installation
15
19
 
16
- sudo gem install git_remote_branch
20
+ sudo gem install git_remote_branch --include-dependencies
17
21
 
18
- If you have an older version of Rubygems (older than 1.2), you will have to manually install the "colored" gem.
22
+ If you have an old version of Rubygems, you may have to manually install the "colored" gem.
19
23
  sudo gem install colored
20
24
 
21
- If you're on Windows, you must install "colored" and "win32console" manually (before or after installing git_remote_branch doesn't matter).
25
+ If you're on Windows, you must also install "win32console" manually (before or after installing git_remote_branch doesn't matter).
22
26
  gem install win32console colored
23
27
 
24
28
 
25
- See the "Bleeding edge and development" section the end of this document for more details about fiddling with the source of git_remote_branch.
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).
26
30
 
27
31
  = Usage
28
32
 
@@ -39,24 +43,22 @@ Available commands (with aliases):
39
43
 
40
44
  === create (alias: new)
41
45
 
42
- Create a new local branch as well as a corresponding remote branch from the
43
- branch you are currently on.
44
- Automatically track the new remote branch (useful for pulling and merging).
45
- Switch to the new branch.
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.
46
49
 
47
50
  $ grb create branch_name [origin_server]
48
51
 
49
52
 
50
- === publish (aliases: remotize)
53
+ === publish (aliases: remotize, share)
51
54
 
52
55
  Publish an existing local branch to the remote server.
53
56
  Set up the local branch to track the new remote branch.
54
- Switch to the new branch.
55
57
 
56
58
  $ grb publish branch_name [origin_server]
57
59
 
58
60
 
59
- === delete (aliases: destroy, kill, remove)
61
+ === delete (aliases: destroy, kill, remove, rm)
60
62
 
61
63
  Delete the remote branch then delete the local branch.
62
64
  The local branch is not deleted if there are pending changes.
@@ -66,18 +68,18 @@ The local branch is not deleted if there are pending changes.
66
68
 
67
69
  === track (aliases: follow grab fetch)
68
70
 
69
- Track an existing remote branch locally.
71
+ Track an existing remote branch locally and checkout the branch.
70
72
 
71
73
  $ grb track branch_name [origin_server]
72
74
 
73
75
 
74
- === rename (aliases: rn, mv, move)
75
- To rename the branch you're currently on.
76
- Rename the remote branch by copying then deleting the old name.
77
- Checkout a new local tracking branch with the new name and delete the local
78
- branch with the old name.
76
+ === rename (aliases: rn mv move)
79
77
 
80
- $ grb rename branch_name [origin_server]
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]
81
83
 
82
84
 
83
85
  === explain
@@ -88,7 +90,7 @@ run to accomplish that goal.
88
90
  Examples:
89
91
 
90
92
  $ grb explain create
91
- git_remote_branch version 0.2.7
93
+ git_remote_branch version 0.3.0
92
94
 
93
95
  List of operations to do to create a new remote branch and track it locally:
94
96
 
@@ -97,9 +99,10 @@ Examples:
97
99
  git branch --track branch_to_create origin/branch_to_create
98
100
  git checkout branch_to_create
99
101
 
102
+ Explain your specific case:
100
103
 
101
104
  $ grb explain create my_branch github
102
- git_remote_branch version 0.2.7
105
+ git_remote_branch version 0.3.0
103
106
 
104
107
  List of operations to do to create a new remote branch and track it locally:
105
108
 
@@ -108,7 +111,7 @@ Examples:
108
111
  git branch --track my_branch github/my_branch
109
112
  git checkout my_branch
110
113
 
111
-
114
+ This, of course, works for each of the grb commands.
112
115
 
113
116
  = More on git_remote_branch
114
117
 
@@ -121,10 +124,7 @@ Examples:
121
124
 
122
125
  == History
123
126
 
124
- git_remote_branch in its current form was inspired by a script created by Carl Mercier and made public on his blog
125
- here:
126
-
127
- {No nonsense GIT, part 1: git-remote-branch}[http://blog.carlmercier.com/2008/01/25/no-nonsense-git-part-1-git-remote-branch/]
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
128
 
129
129
 
130
130
  == Contributors
@@ -137,22 +137,48 @@ here:
137
137
 
138
138
  == Legalese
139
139
 
140
- git_remote_branch is licensed under the MIT License. See the file COPYING for details.
140
+ git_remote_branch is licensed under the MIT License. See the file LICENSE for details.
141
141
 
142
142
  == Bleeding edge and development
143
143
 
144
144
  (Notice the keyword "bleeding")
145
145
 
146
+ === Getting the bleeding edge
147
+
146
148
  Installing from GitHub
147
149
  sudo gem install webmat-git_remote_branch --source=http://gems.github.com
148
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
+
149
153
  Cloning the repo and installing from your copy
150
154
  git clone git://github.com/webmat/git_remote_branch.git
151
155
  rake install
152
156
 
157
+ === Testing dependencies
158
+
153
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.
154
160
 
155
161
  sudo gem install thoughtbot-shoulda --source http://gems.github.com
156
162
  sudo gem install mocha
157
163
 
158
- An attempt is made to require 2 more optional gems: redgreen and ruby-debug
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/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]
@@ -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
@@ -10,7 +10,7 @@ else
10
10
  end
11
11
 
12
12
  begin
13
- WINDOWS = (RUBY_PLATFORM =~ /win32|cygwin/)
13
+ WINDOWS = !!(RUBY_PLATFORM =~ /win32|cygwin/)
14
14
  rescue Exception
15
15
  end
16
16
 
@@ -20,6 +20,7 @@ $LOAD_PATH.unshift( grb_app_root + '/vendor' )
20
20
  require 'capture_fu'
21
21
 
22
22
  $LOAD_PATH.unshift( grb_app_root + '/lib' )
23
+ require 'constants'
23
24
  require 'string_ext'
24
25
  require 'state'
25
26
  require 'param_reader'
@@ -34,10 +35,10 @@ module GitRemoteBranch
34
35
  :description => 'create a new remote branch and track it locally',
35
36
  :aliases => %w{create new},
36
37
  :commands => [
37
- '"git push #{origin} #{current_branch}:refs/heads/#{branch_name}"',
38
- '"git fetch #{origin}"',
39
- '"git branch --track #{branch_name} #{origin}/#{branch_name}"',
40
- '"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}"'
41
42
  ]
42
43
  },
43
44
 
@@ -45,11 +46,11 @@ module GitRemoteBranch
45
46
  :description => 'publish an exiting local branch',
46
47
  :aliases => %w{publish remotize share},
47
48
  :commands => [
48
- '"git push #{origin} #{branch_name}:refs/heads/#{branch_name}"',
49
- '"git fetch #{origin}"',
50
- '"git config branch.#{branch_name}.remote #{origin}"',
51
- '"git config branch.#{branch_name}.merge refs/heads/#{branch_name}"',
52
- '"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}"'
53
54
  ]
54
55
  },
55
56
 
@@ -57,12 +58,12 @@ module GitRemoteBranch
57
58
  :description => 'rename a remote branch and its local tracking branch',
58
59
  :aliases => %w{rename rn mv move},
59
60
  :commands => [
60
- '"git push #{origin} #{current_branch}:refs/heads/#{branch_name}"',
61
- '"git fetch #{origin}"',
62
- '"git branch --track #{branch_name} #{origin}/#{branch_name}"',
63
- '"git checkout #{branch_name}"',
64
- '"git push #{origin} :refs/heads/#{current_branch}"',
65
- '"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}"',
66
67
  ]
67
68
  },
68
69
 
@@ -70,9 +71,9 @@ module GitRemoteBranch
70
71
  :description => 'delete a local and a remote branch',
71
72
  :aliases => %w{delete destroy kill remove rm},
72
73
  :commands => [
73
- '"git push #{origin} :refs/heads/#{branch_name}"',
74
- '"git checkout master" if current_branch == branch_name',
75
- '"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}"'
76
77
  ]
77
78
  },
78
79
 
@@ -81,12 +82,12 @@ module GitRemoteBranch
81
82
  :aliases => %w{track follow grab fetch},
82
83
  :commands => [
83
84
  # This string programming thing is getting old. Not flexible enough anymore.
84
- '"git fetch #{origin}"',
85
+ '"#{GIT} fetch #{origin}"',
85
86
  'if local_branches.include?(branch_name)
86
- "git config branch.#{branch_name}.remote #{origin}\n" +
87
- "git config branch.#{branch_name}.merge refs/heads/#{branch_name}"
87
+ "#{GIT} config branch.#{branch_name}.remote #{origin}\n" +
88
+ "#{GIT} config branch.#{branch_name}.merge refs/heads/#{branch_name}"
88
89
  else
89
- "git branch --track #{branch_name} #{origin}/#{branch_name}"
90
+ "#{GIT} branch --track #{branch_name} #{origin}/#{branch_name}"
90
91
  end'
91
92
  ]
92
93
  }
@@ -1,9 +1,6 @@
1
1
  module GitRemoteBranch
2
2
  include ::CaptureFu
3
3
 
4
- private
5
- LOCAL_BRANCH_LISTING_COMMAND = 'git branch -l'.freeze
6
-
7
4
  public
8
5
  def get_current_branch
9
6
  local_branch_information[0]
@@ -13,6 +10,11 @@ module GitRemoteBranch
13
10
  local_branch_information[1]
14
11
  end
15
12
 
13
+ def git_found?
14
+ ret, msg = capture_process_output "#{GIT} --version"
15
+ ret == 0
16
+ end
17
+
16
18
  private
17
19
  # Returns an array of 2 elements: [current_branch, [all local branches]]
18
20
  def local_branch_information
@@ -1,8 +1,8 @@
1
1
  module GitRemoteBranch
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 2
5
- TINY = 7
4
+ MINOR = 3
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.').freeze
8
8
  end
@@ -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
@@ -128,6 +128,18 @@ class GRBTest < Test::Unit::TestCase
128
128
  end
129
129
 
130
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
+
131
143
  context "displaying help" do
132
144
  setup do
133
145
  @text = run_grb_with 'help'
@@ -8,6 +8,7 @@ require File.dirname(__FILE__) + '/temp_dir_helper'
8
8
  # remote, local1 and local2.
9
9
  class GitHelper < TempDirHelper
10
10
  include InDir
11
+ GIT = GitRemoteBranch::GIT
11
12
 
12
13
  attr_reader :remote, :local1, :local2
13
14
 
@@ -24,7 +25,7 @@ class GitHelper < TempDirHelper
24
25
  mkdir_p repo_dir
25
26
 
26
27
  in_dir repo_dir do
27
- `git init && echo "foo" > file.txt && git add . && git commit -a -m "dummy file"`
28
+ `#{GIT} init && echo "foo" > file.txt && #{GIT} add . && #{GIT} commit -a -m "dummy file"`
28
29
  end
29
30
  raise "Error setting up repository #{name}" unless $?.exitstatus == 0
30
31
  repo_dir
@@ -32,7 +33,7 @@ class GitHelper < TempDirHelper
32
33
 
33
34
  def clone_repo(origin_path, clone_path, name)
34
35
  in_dir clone_path do
35
- `git clone #{File.join(origin_path, '.git').path_for_os} #{name}`
36
+ `#{GIT} clone #{File.join(origin_path, '.git').path_for_os} #{name}`
36
37
  end
37
38
  return File.join(clone_path, name)
38
39
  end
@@ -2,6 +2,8 @@ module ShouldaFunctionalHelpers
2
2
  include CaptureFu
3
3
  include InDir
4
4
 
5
+ GIT = GitRemoteBranch::GIT
6
+
5
7
  def self.ruby_prefix
6
8
  if ENV['RUBY']
7
9
  warn " Forcing execution of grb with ruby interpreter #{ENV['RUBY']}"
@@ -44,7 +46,7 @@ module ShouldaFunctionalHelpers
44
46
  end
45
47
 
46
48
  def in_branch(branch)
47
- execute "git checkout #{branch}"
49
+ execute "#{GIT} checkout #{branch}"
48
50
  end
49
51
 
50
52
 
@@ -77,7 +79,7 @@ module ShouldaFunctionalHelpers
77
79
  wheres.flatten.each do |where|
78
80
  should "have the branch '#{what_branch}' #{where == :local ? 'locally' : 'remotely'}" do
79
81
  args = get_branch_location(where)
80
- assert_match(/#{what_branch}/, execute("git branch #{args}"))
82
+ assert_match(/#{what_branch}/, execute("#{GIT} branch #{args}"))
81
83
  end
82
84
  end
83
85
  end
@@ -86,7 +88,7 @@ module ShouldaFunctionalHelpers
86
88
  wheres.flatten.each do |where|
87
89
  should "not have the branch '#{what_branch}' #{where == :local ? 'locally' : 'remotely'}" do
88
90
  args = get_branch_location(where)
89
- assert_no_match(/#{what_branch}/, execute("git branch #{args}"))
91
+ assert_no_match(/#{what_branch}/, execute("#{GIT} branch #{args}"))
90
92
  end
91
93
  end
92
94
  end
@@ -101,7 +103,9 @@ module ShouldaFunctionalHelpers
101
103
  @gh.cleanup
102
104
  end
103
105
 
104
- yield
106
+ context '' do
107
+ yield
108
+ end
105
109
  end
106
110
  end
107
111
 
@@ -116,7 +120,32 @@ module ShouldaFunctionalHelpers
116
120
  @temp_dir.cleanup
117
121
  end
118
122
 
119
- 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
120
149
  end
121
150
  end
122
151
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webmat-git_remote_branch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.7
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-11-11 21:00:00 -08:00
13
+ date: 2008-11-13 21:00:00 -08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -35,13 +35,14 @@ 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
42
  - lib/state.rb
43
43
  - lib/string_ext.rb
44
44
  - lib/version.rb
45
+ - LICENSE
45
46
  - Rakefile
46
47
  - README.rdoc
47
48
  - tasks