grb 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (7) hide show
  1. data/Manifest +5 -0
  2. data/Rakefile +14 -0
  3. data/bin/grb +28 -0
  4. data/grb.gemspec +32 -0
  5. data/lib/grb.rb +110 -0
  6. data/lib/version.rb +3 -0
  7. metadata +67 -0
@@ -0,0 +1,5 @@
1
+ bin/grb
2
+ Rakefile
3
+ lib/version.rb
4
+ lib/grb.rb
5
+ Manifest
@@ -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,28 @@
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
+ abort('Version: ' + Version::VERSION) if ARGV.delete('--version') || ARGV.delete('-v')
19
+
20
+ EXPLAIN = ARGV.delete('--explain') || ARGV.delete('-e')
21
+
22
+ opt = {
23
+ :command => ARGV[0] || 'push',
24
+ :branch => branch = (ARGV[1] || Grb.get_current_branch),
25
+ :branch_ => ARGV[2] || branch,
26
+ }
27
+
28
+ Grb.parse(opt)
@@ -0,0 +1,32 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{grb}
5
+ s.version = "0.2.3"
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-10-07}
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.homepage = %q{http://www.zhangjinzhu.com}
17
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Grb", "--main", "README.rdoc"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{grb}
20
+ s.rubygems_version = %q{1.3.3}
21
+ s.summary = %q{grb}
22
+
23
+ if s.respond_to? :specification_version then
24
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
25
+ s.specification_version = 3
26
+
27
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
28
+ else
29
+ end
30
+ else
31
+ end
32
+ end
@@ -0,0 +1,110 @@
1
+ class Grb
2
+ GIT = ENV['GRB_GIT'] || 'git'
3
+ ORIGIN = ENV['GRB_ORIGIN'] || 'origin'
4
+
5
+ COMMANDS = {
6
+ :new => {
7
+ :desc => "=> create new branch `branch`\ngrb new [branch] [--explain]",
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 => "=> push branch `branch`, default current_branch\ngrb push [branch] [--explain]",
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 => "=> rename `branch1` to `branch2`\ngrb mv [branch1] [branch2] [--explain]\n=> rename current branch to `branch`\ngrb mv branch [--explain]",
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 => "=> delete branch `branch`,default current_branch\ngrb rm [branch] [--explain]",
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 => "=> pull branch `branch`,default current_branch\ngrb pull [branch] [--explain]",
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
+ '"#{GIT} checkout #{branch}" if current_branch != branch',
68
+ '"#{GIT} merge #{origin}/#{branch}"',
69
+ ]
70
+ },
71
+
72
+ :track => {
73
+ :desc => "=> track branch\ngit track `branch` [--explain]",
74
+ :commands => [
75
+ '"#{GIT} fetch #{origin}"',
76
+ '"#{GIT} branch --track #{branch} origin/#{branch}"',
77
+ '"#{GIT} checkout #{branch}"'
78
+ ]
79
+ }
80
+ }
81
+
82
+ def self.parse(opt)
83
+ if COMMANDS.keys.include?(opt[:command].to_sym)
84
+ current_branch,branch,branch_,origin = get_current_branch,opt[:branch],opt[:branch_],ORIGIN
85
+
86
+ COMMANDS[opt[:command].to_sym][:commands].map {|x| exec_cmd(eval(x))}
87
+ else
88
+ help
89
+ end
90
+ end
91
+
92
+ def self.exec_cmd(str)
93
+ return true unless str
94
+ puts("\e[031m" + str.gsub(/^\s*/,'') + "\e[0m")
95
+ system("#{str}") unless EXPLAIN
96
+ end
97
+
98
+ def self.get_current_branch
99
+ (`git branch 2> /dev/null | grep '^\*'`).gsub(/\W/,'')
100
+ end
101
+
102
+ def self.local_branches
103
+ (`git branch -l`).split(/\n/).map{|x| x.gsub(/\W/,'')}
104
+ end
105
+
106
+ def self.help(*args)
107
+ puts "USAGE:"
108
+ COMMANDS.values.map {|x| puts x[:desc].gsub(/^(\W.*)$/,"\e[31m" + '\1' + "\e[0m").gsub(/^(\w.*)$/,' $ \1')}
109
+ end
110
+ end
@@ -0,0 +1,3 @@
1
+ module Version
2
+ VERSION = '0.2.3'
3
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
5
+ platform: ruby
6
+ authors:
7
+ - Jinzhu Zhang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-10-07 00:00:00 +08: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
+ licenses: []
36
+
37
+ post_install_message:
38
+ rdoc_options:
39
+ - --line-numbers
40
+ - --inline-source
41
+ - --title
42
+ - Grb
43
+ - --main
44
+ - README.rdoc
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - ">="
50
+ - !ruby/object:Gem::Version
51
+ version: "0"
52
+ version:
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ version: "1.2"
58
+ version:
59
+ requirements: []
60
+
61
+ rubyforge_project: grb
62
+ rubygems_version: 1.3.5
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: grb
66
+ test_files: []
67
+