kch-git_remote_branch 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,32 @@
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
+
16
+ * Release 0.2.6 *
17
+ Three new actual features
18
+ - grb rename, contributed by Caio Chassot (caiochassot.com)
19
+ - grb publish, to make available and track a local branch
20
+ - the --silent option, if you want to use grb in a script
21
+
22
+ And other stuff
23
+ - the grb bin file now works when symlinked (also thanks to Caio Chassot)
24
+ - Lots and lots of unit and functional tests
25
+ - bug fixes
26
+ - more flexibility for running grb outside of a git repository (e.g. for 'explain' or 'help')
27
+ - Now officially under the MIT license
28
+ - refactored a bunch of rake tasks
29
+
30
+
31
+ Versions lost in time:
32
+ 0.2.1, 0.2.2, 0.2.3, 0.2.4
data/LICENSE ADDED
@@ -0,0 +1,18 @@
1
+ Copyright (c) 2008 Mathieu Martin
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to
5
+ deal in the Software without restriction, including without limitation the
6
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7
+ sell copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
17
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -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
+ It 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 is that 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 git_remote_branch, 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
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+
3
+ require 'rake'
4
+
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"
11
+
12
+ Dir['tasks/**/*.rake'].each { |rake| load rake }
13
+
14
+ desc 'Default: run all tests.'
15
+ task :default => :test
16
+
17
+ task :clean => [:clobber_package, :clobber_rdoc]
data/bin/grb ADDED
@@ -0,0 +1,44 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Check out the README (or try 'grb help') before you screw up your repos ;-)
4
+
5
+ THIS_FILE = File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__
6
+ require "#{File.dirname(THIS_FILE)}/../lib/git_remote_branch"
7
+
8
+ include GitRemoteBranch
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
+
24
+ begin
25
+ p = read_params(ARGV)
26
+ rescue InvalidBranchError => ex
27
+ crap_out ex.message
28
+ end
29
+
30
+ $WHISPER = p[:silent]
31
+
32
+ whisper get_welcome
33
+
34
+ if p[:action] == :help
35
+ whisper get_usage
36
+ exit 0
37
+ end
38
+
39
+ if p[:explain]
40
+ explain_action(p[:action], p[:branch], p[:origin], p[:current_branch])
41
+ else
42
+ execute_action(p[:action], p[:branch], p[:origin], p[:current_branch])
43
+ end
44
+
@@ -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
@@ -0,0 +1,164 @@
1
+ require 'rubygems'
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
16
+
17
+ grb_app_root = File.expand_path( File.dirname(__FILE__) + '/..' )
18
+
19
+ $LOAD_PATH.unshift( grb_app_root + '/vendor' )
20
+ require 'capture_fu'
21
+
22
+ $LOAD_PATH.unshift( grb_app_root + '/lib' )
23
+ %w(monkey_patches constants state param_reader version).each do |f|
24
+ require f
25
+ end
26
+
27
+ module GitRemoteBranch
28
+ class InvalidBranchError < RuntimeError; end
29
+ class NotOnGitRepositoryError < RuntimeError; end
30
+
31
+ COMMANDS = {
32
+ :create => {
33
+ :description => 'create a new remote branch and track it locally',
34
+ :aliases => %w{create new},
35
+ :commands => [
36
+ '"#{GIT} push #{origin} #{current_branch}:refs/heads/#{branch_name}"',
37
+ '"#{GIT} fetch #{origin}"',
38
+ '"#{GIT} branch --track #{branch_name} #{origin}/#{branch_name}"',
39
+ '"#{GIT} checkout #{branch_name}"'
40
+ ]
41
+ },
42
+
43
+ :publish => {
44
+ :description => 'publish an exiting local branch',
45
+ :aliases => %w{publish remotize share},
46
+ :commands => [
47
+ '"#{GIT} push #{origin} #{branch_name}:refs/heads/#{branch_name}"',
48
+ '"#{GIT} fetch #{origin}"',
49
+ '"#{GIT} config branch.#{branch_name}.remote #{origin}"',
50
+ '"#{GIT} config branch.#{branch_name}.merge refs/heads/#{branch_name}"',
51
+ '"#{GIT} checkout #{branch_name}"'
52
+ ]
53
+ },
54
+
55
+ :rename => {
56
+ :description => 'rename a remote branch and its local tracking branch',
57
+ :aliases => %w{rename rn mv move},
58
+ :commands => [
59
+ '"#{GIT} push #{origin} #{current_branch}:refs/heads/#{branch_name}"',
60
+ '"#{GIT} fetch #{origin}"',
61
+ '"#{GIT} branch --track #{branch_name} #{origin}/#{branch_name}"',
62
+ '"#{GIT} checkout #{branch_name}"',
63
+ '"#{GIT} push #{origin} :refs/heads/#{current_branch}"',
64
+ '"#{GIT} branch -d #{current_branch}"',
65
+ ]
66
+ },
67
+
68
+ :delete => {
69
+ :description => 'delete a local and a remote branch',
70
+ :aliases => %w{delete destroy kill remove rm},
71
+ :commands => [
72
+ '"#{GIT} push #{origin} :refs/heads/#{branch_name}"',
73
+ '"#{GIT} checkout master" if current_branch == branch_name',
74
+ '"#{GIT} branch -d #{branch_name}"'
75
+ ]
76
+ },
77
+
78
+ :track => {
79
+ :description => 'track an existing remote branch',
80
+ :aliases => %w{track follow grab fetch},
81
+ :commands => [
82
+ # This string programming thing is getting old. Not flexible enough anymore.
83
+ '"#{GIT} fetch #{origin}"',
84
+ 'if local_branches.include?(branch_name)
85
+ "#{GIT} config branch.#{branch_name}.remote #{origin}\n" +
86
+ "#{GIT} config branch.#{branch_name}.merge refs/heads/#{branch_name}"
87
+ else
88
+ "#{GIT} branch --track #{branch_name} #{origin}/#{branch_name}"
89
+ end'
90
+ ]
91
+ }
92
+ } unless defined?(COMMANDS)
93
+
94
+ def self.get_reverse_map(commands)
95
+ h={}
96
+ commands.each_pair do |cmd, params|
97
+ params[:aliases].each do |alias_|
98
+ unless h[alias_]
99
+ h[alias_] = cmd
100
+ else
101
+ raise "Duplicate aliases: #{alias_.inspect} already defined for command #{h[alias_].inspect}"
102
+ end
103
+ end
104
+ end
105
+ h
106
+ end
107
+ ALIAS_REVERSE_MAP = get_reverse_map(COMMANDS) unless defined?(ALIAS_REVERSE_MAP)
108
+
109
+ def get_welcome
110
+ "git_remote_branch version #{VERSION::STRING}\n\n"
111
+ end
112
+
113
+ def get_usage
114
+ return <<-HELP
115
+ Usage:
116
+
117
+ #{[:create, :publish, :rename, :delete, :track].map{|action|
118
+ " grb #{action} branch_name [origin_server] \n\n"
119
+ }
120
+ }
121
+
122
+ Notes:
123
+ - If origin_server is not specified, the name 'origin' is assumed (git's default)
124
+ - The rename functionality renames the current branch
125
+
126
+ The explain meta-command: you can also prepend any command with the keyword 'explain'. Instead of executing the command, git_remote_branch will simply output the list of commands you need to run to accomplish that goal.
127
+ Example:
128
+ grb explain create
129
+ grb explain create my_branch github
130
+
131
+ All commands also have aliases:
132
+ #{ COMMANDS.keys.map{|k| k.to_s}.sort.map {|cmd|
133
+ "#{cmd}: #{COMMANDS[cmd.to_sym][:aliases].join(', ')}" }.join("\n ") }
134
+ HELP
135
+ end
136
+
137
+ def execute_action(action, branch_name, origin, current_branch)
138
+ cmds = COMMANDS[action][:commands].map{ |c| eval(c) }.compact
139
+ execute_cmds(cmds)
140
+ end
141
+
142
+ def explain_action(action, branch_name, origin, current_branch)
143
+ cmds = COMMANDS[action][:commands].map{ |c| eval(c) }.compact
144
+
145
+ whisper "List of operations to do to #{COMMANDS[action][:description]}:", ''
146
+ puts_cmd cmds
147
+ whisper ''
148
+ end
149
+
150
+ def execute_cmds(*cmds)
151
+ silencer = $WHISPER ? ' 2>&1' : ''
152
+ cmds.flatten.each do |c|
153
+ puts_cmd c
154
+ `#{c}#{silencer}`
155
+ whisper ''
156
+ end
157
+ end
158
+
159
+ def puts_cmd(*cmds)
160
+ cmds.flatten.each do |c|
161
+ whisper "#{c}".red
162
+ end
163
+ end
164
+ end