capita_git 0.0.2 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -2,4 +2,5 @@ pkg/*
2
2
  *.gem
3
3
  .bundle
4
4
  .idea
5
- lib/capita_git/man
5
+ lib/capita_git/man
6
+ tmp/*
data/Gemfile CHANGED
@@ -2,4 +2,3 @@ source "http://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in capita_git.gemspec
4
4
  gemspec
5
- gem 'ronn'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- capita_git (0.0.1)
4
+ capita_git (0.1.0)
5
5
  git (>= 1.2.5)
6
6
  thor (>= 0.14.6)
7
7
 
@@ -11,11 +11,13 @@ GEM
11
11
  git (1.2.5)
12
12
  hpricot (0.8.3)
13
13
  mustache (0.12.0)
14
+ open4 (1.0.1)
14
15
  rdiscount (1.6.5)
15
16
  ronn (0.7.3)
16
17
  hpricot (>= 0.8.2)
17
18
  mustache (>= 0.7.0)
18
19
  rdiscount (>= 1.5.8)
20
+ shoulda (2.11.3)
19
21
  thor (0.14.6)
20
22
 
21
23
  PLATFORMS
@@ -23,6 +25,6 @@ PLATFORMS
23
25
 
24
26
  DEPENDENCIES
25
27
  capita_git!
26
- git (>= 1.2.5)
27
- ronn
28
- thor (>= 0.14.6)
28
+ open4
29
+ ronn (>= 0.7.3)
30
+ shoulda (>= 2.11.0)
data/README.rdoc CHANGED
@@ -8,23 +8,23 @@
8
8
 
9
9
  $ gitc check
10
10
 
11
- $ gitc create [name] [source_branch]
11
+ $ gitc create [name] ([source_branch])
12
12
 
13
- $ gitc update [branch]
13
+ $ gitc update ([source_branch])
14
14
 
15
- $ gitc close [branch]
15
+ $ gitc close ([source_branch])
16
16
 
17
17
  === DESCRIPTION
18
18
 
19
- *gitc* is a git automation tool used by CAPITA Unternehmensberatung GmbH with comes
20
- along the gem *capita_git*.
19
+ *gitc* is a git automation tool used by CAPITA Unternehmensberatung GmbH which comes
20
+ packaged as the Rubygem *capita_git*.
21
21
 
22
- It's main purpose is to automate repetivite tasks as spawing new feature branches,
22
+ It's main purpose is to automate repetivite tasks like spawing new feature branches,
23
23
  updating and rebasing from the source branch of a given feature branch, as well as
24
- closing/merging feature branchs back into their originating timeline.
24
+ closing/merging feature branches back into their original tree.
25
25
 
26
- *gict* uses a strict naming convention for creating, idenfitying and maintaining
27
- local and remote branches and depends on the users's name being set in the git
26
+ *gitc* uses a strict naming convention for creating, identifying and maintaining
27
+ local and remote branches and depends on the user's name being set in the git
28
28
  configuration of your local cloned copy or in the global settings.
29
29
 
30
30
  Please make sure that both
@@ -33,7 +33,7 @@ and
33
33
  $ git config user.email
34
34
  return your correct name and email address.
35
35
 
36
- === Installation
36
+ === INSTALLATION
37
37
 
38
38
  $ gem install capita_git
39
39
 
@@ -44,14 +44,23 @@ For detailed explanation of the various commands, please use *gitc help <command
44
44
  Available commands currently are:
45
45
 
46
46
  * <check>:
47
- performs a basic check of your repository, as well as maintains fixbranches for
48
- major release tags both locally and remotely
47
+ Performs a basic check of your repository, as well as maintains fixbranches for
48
+ major release tags both locally and remotely.
49
+ i.e., assuming your current release tag is 1.0, this will automatically create
50
+ the remote branch 1.0-fix that is based upon 1.0
49
51
 
50
- * <create>:
51
- creates a feature branch
52
+ * <create> branch_name:
53
+ Creates a feature branch based upon the current branch with the naming scheme
54
+ <USER_INITIALS>_sourcebranch_branch_name>.
55
+ Assuming you are 'CO' and on 1.0-fix, gitc create js_bugfix will create
56
+ the local branch co_1.0-fix_js_bugfix and check it out
52
57
 
53
58
  * <update>:
54
- updates the feature branch's source branch and does a rebase
59
+ Updates the active feature branch's source branch and does a rebase, thus pulling
60
+ in the latest changes into your local tree
55
61
 
56
62
  * <close>:
57
- closes a feature branch by updating and merging into the source branch
63
+ Closes a feature branch by updating the source branch, rebasing it onto your feature
64
+ branch and then merging into the source branch.
65
+
66
+
data/Rakefile CHANGED
@@ -2,6 +2,22 @@ $:.unshift File.expand_path("../lib", __FILE__)
2
2
  require 'bundler/gem_helper'
3
3
  Bundler::GemHelper.install_tasks
4
4
 
5
+ require 'rake/testtask'
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.pattern = 'test/**/*_test.rb'
9
+ test.verbose = true
10
+ end
11
+
12
+ task :default => :test
13
+
14
+ require 'rake/rdoctask'
15
+ Rake::RDocTask.new do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.rdoc_files.include('README*')
18
+ rdoc.rdoc_files.include('lib/**/*.rb')
19
+ end
20
+
5
21
  task :install => ["man:clean", "man:build"]
