jinzhu-grb 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Manifest +5 -0
- data/Rakefile +14 -0
- data/bin/grb +24 -0
- data/grb.gemspec +33 -0
- data/lib/grb.rb +99 -0
- data/lib/version.rb +3 -0
- metadata +65 -0
data/Manifest
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'rake'
|
3
|
+
require 'echoe'
|
4
|
+
require File.dirname(__FILE__) + '/lib/version'
|
5
|
+
|
6
|
+
Echoe.new('grb', Version::VERSION) do |p|
|
7
|
+
p.description = "grb"
|
8
|
+
p.url = "http://www.zhangjinzhu.com"
|
9
|
+
p.author = "Jinzhu Zhang"
|
10
|
+
p.email = "wosmvp@gmail.com"
|
11
|
+
p.ignore_pattern = ["TODO"]
|
12
|
+
p.rubyforge_name = "grb"
|
13
|
+
end
|
14
|
+
|
data/bin/grb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Copyright (c) 2009. GPL3.
|
4
|
+
# Author: Zhang Jinzhu
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + "/../lib"))
|
7
|
+
|
8
|
+
# easy debug
|
9
|
+
if ARGV.delete('--debug')
|
10
|
+
['rubygems','ruby-debug'].each {|x| require x}
|
11
|
+
else
|
12
|
+
def debugger;end
|
13
|
+
end
|
14
|
+
|
15
|
+
require "version"
|
16
|
+
require "grb"
|
17
|
+
|
18
|
+
opt = {
|
19
|
+
:command => ARGV[0] || 'help',
|
20
|
+
:branch => branch = (ARGV[1] || Grb.get_current_branch),
|
21
|
+
:branch_ => ARGV[2] || branch,
|
22
|
+
}
|
23
|
+
|
24
|
+
Grb.parse(opt)
|
data/grb.gemspec
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{grb}
|
5
|
+
s.version = "0.0.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Jinzhu Zhang"]
|
9
|
+
s.date = %q{2009-07-09}
|
10
|
+
s.default_executable = %q{grb}
|
11
|
+
s.description = %q{grb}
|
12
|
+
s.email = %q{wosmvp@gmail.com}
|
13
|
+
s.executables = ["grb"]
|
14
|
+
s.extra_rdoc_files = ["bin/grb", "lib/version.rb", "lib/grb.rb"]
|
15
|
+
s.files = ["bin/grb", "Rakefile", "lib/version.rb", "lib/grb.rb", "Manifest", "grb.gemspec"]
|
16
|
+
s.has_rdoc = true
|
17
|
+
s.homepage = %q{http://www.zhangjinzhu.com}
|
18
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Grb", "--main", "README.rdoc"]
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
s.rubyforge_project = %q{grb}
|
21
|
+
s.rubygems_version = %q{1.3.1}
|
22
|
+
s.summary = %q{grb}
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
|
+
s.specification_version = 2
|
27
|
+
|
28
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
29
|
+
else
|
30
|
+
end
|
31
|
+
else
|
32
|
+
end
|
33
|
+
end
|
data/lib/grb.rb
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
class Grb
|
2
|
+
GIT = ENV['GRB_GIT'] || 'git'
|
3
|
+
ORIGIN = ENV['GRB_ORIGIN'] || 'origin'
|
4
|
+
|
5
|
+
COMMANDS = {
|
6
|
+
:new => {
|
7
|
+
:desc => "grb new [branch]",
|
8
|
+
:commands => [
|
9
|
+
'"#{GIT} push #{origin} #{current_branch}:refs/heads/#{branch}"',
|
10
|
+
'"#{GIT} fetch #{origin}"',
|
11
|
+
'"#{GIT} branch --track #{branch} #{origin}/#{branch}"',
|
12
|
+
'"#{GIT} checkout #{branch}"'
|
13
|
+
]
|
14
|
+
},
|
15
|
+
|
16
|
+
:push => {
|
17
|
+
:desc => "grb push [branch] (default current_branch)",
|
18
|
+
:commands => [
|
19
|
+
'"#{GIT} push #{origin} #{branch}:refs/heads/#{branch}"',
|
20
|
+
'"#{GIT} fetch #{origin}"',
|
21
|
+
'"#{GIT} config branch.#{branch}.remote #{origin}"',
|
22
|
+
'"#{GIT} config branch.#{branch}.merge refs/heads/#{branch}"',
|
23
|
+
'"#{GIT} checkout #{branch}"'
|
24
|
+
]
|
25
|
+
},
|
26
|
+
|
27
|
+
:mv => {
|
28
|
+
:desc => "grb mv [branch1] [branch2]\n\tgrb mv [branch] (default current_branch)",
|
29
|
+
:commands => [
|
30
|
+
' if(branch != branch_)
|
31
|
+
"#{GIT} push #{origin} #{branch}:refs/heads/#{branch_}
|
32
|
+
#{GIT} fetch #{origin}
|
33
|
+
#{GIT} branch --track #{branch_} #{origin}/#{branch_}
|
34
|
+
#{GIT} checkout #{branch_}
|
35
|
+
#{GIT} branch -d #{branch}
|
36
|
+
#{GIT} push #{origin} :refs/heads/#{branch}"
|
37
|
+
else
|
38
|
+
"#{GIT} push #{origin} #{current_branch}:refs/heads/#{branch}
|
39
|
+
#{GIT} fetch #{origin}
|
40
|
+
#{GIT} branch --track #{branch} #{origin}/#{branch}
|
41
|
+
#{GIT} checkout #{branch}
|
42
|
+
#{GIT} push #{origin} :refs/heads/#{current_branch}
|
43
|
+
#{GIT} branch -d #{current_branch}"
|
44
|
+
end'
|
45
|
+
]
|
46
|
+
},
|
47
|
+
|
48
|
+
:rm => {
|
49
|
+
:desc => "grb rm [branch] (default current_branch)",
|
50
|
+
:commands => [
|
51
|
+
'"#{GIT} push #{origin} :refs/heads/#{branch}"',
|
52
|
+
'"#{GIT} checkout master" if current_branch == branch',
|
53
|
+
'"#{GIT} branch -d #{branch}"'
|
54
|
+
]
|
55
|
+
},
|
56
|
+
|
57
|
+
:pull => {
|
58
|
+
:desc => "grb pull [branch] (default current_branch)",
|
59
|
+
:commands => [
|
60
|
+
'"#{GIT} fetch #{origin}"',
|
61
|
+
'if local_branches.include?(branch)
|
62
|
+
"#{GIT} config branch.#{branch}.remote #{origin}\n" +
|
63
|
+
"#{GIT} config branch.#{branch}.merge refs/heads/#{branch}"
|
64
|
+
else
|
65
|
+
"#{GIT} branch --track #{branch} #{origin}/#{branch}"
|
66
|
+
end'
|
67
|
+
]
|
68
|
+
}
|
69
|
+
}
|
70
|
+
|
71
|
+
def self.parse(opt)
|
72
|
+
if COMMANDS.keys.include?(opt[:command].to_sym)
|
73
|
+
current_branch,branch,branch_,origin = get_current_branch,opt[:branch],opt[:branch_],ORIGIN
|
74
|
+
|
75
|
+
COMMANDS[opt[:command].to_sym][:commands].map {|x| exec_cmd(eval(x))}
|
76
|
+
else
|
77
|
+
help
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def self.exec_cmd(str)
|
82
|
+
return true unless str
|
83
|
+
puts("\e[031m" + str.gsub(/^\s*/,'') + "\e[0m")
|
84
|
+
system("#{str}")
|
85
|
+
end
|
86
|
+
|
87
|
+
def self.get_current_branch
|
88
|
+
(`git branch 2> /dev/null | grep '^\*'`).gsub(/\W/,'')
|
89
|
+
end
|
90
|
+
|
91
|
+
def self.local_branches
|
92
|
+
(`git branch -l`).split(/\n/).map{|x| x.gsub(/\W/,'')}
|
93
|
+
end
|
94
|
+
|
95
|
+
def self.help(*args)
|
96
|
+
puts "USAGE:"
|
97
|
+
COMMANDS.values.map {|x| puts "\t" + x[:desc]}
|
98
|
+
end
|
99
|
+
end
|
data/lib/version.rb
ADDED
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jinzhu-grb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jinzhu Zhang
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-07-09 00:00:00 -07:00
|
13
|
+
default_executable: grb
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: grb
|
17
|
+
email: wosmvp@gmail.com
|
18
|
+
executables:
|
19
|
+
- grb
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- bin/grb
|
24
|
+
- lib/version.rb
|
25
|
+
- lib/grb.rb
|
26
|
+
files:
|
27
|
+
- bin/grb
|
28
|
+
- Rakefile
|
29
|
+
- lib/version.rb
|
30
|
+
- lib/grb.rb
|
31
|
+
- Manifest
|
32
|
+
- grb.gemspec
|
33
|
+
has_rdoc: true
|
34
|
+
homepage: http://www.zhangjinzhu.com
|
35
|
+
post_install_message:
|
36
|
+
rdoc_options:
|
37
|
+
- --line-numbers
|
38
|
+
- --inline-source
|
39
|
+
- --title
|
40
|
+
- Grb
|
41
|
+
- --main
|
42
|
+
- README.rdoc
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: "0"
|
50
|
+
version:
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: "1.2"
|
56
|
+
version:
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project: grb
|
60
|
+
rubygems_version: 1.2.0
|
61
|
+
signing_key:
|
62
|
+
specification_version: 2
|
63
|
+
summary: grb
|
64
|
+
test_files: []
|
65
|
+
|