webmat-git_remote_branch 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +158 -0
- data/Rakefile +9 -4
- data/lib/git_remote_branch.rb +24 -4
- data/lib/param_reader.rb +0 -21
- data/lib/state.rb +40 -0
- data/lib/string_ext.rb +5 -0
- data/lib/version.rb +1 -1
- data/tasks/gem.rake +29 -14
- data/tasks/rdoc.rake +15 -0
- data/tasks/test.rake +1 -4
- data/test/functional/grb_test.rb +25 -3
- data/test/helpers/constants.rb +15 -0
- data/test/helpers/git_helper.rb +13 -7
- data/test/helpers/in_dir.rb +10 -0
- data/test/helpers/shoulda_functional_helpers.rb +20 -3
- data/test/helpers/temp_dir_helper.rb +6 -6
- data/test/test_helper.rb +16 -8
- data/test/unit/param_reader_test.rb +1 -47
- data/test/unit/state_test.rb +56 -0
- metadata +20 -11
- data/README +0 -140
- data/TODO +0 -16
- data/test/helpers/dir_stack.rb +0 -25
data/README.rdoc
ADDED
@@ -0,0 +1,158 @@
|
|
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 git_remote_branch
|
17
|
+
|
18
|
+
If you have an older version of Rubygems (older than 1.2), you will have to manually install the "colored" gem.
|
19
|
+
sudo gem install colored
|
20
|
+
|
21
|
+
If you're on Windows, you must install "colored" and "win32console" manually (before or after installing git_remote_branch doesn't matter).
|
22
|
+
gem install win32console colored
|
23
|
+
|
24
|
+
|
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.
|
26
|
+
|
27
|
+
= Usage
|
28
|
+
|
29
|
+
Notes:
|
30
|
+
- parts between brackets are optional
|
31
|
+
- When 'origin_server' is not specified, the name 'origin' is assumed.
|
32
|
+
|
33
|
+
Available commands (with aliases):
|
34
|
+
|
35
|
+
|
36
|
+
=== Help
|
37
|
+
|
38
|
+
$ grb [-h|help] #=> Displays help
|
39
|
+
|
40
|
+
=== create (alias: new)
|
41
|
+
|
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
|
+
|
47
|
+
$ grb create branch_name [origin_server]
|
48
|
+
|
49
|
+
|
50
|
+
=== publish (aliases: remotize)
|
51
|
+
|
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
|
+
|
61
|
+
Delete the remote branch then delete the local branch.
|
62
|
+
The local branch is not deleted if there are pending changes.
|
63
|
+
|
64
|
+
$ grb delete branch_name [origin_server]
|
65
|
+
|
66
|
+
|
67
|
+
=== track (aliases: follow grab fetch)
|
68
|
+
|
69
|
+
Track an existing remote branch locally.
|
70
|
+
|
71
|
+
$ grb track branch_name [origin_server]
|
72
|
+
|
73
|
+
|
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.
|
79
|
+
|
80
|
+
$ grb rename branch_name [origin_server]
|
81
|
+
|
82
|
+
|
83
|
+
=== explain
|
84
|
+
|
85
|
+
All commands can be prepended by the word 'explain'. Instead of executing the
|
86
|
+
command, git_remote_branch will simply output the list of commands you need to
|
87
|
+
run to accomplish that goal.
|
88
|
+
Examples:
|
89
|
+
|
90
|
+
$ grb explain create
|
91
|
+
git_remote_branch version 0.2.7
|
92
|
+
|
93
|
+
List of operations to do to create a new remote branch and track it locally:
|
94
|
+
|
95
|
+
git push origin master:refs/heads/branch_to_create
|
96
|
+
git fetch origin
|
97
|
+
git branch --track branch_to_create origin/branch_to_create
|
98
|
+
git checkout branch_to_create
|
99
|
+
|
100
|
+
|
101
|
+
$ grb explain create my_branch github
|
102
|
+
git_remote_branch version 0.2.7
|
103
|
+
|
104
|
+
List of operations to do to create a new remote branch and track it locally:
|
105
|
+
|
106
|
+
git push github master:refs/heads/my_branch
|
107
|
+
git fetch github
|
108
|
+
git branch --track my_branch github/my_branch
|
109
|
+
git checkout my_branch
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
= More on git_remote_branch
|
114
|
+
|
115
|
+
- Documentation: http://grb.rubyforge.org
|
116
|
+
- News: http://programblings.com/category/git/git_remote_branch/
|
117
|
+
- Bug tracker: http://git-remote-branch.lighthouseapp.com/projects/19198-git_remote_branch/overview
|
118
|
+
- Code: http://github.com/webmat/git_remote_branch
|
119
|
+
- Mailing list: http://groups.google.com/group/git_remote_branch
|
120
|
+
|
121
|
+
|
122
|
+
== History
|
123
|
+
|
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/]
|
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 COPYING for details.
|
141
|
+
|
142
|
+
== Bleeding edge and development
|
143
|
+
|
144
|
+
(Notice the keyword "bleeding")
|
145
|
+
|
146
|
+
Installing from GitHub
|
147
|
+
sudo gem install webmat-git_remote_branch --source=http://gems.github.com
|
148
|
+
|
149
|
+
Cloning the repo and installing from your copy
|
150
|
+
git clone git://github.com/webmat/git_remote_branch.git
|
151
|
+
rake install
|
152
|
+
|
153
|
+
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
|
+
|
155
|
+
sudo gem install thoughtbot-shoulda --source http://gems.github.com
|
156
|
+
sudo gem install mocha
|
157
|
+
|
158
|
+
An attempt is made to require 2 more optional gems: redgreen and ruby-debug
|
data/Rakefile
CHANGED
@@ -2,11 +2,16 @@ require 'rubygems'
|
|
2
2
|
|
3
3
|
require 'rake'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
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/lib/git_remote_branch.rb
CHANGED
@@ -1,5 +1,18 @@
|
|
1
1
|
require 'rubygems'
|
2
|
-
|
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,8 @@ $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 'string_ext'
|
24
|
+
require 'state'
|
10
25
|
require 'param_reader'
|
11
26
|
require 'version'
|
12
27
|
|
@@ -28,7 +43,7 @@ module GitRemoteBranch
|
|
28
43
|
|
29
44
|
:publish => {
|
30
45
|
:description => 'publish an exiting local branch',
|
31
|
-
:aliases => %w{publish remotize},
|
46
|
+
:aliases => %w{publish remotize share},
|
32
47
|
:commands => [
|
33
48
|
'"git push #{origin} #{branch_name}:refs/heads/#{branch_name}"',
|
34
49
|
'"git fetch #{origin}"',
|
@@ -65,9 +80,14 @@ module GitRemoteBranch
|
|
65
80
|
:description => 'track an existing remote branch',
|
66
81
|
:aliases => %w{track follow grab fetch},
|
67
82
|
:commands => [
|
83
|
+
# This string programming thing is getting old. Not flexible enough anymore.
|
68
84
|
'"git fetch #{origin}"',
|
69
|
-
'
|
70
|
-
|
85
|
+
'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}"
|
88
|
+
else
|
89
|
+
"git branch --track #{branch_name} #{origin}/#{branch_name}"
|
90
|
+
end'
|
71
91
|
]
|
72
92
|
}
|
73
93
|
} 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,40 @@
|
|
1
|
+
module GitRemoteBranch
|
2
|
+
include ::CaptureFu
|
3
|
+
|
4
|
+
private
|
5
|
+
LOCAL_BRANCH_LISTING_COMMAND = 'git branch -l'.freeze
|
6
|
+
|
7
|
+
public
|
8
|
+
def get_current_branch
|
9
|
+
local_branch_information[0]
|
10
|
+
end
|
11
|
+
|
12
|
+
def local_branches
|
13
|
+
local_branch_information[1]
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
# Returns an array of 2 elements: [current_branch, [all local branches]]
|
18
|
+
def local_branch_information
|
19
|
+
#This is sensitive to checkouts of branches specified with wrong case
|
20
|
+
|
21
|
+
listing = capture_process_output("#{LOCAL_BRANCH_LISTING_COMMAND}")[1]
|
22
|
+
|
23
|
+
raise(NotOnGitRepositoryError, listing.chomp) if listing =~ /Not a git repository/i
|
24
|
+
if listing =~ /\(no branch\)/
|
25
|
+
raise InvalidBranchError, ["Couldn't identify the current local branch. The branch listing was:",
|
26
|
+
LOCAL_BRANCH_LISTING_COMMAND.red,
|
27
|
+
listing].join("\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
current_branch = nil
|
31
|
+
branches = listing.split("\n").map do |line|
|
32
|
+
current = line.include? '*'
|
33
|
+
clean_line = line.gsub('*','').strip
|
34
|
+
current_branch = clean_line if current
|
35
|
+
clean_line
|
36
|
+
end
|
37
|
+
|
38
|
+
return current_branch, branches
|
39
|
+
end
|
40
|
+
end
|
data/lib/string_ext.rb
ADDED
data/lib/version.rb
CHANGED
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 =
|
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 '
|
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
|
-
|
66
|
-
|
67
|
-
task :install => [:clean, :gem] do
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
|
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
data/test/functional/grb_test.rb
CHANGED
@@ -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
|
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
|
-
|
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
|
@@ -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
|
+
|
data/test/helpers/git_helper.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
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,12 @@ 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
|
+
|
12
12
|
attr_reader :remote, :local1, :local2
|
13
13
|
|
14
14
|
def initialize
|
15
|
-
super(
|
16
|
-
|
15
|
+
super("#{TEST_DIR}/test_runs")
|
17
16
|
@remote = init_repo(directory, 'remote')
|
18
17
|
@local1 = clone_repo(@remote, directory, 'local1')
|
19
18
|
@local2 = clone_repo(@remote, directory, 'local2')
|
@@ -22,12 +21,19 @@ class GitHelper < TempDirHelper
|
|
22
21
|
protected
|
23
22
|
def init_repo(path, name)
|
24
23
|
repo_dir = File.join(path, name)
|
25
|
-
|
24
|
+
mkdir_p repo_dir
|
25
|
+
|
26
|
+
in_dir repo_dir do
|
27
|
+
`git init && echo "foo" > file.txt && git add . && git commit -a -m "dummy file"`
|
28
|
+
end
|
29
|
+
raise "Error setting up repository #{name}" unless $?.exitstatus == 0
|
26
30
|
repo_dir
|
27
31
|
end
|
28
32
|
|
29
33
|
def clone_repo(origin_path, clone_path, name)
|
30
|
-
|
34
|
+
in_dir clone_path do
|
35
|
+
`git clone #{File.join(origin_path, '.git').path_for_os} #{name}`
|
36
|
+
end
|
31
37
|
return File.join(clone_path, name)
|
32
38
|
end
|
33
39
|
end
|
@@ -1,6 +1,21 @@
|
|
1
1
|
module ShouldaFunctionalHelpers
|
2
2
|
include CaptureFu
|
3
|
-
|
3
|
+
include InDir
|
4
|
+
|
5
|
+
def self.ruby_prefix
|
6
|
+
if ENV['RUBY']
|
7
|
+
warn " Forcing execution of grb with ruby interpreter #{ENV['RUBY']}"
|
8
|
+
ENV['RUBY'] + ' '
|
9
|
+
elsif WINDOWS
|
10
|
+
'ruby '
|
11
|
+
else
|
12
|
+
''
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# Here we're only prepending with 'ruby'.
|
17
|
+
# When run as a gem, RubyGems takes care of generating a batch file that does this stuff.
|
18
|
+
GRB_COMMAND = ruby_prefix + File.expand_path(File.dirname(__FILE__) + '/../../bin/grb') unless defined?(GRB_COMMAND)
|
4
19
|
|
5
20
|
def self.included(base)
|
6
21
|
base.extend ClassMethods
|
@@ -38,8 +53,10 @@ module ShouldaFunctionalHelpers
|
|
38
53
|
end
|
39
54
|
|
40
55
|
def execute(command)
|
41
|
-
|
42
|
-
|
56
|
+
in_dir current_dir do
|
57
|
+
errno, returned_string = capture_process_output(command)
|
58
|
+
returned_string
|
59
|
+
end
|
43
60
|
end
|
44
61
|
|
45
62
|
private
|
@@ -6,8 +6,8 @@ class TempDirHelper
|
|
6
6
|
|
7
7
|
attr_reader :directory
|
8
8
|
|
9
|
-
def initialize(
|
10
|
-
@directory = get_temp_dir!(
|
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!(
|
23
|
-
|
24
|
-
|
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(
|
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
|
-
|
4
|
+
TEST_DIR = File.dirname(__FILE__)
|
5
5
|
|
6
|
-
# Install the
|
7
|
-
#
|
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
|
-
|
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( [
|
24
|
+
require File.join( [TEST_DIR] + %w{ .. lib git_remote_branch} )
|
18
25
|
|
19
|
-
|
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: webmat-git_remote_branch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
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-
|
13
|
+
date: 2008-11-11 21:00:00 -08:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -29,8 +29,8 @@ 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
|
@@ -39,20 +39,24 @@ files:
|
|
39
39
|
- lib
|
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
|
43
45
|
- Rakefile
|
44
|
-
- README
|
46
|
+
- README.rdoc
|
45
47
|
- tasks
|
46
48
|
- tasks/gem.rake
|
49
|
+
- tasks/rdoc.rake
|
47
50
|
- tasks/test.rake
|
48
51
|
- test
|
49
52
|
- test/functional
|
50
53
|
- test/functional/grb_test.rb
|
51
54
|
- test/helpers
|
52
55
|
- test/helpers/array_extensions.rb
|
53
|
-
- test/helpers/
|
56
|
+
- test/helpers/constants.rb
|
54
57
|
- test/helpers/extractable.rb
|
55
58
|
- test/helpers/git_helper.rb
|
59
|
+
- test/helpers/in_dir.rb
|
56
60
|
- test/helpers/more_assertions.rb
|
57
61
|
- test/helpers/shoulda_functional_helpers.rb
|
58
62
|
- test/helpers/shoulda_unit_helpers.rb
|
@@ -62,14 +66,17 @@ files:
|
|
62
66
|
- test/unit/git_helper_test.rb
|
63
67
|
- test/unit/git_remote_branch_test.rb
|
64
68
|
- test/unit/param_reader_test.rb
|
65
|
-
-
|
69
|
+
- test/unit/state_test.rb
|
66
70
|
- vendor
|
67
71
|
- vendor/capture_fu.rb
|
68
|
-
has_rdoc:
|
72
|
+
has_rdoc: true
|
69
73
|
homepage: http://github.com/webmat/git_remote_branch
|
70
74
|
post_install_message:
|
71
|
-
rdoc_options:
|
72
|
-
|
75
|
+
rdoc_options:
|
76
|
+
- --main
|
77
|
+
- README.rdoc
|
78
|
+
- --exclude
|
79
|
+
- lib
|
73
80
|
require_paths:
|
74
81
|
- lib
|
75
82
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -96,9 +103,10 @@ test_files:
|
|
96
103
|
- test/functional/grb_test.rb
|
97
104
|
- test/helpers
|
98
105
|
- test/helpers/array_extensions.rb
|
99
|
-
- test/helpers/
|
106
|
+
- test/helpers/constants.rb
|
100
107
|
- test/helpers/extractable.rb
|
101
108
|
- test/helpers/git_helper.rb
|
109
|
+
- test/helpers/in_dir.rb
|
102
110
|
- test/helpers/more_assertions.rb
|
103
111
|
- test/helpers/shoulda_functional_helpers.rb
|
104
112
|
- test/helpers/shoulda_unit_helpers.rb
|
@@ -108,3 +116,4 @@ test_files:
|
|
108
116
|
- test/unit/git_helper_test.rb
|
109
117
|
- test/unit/git_remote_branch_test.rb
|
110
118
|
- test/unit/param_reader_test.rb
|
119
|
+
- 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
|
-
|
data/test/helpers/dir_stack.rb
DELETED
@@ -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
|