6
22
  task :build => ["man:clean", "man:build"]
7
23
  task :release => ["man:clean", "man:build"]
data/capita_git.gemspec CHANGED
@@ -6,11 +6,11 @@ Gem::Specification.new do |s|
6
6
  s.name = "capita_git"
7
7
  s.version = CapitaGit::VERSION
8
8
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Sebastian Georgi"]
10
- s.email = ["sgeorgi@capita.de"]
9
+ s.authors = ["Sebastian Georgi", "Christoph Olszowka"]
10
+ s.email = ["sgeorgi@capita.de", "colszowka at capita de"]
11
11
  s.homepage = "https://github.com/capita/capita_git"
12
- s.summary = %q{Git-automation tool for managing features branches and more}
13
- s.description = %q{see RDoc or command help for further information}
12
+ s.summary = %q{Git-automation tool for quick handling of common patterns for feature and fix branches}
13
+ s.description = %q{Git-automation tool for quick handling of common patterns for feature and fix branches}
14
14
 
15
15
  s.rubyforge_project = "capita_git"
16
16
 
@@ -21,4 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.require_paths = ["lib"]
22
22
  s.add_dependency('git', '>= 1.2.5')
23
23
  s.add_dependency('thor', '>= 0.14.6')
24
+ s.add_development_dependency('ronn', ">= 0.7.3")
25
+ s.add_development_dependency('shoulda', ">= 2.11.0")
26
+ s.add_development_dependency('open4')
24
27
  end
@@ -126,7 +126,6 @@ module CapitaGit
126
126
  raise "Source branch '#{name}' is not a feature branch, can't close!" unless repo.is_local_feature_branch?(name)
127
127
 
128
128
  CapitaGit.ui.confirm "--> Closing feature branch '#{name}' onto '#{repo.source_branch(name)}'"
129
- repo.rebase_local_branch(name)
130
129
  repo.close_local_branch(name)
131
130
  end
132
131
 
@@ -142,4 +141,4 @@ module CapitaGit
142
141
  !(`which groff` rescue '').empty?
143
142
  end
144
143
  end
145
- end
144
+ end
@@ -1,7 +1,7 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "GITC" "5" "January 2011" "GITC 0.0.2" "GITC Manual"
4
+ .TH "GITC" "5" "January 2011" "GITC 0.1.0" "GITC Manual"
5
5
  .
6
6
  .SH "NAME"
7
7
  \fBgitc\fR \- git helper for CAPITA Unternehmensberatung GmbH
@@ -1,5 +1,5 @@
1
1
  .\" generated with Ronn/v0.7.3
2
2
  .\" http://github.com/rtomayko/ronn/tree/0.7.3
3
3
  .
4
- .TH "GITC\-CHECK" "" "January 2011" "GITC 0.0.2" "GITC Manual"
4
+ .TH "GITC\-CHECK" "" "January 2011" "GITC 0.1.0" "GITC Manual"
5
5
 
@@ -2,4 +2,4 @@ GITC-CHECK() GITC Manual GITC-CHECK()
2
2
 
3
3
 
4
4
 
5
- GITC 0.0.2 January 2011 GITC-CHECK()
5
+ GITC 0.1.0 January 2011 GITC-CHECK()
@@ -50,4 +50,4 @@ COMMANDS
50
50
 
51
51
 
52
52
 
