mattgillooly-grb 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Contributors +2 -0
- data/Gemfile +4 -0
- data/README.rdoc +30 -0
- data/Rakefile +1 -0
- data/bin/grb +25 -0
- data/grb.gemspec +22 -0
- data/lib/grb.rb +145 -0
- data/lib/grb/version.rb +3 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ccd31ce22f8cf8cdfb91b5645e7bbbf7d717f728
|
4
|
+
data.tar.gz: 8c2dac1f192b190cbe73ec8056f58c528be23927
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c7729ee41105d0e7a4d8bbdd4f9a364445df27ad1cc15e98e21ec286bd7a1b497593c229f88690fe8fe46f519c38046f1b92b5110b3accdade9ef8d6931371a
|
7
|
+
data.tar.gz: 98607dc56a09533916a7e81a1d6d35896a24effe337cc92ec6344b5d65aa9af2da511f964a603af1b5fcf176e52c937403a6bf59aa2409970b052af7e6d68c89
|
data/.gitignore
ADDED
data/Contributors
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
= GRB
|
2
|
+
A tool to simplify working with remote branches.
|
3
|
+
|
4
|
+
== Install:
|
5
|
+
$ sudo gem install grb
|
6
|
+
|
7
|
+
== USAGE:
|
8
|
+
* rename `branch1` to `branch2`
|
9
|
+
$ grb mv [branch1] [branch2] [--explain]
|
10
|
+
* rename current branch to `branch`
|
11
|
+
$ grb mv branch [--explain]
|
12
|
+
* add a remote repo
|
13
|
+
$ grb remote_add `name` `repo path` [--explain]
|
14
|
+
* remove a remote repo
|
15
|
+
$ grb remote_rm `name` [--explain]
|
16
|
+
* delete branch `branch`,default current_branch
|
17
|
+
$ grb rm [branch] [--explain]
|
18
|
+
* pull branch `branch`,default current_branch
|
19
|
+
$ grb pull [branch] [--explain]
|
20
|
+
* push branch `branch`, default current_branch
|
21
|
+
$ grb push [branch] [--explain]
|
22
|
+
* create new branch `branch`
|
23
|
+
$ grb new [branch] [--explain]
|
24
|
+
* prune dead remote branches
|
25
|
+
$ grb prune
|
26
|
+
|
27
|
+
Copyright (c) 2009-present MIT
|
28
|
+
|
29
|
+
Author : Jinzhu Zhang
|
30
|
+
Email : wosmvp@gmail.com
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/grb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009-present. MIT.
|
4
|
+
# Author: Zhang Jinzhu
|
5
|
+
|
6
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/grb")
|
7
|
+
|
8
|
+
# easy debugger
|
9
|
+
if ARGV.delete('--debug')
|
10
|
+
['rubygems','ruby-debug'].each {|x| require x}
|
11
|
+
else
|
12
|
+
def debugger;end
|
13
|
+
end
|
14
|
+
|
15
|
+
abort('Version: ' + Grb::VERSION) if ARGV.delete('--version') || ARGV.delete('-v')
|
16
|
+
|
17
|
+
EXPLAIN = ARGV.delete('--explain') || ARGV.delete('-e')
|
18
|
+
|
19
|
+
opt = {
|
20
|
+
:command => ARGV[0] || 'push',
|
21
|
+
:branch => branch = (ARGV[1] || Grb.get_current_branch),
|
22
|
+
:branch_ => ARGV[2] || branch,
|
23
|
+
}
|
24
|
+
|
25
|
+
Grb.parse(opt)
|
data/grb.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'grb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mattgillooly-grb"
|
8
|
+
spec.version = Grb::VERSION
|
9
|
+
spec.authors = ["Jinzhu Zhang"]
|
10
|
+
spec.email = ["wosmvp@gmail.com"]
|
11
|
+
spec.summary = %{A tool to simplify working with remote branches}
|
12
|
+
spec.description = %{A tool to simplify working with remote branches}
|
13
|
+
spec.homepage = "http://github.com/jinzhu/grb"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
21
|
+
spec.add_development_dependency "rake"
|
22
|
+
end
|
data/lib/grb.rb
ADDED
@@ -0,0 +1,145 @@
|
|
1
|
+
require "grb/version"
|
2
|
+
|
3
|
+
class Grb
|
4
|
+
GIT = ENV['GRB_GIT'] || 'git'
|
5
|
+
ORIGIN = ENV['GRB_ORIGIN'] || 'origin'
|
6
|
+
|
7
|
+
COMMANDS = {
|
8
|
+
:new => {
|
9
|
+
:desc => "=> create new branch `branch`\ngrb new [branch] [--explain]",
|
10
|
+
:commands => [
|
11
|
+
'"#{GIT} push #{origin} #{current_branch}:refs/heads/#{branch}"',
|
12
|
+
'"#{GIT} fetch #{origin}"',
|
13
|
+
'"#{GIT} branch --track #{branch} #{origin}/#{branch}"',
|
14
|
+
'"#{GIT} checkout #{branch}"'
|
15
|
+
]
|
16
|
+
},
|
17
|
+
|
18
|
+
:push => {
|
19
|
+
:desc => "=> push branch `branch`, default current_branch\ngrb push [branch] [--explain]",
|
20
|
+
:commands => [
|
21
|
+
'"#{GIT} push #{origin} #{branch}:refs/heads/#{branch}"',
|
22
|
+
'"#{GIT} fetch #{origin}"',
|
23
|
+
'"#{GIT} config branch.#{branch}.remote #{origin}"',
|
24
|
+
'"#{GIT} config branch.#{branch}.merge refs/heads/#{branch}"',
|
25
|
+
'"#{GIT} checkout #{branch}"'
|
26
|
+
]
|
27
|
+
},
|
28
|
+
|
29
|
+
:forcepush => {
|
30
|
+
:desc => "=> force push branch `branch`, default current_branch\ngrb forcepush [branch] [--explain]",
|
31
|
+
:commands => [
|
32
|
+
'"#{GIT} push #{origin} #{branch}:refs/heads/#{branch} --force"',
|
33
|
+
'"#{GIT} fetch #{origin}"',
|
34
|
+
'"#{GIT} config branch.#{branch}.remote #{origin}"',
|
35
|
+
'"#{GIT} config branch.#{branch}.merge refs/heads/#{branch}"',
|
36
|
+
'"#{GIT} checkout #{branch}"'
|
37
|
+
]
|
38
|
+
},
|
39
|
+
|
40
|
+
:mv => {
|
41
|
+
:desc => "=> rename `branch1` to `branch2`\ngrb mv [branch1] [branch2] [--explain]\n=> rename current branch to `branch`\ngrb mv branch [--explain]",
|
42
|
+
:commands => [
|
43
|
+
' if(branch != branch_)
|
44
|
+
"#{GIT} push #{origin} #{branch}:refs/heads/#{branch_}
|
45
|
+
#{GIT} fetch #{origin}
|
46
|
+
#{GIT} branch --track #{branch_} #{origin}/#{branch_}
|
47
|
+
#{GIT} checkout #{branch_}
|
48
|
+
#{GIT} branch -d #{branch}
|
49
|
+
#{GIT} push #{origin} :refs/heads/#{branch}"
|
50
|
+
else
|
51
|
+
"#{GIT} push #{origin} #{current_branch}:refs/heads/#{branch}
|
52
|
+
#{GIT} fetch #{origin}
|
53
|
+
#{GIT} branch --track #{branch} #{origin}/#{branch}
|
54
|
+
#{GIT} checkout #{branch}
|
55
|
+
#{GIT} push #{origin} :refs/heads/#{current_branch}
|
56
|
+
#{GIT} branch -d #{current_branch}"
|
57
|
+
end'
|
58
|
+
]
|
59
|
+
},
|
60
|
+
|
61
|
+
:rm => {
|
62
|
+
:desc => "=> delete branch `branch`,default current_branch\ngrb rm [branch] [--explain]",
|
63
|
+
:commands => [
|
64
|
+
'"#{GIT} push #{origin} :refs/heads/#{branch}"',
|
65
|
+
'"#{GIT} checkout master" if current_branch == branch',
|
66
|
+
'"#{GIT} branch -d #{branch}"'
|
67
|
+
]
|
68
|
+
},
|
69
|
+
|
70
|
+
:pull => {
|
71
|
+
:desc => "=> pull branch `branch`,default current_branch\ngrb pull [branch] [--explain]",
|
72
|
+
:commands => [
|
73
|
+
'"#{GIT} fetch #{origin}"',
|
74
|
+
'if local_branches.include?(branch)
|
75
|
+
"#{GIT} config branch.#{branch}.remote #{origin}\n" +
|
76
|
+
"#{GIT} config branch.#{branch}.merge refs/heads/#{branch}"
|
77
|
+
else
|
78
|
+
"#{GIT} branch --track #{branch} #{origin}/#{branch}"
|
79
|
+
end',
|
80
|
+
'"#{GIT} checkout #{branch}" if current_branch != branch',
|
81
|
+
'"#{GIT} rebase #{origin}/#{branch}"',
|
82
|
+
]
|
83
|
+
},
|
84
|
+
|
85
|
+
:track => {
|
86
|
+
:desc => "=> track branch\ngrb track `branch` [--explain]",
|
87
|
+
:commands => [
|
88
|
+
'"#{GIT} fetch #{origin}"',
|
89
|
+
'"#{GIT} branch --track #{branch} origin/#{branch}"',
|
90
|
+
'"#{GIT} checkout #{branch}"'
|
91
|
+
]
|
92
|
+
},
|
93
|
+
|
94
|
+
:remote_add => {
|
95
|
+
:desc => "=> add a remote repo\ngrb remote_add `name` `repo path` [--explain]",
|
96
|
+
:commands => [
|
97
|
+
'"#{GIT} remote add #{branch} #{branch_}"',
|
98
|
+
'"#{GIT} fetch #{branch}"'
|
99
|
+
]
|
100
|
+
},
|
101
|
+
|
102
|
+
:remote_rm => {
|
103
|
+
:desc => "=> remove a remote repo\ngrb remote_rm `name` [--explain]",
|
104
|
+
:commands => [
|
105
|
+
'"#{GIT} remote rm #{branch}"',
|
106
|
+
]
|
107
|
+
},
|
108
|
+
|
109
|
+
:prune => {
|
110
|
+
:desc => "=> prunes the remote branches from the list\ngrb prune",
|
111
|
+
:commands => [
|
112
|
+
'"#{GIT} remote prune #{origin}"',
|
113
|
+
]
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
def self.parse(opt)
|
118
|
+
if COMMANDS.keys.include?(opt[:command].to_sym)
|
119
|
+
current_branch,branch,branch_,origin = get_current_branch,opt[:branch],opt[:branch_],ORIGIN
|
120
|
+
|
121
|
+
COMMANDS[opt[:command].to_sym][:commands].map {|x| exec_cmd(eval(x))}
|
122
|
+
else
|
123
|
+
help
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.exec_cmd(str)
|
128
|
+
return true unless str
|
129
|
+
puts("\e[031m" + str.gsub(/^\s*/,'') + "\e[0m")
|
130
|
+
system("#{str}") unless EXPLAIN
|
131
|
+
end
|
132
|
+
|
133
|
+
def self.get_current_branch
|
134
|
+
(`#{GIT} branch 2> /dev/null | grep '^\*'`).gsub(/[\*\s]/,'')
|
135
|
+
end
|
136
|
+
|
137
|
+
def self.local_branches
|
138
|
+
(`#{GIT} branch -l`).split(/\n/).map{|x| x.gsub(/[\*\s]/,'')}
|
139
|
+
end
|
140
|
+
|
141
|
+
def self.help(*args)
|
142
|
+
puts "USAGE:"
|
143
|
+
COMMANDS.values.map {|x| puts x[:desc].gsub(/^(\W.*)$/,"\e[31m" + '\1' + "\e[0m").gsub(/^(\w.*)$/,' $ \1')}
|
144
|
+
end
|
145
|
+
end
|
data/lib/grb/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mattgillooly-grb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.4.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jinzhu Zhang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: A tool to simplify working with remote branches
|
42
|
+
email:
|
43
|
+
- wosmvp@gmail.com
|
44
|
+
executables:
|
45
|
+
- grb
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Contributors
|
51
|
+
- Gemfile
|
52
|
+
- README.rdoc
|
53
|
+
- Rakefile
|
54
|
+
- bin/grb
|
55
|
+
- grb.gemspec
|
56
|
+
- lib/grb.rb
|
57
|
+
- lib/grb/version.rb
|
58
|
+
homepage: http://github.com/jinzhu/grb
|
59
|
+
licenses: []
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.0.14
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: A tool to simplify working with remote branches
|
81
|
+
test_files: []
|