hack 0.1.0

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.
Files changed (5) hide show
  1. data/README.md +29 -0
  2. data/bin/hack +9 -0
  3. data/hack.gemspec +27 -0
  4. data/lib/hack/hack.rb +96 -0
  5. metadata +58 -0
@@ -0,0 +1,29 @@
1
+ # Hack
2
+
3
+ ## Overview
4
+ The basic purpose is to provide some simple automations based upon common Git workflows
5
+
6
+ ## Credits
7
+ * Variation on ReinH's script for managing the git process as documented here: http://reinh.com/blog/2008/08/27/hack-and-and-ship.html
8
+
9
+ ## Usage
10
+
11
+ $ hack on [branch]
12
+
13
+ Switch branches. If no branch is provided it will default to 'master'. If the provided branch does not exist, it is created.
14
+
15
+ $ hack sync
16
+
17
+ Rebases with the master.
18
+
19
+ $ hack push
20
+
21
+ Merge and pushes to your remote repository.
22
+
23
+ $ hack sp
24
+
25
+ Shortcut for (s)ync and (p)ush.
26
+
27
+ $ hack stp [test commands]
28
+
29
+ Run your test suite between the sync and push operations. If no test commands are passed it will default to 'rake'
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'hack/hack'
4
+
5
+ begin
6
+ hack_session = Hack.new(ARGV, STDIN)
7
+ rescue
8
+ $stderr.print "Error: " + $!
9
+ end
@@ -0,0 +1,27 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'hack'
3
+ s.description = "Hack - Convenient git workflow"
4
+ s.summary = s.description
5
+ s.homepage = "http://github.com/jpease/hack/"
6
+
7
+ s.version = '0.1.0'
8
+ s.date = '2009-11-19'
9
+
10
+ s.authors = ["Justin Pease"]
11
+ s.email = "justin.pease@gmail.com"
12
+
13
+ s.files = %w[
14
+ README.md
15
+ hack.gemspec
16
+ bin/hack
17
+ lib/hack/hack.rb
18
+ ]
19
+ s.executables = ['hack']
20
+ s.extra_rdoc_files = %w[README.md]
21
+
22
+ s.require_paths = %w[lib]
23
+ s.rubygems_version = '1.3.5'
24
+ s.specification_version = 2 if s.respond_to? :specification_version=
25
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
26
+
27
+ end
@@ -0,0 +1,96 @@
1
+ require 'optparse'
2
+
3
+ class Hack
4
+
5
+ def initialize(args, stdin)
6
+ set_current_branch
7
+ parse_commands(args)
8
+ end
9
+
10
+ private
11
+
12
+ def parse_commands(args)
13
+ @commands = {}
14
+ display_usage("Error: No command supplied") if args.size == 0
15
+ args.each do |arg|
16
+ case arg
17
+ when "on"
18
+ branch = args[1] ? args[1] : 'master'
19
+ switch_to(branch)
20
+ break
21
+ when "sync"
22
+ sync_with_remote
23
+ break
24
+ when "push"
25
+ push_to_remote
26
+ break
27
+ when "sp"
28
+ sync_with_remote
29
+ push_to_remote
30
+ break
31
+ when "stp"
32
+ sync_with_remote
33
+ run_tests
34
+ push_to_remote
35
+ break
36
+ else
37
+ display_usage("Error: That command was not recognized")
38
+ end
39
+ end
40
+ end
41
+
42
+ def switch_to(branch)
43
+ `git checkout master` unless @current == 'master'
44
+ `git pull origin master`
45
+ create_branch(branch)
46
+ `git checkout #{branch}`
47
+ end
48
+
49
+ def sync_with_remote
50
+ `git checkout master`
51
+ `git pull origin master`
52
+ `git checkout #{@current}`
53
+ `git rebase master`
54
+ end
55
+
56
+ def push_to_remote
57
+ `git checkout master`
58
+ `git merge #{@current}`
59
+ `git push origin master`
60
+ `git checkout #{@current}`
61
+ end
62
+
63
+ def run_tests(cmd)
64
+ `#{cmd}`
65
+ end
66
+
67
+ def set_current_branch
68
+ @current ||= `git branch | grep "*" | awk '{print $2}'`.strip
69
+ end
70
+
71
+ def create_branch(branch)
72
+ branches = `git branch`.split
73
+ if branches.include? branch
74
+ puts "Branch #{branch} already exists."
75
+ else
76
+ `git branch #{branch}`
77
+ puts "New branch #{branch} created."
78
+ end
79
+ end
80
+
81
+ def display_usage(msg=nil)
82
+ puts "#{msg}\n\n" unless msg.nil?
83
+ puts "Usage:\n\n"
84
+ puts "hack on [branch]\n"
85
+ puts "If no branch is supplied master is used.\n\n"
86
+ puts "hack sync\n"
87
+ puts "Rebase to master branch\n\n"
88
+ puts "hack push\n"
89
+ puts "Merges and pushes to origin master\n\n"
90
+ puts "hack sp\n"
91
+ puts "Shortcut for sync then push\n\n"
92
+ puts "hack stp [test command]\n"
93
+ puts "Shortcut for sync, test then push. If not test command is provided, it will default to 'rake'."
94
+ end
95
+ end
96
+
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: hack
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justin Pease
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-11-19 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Hack - Convenient git workflow
17
+ email: justin.pease@gmail.com
18
+ executables:
19
+ - hack
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.md
24
+ files:
25
+ - README.md
26
+ - hack.gemspec
27
+ - bin/hack
28
+ - lib/hack/hack.rb
29
+ has_rdoc: true
30
+ homepage: http://github.com/jpease/hack/
31
+ licenses: []
32
+
33
+ post_install_message:
34
+ rdoc_options: []
35
+
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: "0"
43
+ version:
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: "0"
49
+ version:
50
+ requirements: []
51
+
52
+ rubyforge_project:
53
+ rubygems_version: 1.3.5
54
+ signing_key:
55
+ specification_version: 2
56
+ summary: Hack - Convenient git workflow
57
+ test_files: []
58
+