53
- GITC 0.0.2 January 2011 GITC(5)
53
+ GITC 0.1.0 January 2011 GITC(5)
@@ -1,3 +1,3 @@
1
1
  module CapitaGit
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
data/test/cli_test.rb ADDED
@@ -0,0 +1,101 @@
1
+ require 'test_helper'
2
+
3
+ class CliTest < Test::Unit::TestCase
4
+ with_a_repo_setup do
5
+ in_dir 'local_checkout_1' do
6
+ after('git pull') { should_have_tag '1.0' }
7
+
8
+ gitc 'check' do
9
+ should_have_branch '1.0-fix'
10
+
11
+ in_dir 'local_checkout_2' do
12
+ should_not_have_branch '1.0-fix'
13
+
14
+ gitc 'check' do
15
+ should_have_branch '1.0-fix'
16
+
17
+ context "after creating a fix" do
18
+ setup do
19
+ assert_command 'git checkout 1.0-fix'
20
+ assert_command 'echo "foo" > fixfile'
21
+ assert_command 'git add . && git commit -m "fixfile" && git push'
22
+ end
23
+
24
+ should_not_have_file 'fixfile', :in => 'local_checkout_1'
25
+
26
+ context "after pull and checkout of 1.0-fix in checkout 1" do
27
+ setup do
28
+ in_dir 'local_checkout_1' do
29
+ assert_command 'git checkout 1.0-fix'
30
+ assert_command 'git pull'
31
+ end
32
+ end
33
+ should_have_file 'fixfile', :in => 'local_checkout_1'
34
+ end
35
+ end
36
+
37
+ end
38
+ end
39
+ end
40
+
41
+ gitc 'create my_feature' do
42
+ should "be on branch USER_master_my_feature" do
43
+ user = CapitaGit::Repository.new('.').user_shortcut
44
+ assert_equal "#{user}_master_my_feature", repo.current_branch
45
+ end
46
+
47
+ should_not_have_file 'awesome_feature', :in => 'local_checkout_1'
48
+
49
+ # Propagating changes on source branch with gitc update
50
+ context "after checkout 2 pushes file master_2_update on master" do
51
+ setup do
52
+ in_dir 'local_checkout_2' do
53
+ assert_command 'echo "foo" > master_2_update'
54
+ assert_command 'git add . && git commit -m "master 2 update" && git push'
55
+ end
56
+ end
57
+
58
+ after 'git pull origin master' do
59
+ should_not_have_file 'awesome_feature', :in => 'local_checkout_1'
60
+ end
61
+
62
+ context "after invoking 'gitc update'" do
63
+ setup { assert_command("#{ShouldaMacros::BIN_PATH} update") }
64
+ should_have_file 'master_2_update', :in => 'local_checkout_1'
65
+ end
66
+ end
67
+
68
+ # Committing a fix and closing branch
69
+ context "after committing a file and gitc close" do
70
+ setup do
71
+ assert_command 'echo "foo" > awesome_feature'
72
+ assert_command 'git add . && git commit -m "my feature"'
73
+ assert_command("#{ShouldaMacros::BIN_PATH} close")
74
+ assert_command 'git push'
75
+ end
76
+
77
+ should "be on branch master" do
78
+ assert_equal 'master', repo.current_branch
79
+ end
80
+
81
+ should "have removed the feature branch" do
82
+ assert !repo.branches.map(&:name).any? {|n| n =~ /feature/}
83
+ end
84
+
85
+ should_have_file 'awesome_feature', :in => 'local_checkout_1'
86
+
87
+ context "after git pull on local_checkout_2" do
88
+ setup do
89
+ in_dir 'local_checkout_2' do
90
+ assert_command 'git pull'
91
+ end
92
+ end
93
+
94
+ should_have_file 'awesome_feature', :in => 'local_checkout_2'
95
+ end
96
+ end
97
+
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,160 @@
1
+ module ShouldaMacros
2
+ TEMP_DIR = File.expand_path('/tmp/capita_git_tmp')
3
+ BIN_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..', 'bin/gitc'))
4
+
5
+ # Test method level helpers
6
+ module InstanceMethods
7
+ # Returns the path to the temporary directory, with the optional subdirectory
8
+ # Creates the directory if it's missing
9
+ def temp_dir(subdirectory = nil)
10
+ path = ShouldaMacros::TEMP_DIR
11
+ path = File.join(path, subdirectory) if subdirectory
12
+ FileUtils.mkdir_p(path)
13
+ path
14
+ end
15
+
16
+ # Switches current working directory to the temp_dir subdirectory of given
17
+ # name for the given block, switching back after execution
18
+ def in_dir(name)
19
+ Dir.chdir(temp_dir(name)) do
20
+ yield
21
+ end
22
+ end
23
+
24
+ # Runs the specified command and asserts it's exit status should be 0
25
+ def assert_command(cmd)
26
+ Open4.popen4(cmd) { |pid, stdin, stdout, stderr| }
27
+ #puts `#{cmd}`
28
+ assert_equal 0, $?.exitstatus, "Expected exit status of 0 for command '#{cmd}'"
29
+ end
30
+
31
+ # Opens a Git ruby lib instance for current working dir and returns it
32
+ def repo
33
+ Git.open(Dir.getwd)
34
+ end
35
+ end
36
+
37
+ # Context and should block helpers
38
+ module ClassMethods
39
+
40
+ #
41
+ # Creates a repository with a remote in temp_dir
42
+ #
43
+ def with_a_repo_setup
44
+ context "With a basic repo setup" do
45
+ setup do
46
+ ENV["GIT_WORK_TREE"] = nil
47
+ ENV['GIT_DIR'] = nil
48
+ ENV['GIT_INDEX_FILE'] = nil
49
+
50
+ in_dir 'origin' do
51
+ assert_command 'git init --bare'
52
+ end
53
+
54
+ in_dir "initial_commit" do
55
+ assert_command 'git init'
56
+ assert_command "echo 'foo bar commit' > README"
57
+ assert_command "git add . && git commit -m 'Initial commit'"
58
+ assert_command "git remote add origin #{temp_dir('origin')}"
59
+ assert_command 'git push origin master'
60
+ end
61
+
62
+ in_dir "local_checkout_1" do
63
+ assert_command "git clone #{temp_dir('origin')} ."
64
+ assert_command 'git push origin master'
65
+ assert_command 'git pull origin master'
66
+ end
67
+
68
+ in_dir "local_checkout_2" do
69
+ assert_command "git clone #{temp_dir('origin')} ."
70
+ assert_command 'git tag -a 1.0 -m "First release"'
71
+ assert_command 'git push --tags origin master'
72
+ assert_command 'git pull origin master'
73
+ end
74
+ end
75
+
76
+ yield
77
+
78
+ # Make sure the temporary directory is purged after every run
79
+ teardown do
80
+ FileUtils.rm_rf(temp_dir)
81
+ end
82
+ end
83
+ end
84
+
85
+ def in_dir(name)
86
+ context "in dir '#{name}'" do
87
+ setup do
88
+ @original_wd ||= {}
89
+ @original_wd[name] = Dir.getwd
90
+ Dir.chdir(temp_dir(name))
91
+ end
92
+
93
+ yield
94
+
95
+ teardown do
96
+ Dir.chdir(@original_wd[name]) if @original_wd
97
+ end
98
+ end
99
+ end
100
+
101
+ # Invokes the gitc binary with given arguments and yields after the setup
102
+ def gitc(args)
103
+ context "after invoking 'gitc #{args}'" do
104
+ setup { assert_command("#{BIN_PATH} #{args}") }
105
+ yield
106
+ end
107
+ end
108
+
109
+ def after(command)
110
+ context "after '#{command}'" do
111
+ setup do
112
+ assert_command command
113
+ end
114
+ yield
115
+ end
116
+ end
117
+
118
+ def should_have_branch(name)
119
+ should "have branch '#{name}'" do
120
+ assert repo.branches.map(&:name).include?(name), "Found in #{Dir.getwd}: " + repo.branches.map(&:name).inspect
121
+ end
122
+ end
123
+
124
+ def should_not_have_branch(name)
125
+ should "NOT have branch '#{name}'" do
126
+ assert !repo.branches.map(&:name).include?(name), "Found in #{Dir.getwd}: " + repo.branches.map(&:name).inspect
127
+ end
128
+ end
129
+
130
+ def should_have_tag(name)
131
+ should "have tag '#{name}'" do
132
+ assert repo.tags.map(&:name).include?(name), repo.tags.map(&:name).inspect
133
+ end
134
+ end
135
+
136
+ def should_not_have_tag(name)
137
+ should "NOT have tag '#{name}'" do
138
+ assert !repo.tags.map(&:name).include?(name), repo.tags.map(&:name).inspect
139
+ end
140
+ end
141
+
142
+ def should_have_file(name, options)
143
+ raise "Usage: should_have_file 'filename', :in => 'tempdirname' (or %w(dir1 dir2))" unless options[:in]
144
+ [options[:in]].flatten.each do |dir|
145
+ should "have file '#{name}' in #{dir}" do
146
+ assert_equal 1, Dir[File.join(temp_dir(dir), name)].length
147
+ end
148
+ end
149
+ end
150
+
151
+ def should_not_have_file(name, options)
152
+ raise "Usage: should_not_have_file 'filename', :in => 'tempdirname' (or %w(dir1 dir2))" unless options[:in]
153
+ [options[:in]].flatten.each do |dir|
154
+ should "not have file '#{name}' in #{dir}" do
155
+ assert_equal 0, Dir[File.join(temp_dir(dir), name)].length
156
+ end
157
+ end
158
+ end
159
+ end
160
+ end
@@ -0,0 +1,16 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'capita_git'
4
+ require 'git'
5
+
6
+ require 'test/unit'
7
+ require 'shoulda'
8
+
9
+ require 'fileutils'
10
+ require "open4" # See http://tech.natemurray.com/2007/03/ruby-shell-commands.html
11
+ require 'shoulda_macros'
12
+
13
+ class Test::Unit::TestCase
14
+ include ShouldaMacros::InstanceMethods
15
+ extend ShouldaMacros::ClassMethods
16
+ end
metadata CHANGED
@@ -2,20 +2,21 @@
2
2
  name: capita_git
3
3
  version: !ruby/object:Gem::Version
4
4
  hash: 27
5
- prerelease: false
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sebastian Georgi
14
+ - Christoph Olszowka
14
15
  autorequire:
15
16
  bindir: bin
16
17
  cert_chain: []
17
18
 
18
- date: 2011-01-25 00:00:00 +01:00
19
+ date: 2011-01-27 00:00:00 +01:00
19
20
  default_executable:
20
21
  dependencies:
21
22
  - !ruby/object:Gem::Dependency
@@ -50,9 +51,56 @@ dependencies:
50
51
  version: 0.14.6
51
52
  type: :runtime
52
53
  version_requirements: *id002
53
- description: see RDoc or command help for further information
54
+ - !ruby/object:Gem::Dependency
55
+ name: ronn
56
+ prerelease: false
57
+ requirement: &id003 !ruby/object:Gem::Requirement
58
+ none: false
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ hash: 5
63
+ segments:
64
+ - 0
65
+ - 7
66
+ - 3
67
+ version: 0.7.3
68
+ type: :development
69
+ version_requirements: *id003
70
+ - !ruby/object:Gem::Dependency
71
+ name: shoulda
72
+ prerelease: false
73
+ requirement: &id004 !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 35
79
+ segments:
80
+ - 2
81
+ - 11
82
+ - 0
83
+ version: 2.11.0
84
+ type: :development
85
+ version_requirements: *id004
86
+ - !ruby/object:Gem::Dependency
87
+ name: open4
88
+ prerelease: false
89
+ requirement: &id005 !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ type: :development
99
+ version_requirements: *id005
100
+ description: Git-automation tool for quick handling of common patterns for feature and fix branches
54
101
  email:
55
102
  - sgeorgi@capita.de
103
+ - colszowka at capita de
56
104
  executables:
57
105
  - gitc
58
106
  extensions: []
@@ -74,10 +122,13 @@ files:
74
122
  - lib/capita_git/version.rb
75
123
  - man/gitc-check.ronn
76
124
  - man/gitc.ronn
125
+ - test/cli_test.rb
126
+ - test/shoulda_macros.rb
127
+ - test/test_helper.rb
77
128
  - lib/capita_git/man/gitc
129
+ - lib/capita_git/man/gitc.txt
78
130
  - lib/capita_git/man/gitc-check.txt
79
131
  - lib/capita_git/man/gitc-check
80
- - lib/capita_git/man/gitc.txt
81
132
  has_rdoc: true
82
133
  homepage: https://github.com/capita/capita_git
83
134
  licenses: []
@@ -108,9 +159,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
159
  requirements: []
109
160
 
110
161
  rubyforge_project: capita_git
111
- rubygems_version: 1.3.7
162
+ rubygems_version: 1.4.1
112
163
  signing_key:
113
164
  specification_version: 3
114
- summary: Git-automation tool for managing features branches and more
165
+ summary: Git-automation tool for quick handling of common patterns for feature and fix branches
115
166
  test_files: []
116
167