gcb 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: dbcb86bc1d9058bfcd022e601ba3569e36bac34d
4
+ data.tar.gz: 042bb7467502c46b198b5e7e3afd1b096d9bb4fd
5
+ SHA512:
6
+ metadata.gz: 2dabd46423a782f5c119dcacc574e26a99807cfe0d8537da3f14f894bb2dd61d000219ac178eb8205444044fbc4a93d25b8a778593d6c7aa0860e3ffbf9584e2
7
+ data.tar.gz: d7d6e423f6c7eada5d99e0be396cf200c43b005f45221026fa8950035e1398ff605e07dfc04aeb6b4432755f08b611ec8ad3aad80f46ee382bdd4bbd0501d004
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem 'rspec'
7
+ gem 'rspec-nc'
8
+ gem 'guard'
9
+ gem 'guard-rspec'
10
+ end
@@ -0,0 +1,48 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features)
6
+
7
+ ## Uncomment to clear the screen before every task
8
+ # clearing :on
9
+
10
+ ## Guard internally checks for changes in the Guardfile and exits.
11
+ ## If you want Guard to automatically start up again, run guard in a
12
+ ## shell loop, e.g.:
13
+ ##
14
+ ## $ while bundle exec guard; do echo "Restarting Guard..."; done
15
+ ##
16
+ ## Note: if you are using the `directories` clause above and you are not
17
+ ## watching the project directory ('.'), then you will want to move
18
+ ## the Guardfile to a watched dir and symlink it back, e.g.
19
+ #
20
+ # $ mkdir config
21
+ # $ mv Guardfile config/
22
+ # $ ln -s config/Guardfile .
23
+ #
24
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
25
+
26
+ # Note: The cmd option is now required due to the increasing number of ways
27
+ # rspec may be run, below are examples of the most common uses.
28
+ # * bundler: 'bundle exec rspec'
29
+ # * bundler binstubs: 'bin/rspec'
30
+ # * spring: 'bin/rspec' (This will use spring if running and you have
31
+ # installed the spring binstubs per the docs)
32
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
33
+ # * 'just' rspec: 'rspec'
34
+
35
+ guard :rspec, cmd: "bundle exec rspec" do
36
+ require "guard/rspec/dsl"
37
+ dsl = Guard::RSpec::Dsl.new(self)
38
+
39
+ # RSpec files
40
+ rspec = dsl.rspec
41
+ watch(rspec.spec_helper) { rspec.spec_dir }
42
+ watch(rspec.spec_support) { rspec.spec_dir }
43
+ watch(rspec.spec_files)
44
+
45
+ # Ruby files
46
+ ruby = dsl.ruby
47
+ dsl.watch_spec_files_for(ruby.lib_files)
48
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Fredrik Persen Fostvedt
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,26 @@
1
+ # Git Checkout Branch
2
+
3
+ Git Checkout Branch (gcb) is a gem for quickly checking out branches based on partial names.
4
+
5
+ ## Installation
6
+
7
+ $ gem install gcb
8
+
9
+ Beware that this will only install the gem for your current ruby environment! If you're using tools like rvm or rbenv, you might want to install the gem globally.
10
+
11
+ ## Usage
12
+
13
+ ```
14
+ $ gcb weird
15
+ Switched to branch 'my-weird-branch-1337123456'
16
+ $ gcb ast
17
+ Switched to branch 'master'
18
+ ```
19
+
20
+ ## Contributing
21
+
22
+ 1. Fork it ( https://github.com/[my-github-username]/gco/fork )
23
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
24
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
25
+ 4. Push to the branch (`git push origin my-new-feature`)
26
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/gcb ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gcb'
4
+
5
+ Gcb::BranchChanger.new.change!(ARGV.join(' '))
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gcb/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gcb"
8
+ spec.version = Gco::VERSION
9
+ spec.authors = ["Fredrik Persen Fostvedt"]
10
+ spec.email = ["fpfostvedt@gmail.com"]
11
+ spec.summary = %q{git checkout +}
12
+ spec.description = %q{git checkout +}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = ['gcb']
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,53 @@
1
+ require 'gcb/version'
2
+
3
+ module Gcb
4
+ def self.root
5
+ File.expand_path '../..', __FILE__
6
+ end
7
+
8
+ class BranchChanger
9
+ def initialize(git_repository_directory=Dir.pwd)
10
+ @git_dir = "#{git_repository_directory}/.git"
11
+ end
12
+
13
+ def change!(branch)
14
+ if branches.include?(branch)
15
+ checkout_branch(branch)
16
+ elsif partially_matching_branch = partially_matching_branch_from_branches_and_branch(branches, branch)
17
+ checkout_branch(partially_matching_branch)
18
+ else
19
+ # don't change branch
20
+ end
21
+ current_branch
22
+ end
23
+
24
+ private
25
+
26
+ #
27
+ # Matching
28
+ #
29
+ def partially_matching_branch_from_branches_and_branch(branches, branch)
30
+ branches.find { |existing_branch| existing_branch.include?(branch) }
31
+ end
32
+
33
+
34
+ #
35
+ # Git Queries
36
+ #
37
+ def branches
38
+ @branches ||= git('branch').split("\n").map { |branch| branch.gsub('*', '') }.map(&:strip)
39
+ end
40
+
41
+ def current_branch
42
+ git('branch').match(/\* (.*)\n/)[1]
43
+ end
44
+
45
+ def checkout_branch(branch)
46
+ git("checkout #{branch}")
47
+ end
48
+
49
+ def git(command)
50
+ `git --git-dir=#{@git_dir} #{command}`
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module Gco
2
+ VERSION = "0.0.1"
3
+ end
File without changes
@@ -0,0 +1,76 @@
1
+ require 'spec_helper'
2
+
3
+ module Gcb
4
+ describe BranchChanger do
5
+ GIT_TEST_REPO_DIRECTORY = "#{Gcb.root}/spec/fixtures/git_test_repo"
6
+
7
+ let (:branch_changer) { BranchChanger.new(GIT_TEST_REPO_DIRECTORY) }
8
+
9
+ let (:branches) { ['master'] }
10
+
11
+ before do
12
+ initialize_repo
13
+ add_branches(branches)
14
+ end
15
+
16
+ after do
17
+ FileUtils.rm_rf(GIT_TEST_REPO_DIRECTORY)
18
+ end
19
+
20
+ describe "#change!" do
21
+ let (:branches) { ['master'] }
22
+ let (:input) { 'master' }
23
+
24
+ before do
25
+ branch_changer.change!(input)
26
+ end
27
+
28
+
29
+ describe 'switch to exact branch name' do
30
+ let (:branches) { ['master', 'new-branch'] }
31
+
32
+ let (:input) { 'new-branch' }
33
+ let (:expected_branch) { 'new-branch' }
34
+
35
+ specify { expect(current_branch).to eq expected_branch }
36
+ end
37
+
38
+ describe 'switch to partial branch name' do
39
+ let (:branches) { ['master', 'new-branch'] }
40
+
41
+ let (:input) { 'new' }
42
+ let (:expected_branch) { 'new-branch' }
43
+
44
+ specify { expect(current_branch).to eq expected_branch }
45
+ end
46
+ end
47
+
48
+ def initialize_repo
49
+ `git init #{GIT_TEST_REPO_DIRECTORY}`
50
+ `touch #{GIT_TEST_REPO_DIRECTORY}/file`
51
+ git("add #{GIT_TEST_REPO_DIRECTORY}")
52
+ git("commit -m 'initial'")
53
+ end
54
+
55
+ def add_branches(branches)
56
+ branches.each do |branch|
57
+ next if branch == 'master'
58
+ add_branch(branch)
59
+ end
60
+ end
61
+
62
+ def add_branch(branch_name)
63
+ previous_branch = current_branch
64
+ git("checkout -b #{branch_name}")
65
+ git("checkout #{previous_branch}")
66
+ end
67
+
68
+ def current_branch
69
+ git('branch').match(/\* (.*)\n/)[1]
70
+ end
71
+
72
+ def git(command)
73
+ `git --git-dir=#{GIT_TEST_REPO_DIRECTORY}/.git #{command}`
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,93 @@
1
+ Dir["./lib/*"].each {|file| require file }
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+ RSpec.configure do |config|
22
+ # rspec-expectations config goes here. You can use an alternate
23
+ # assertion/expectation library such as wrong or the stdlib/minitest
24
+ # assertions if you prefer.
25
+ config.expect_with :rspec do |expectations|
26
+ # This option will default to `true` in RSpec 4. It makes the `description`
27
+ # and `failure_message` of custom matchers include text for helper methods
28
+ # defined using `chain`, e.g.:
29
+ # be_bigger_than(2).and_smaller_than(4).description
30
+ # # => "be bigger than 2 and smaller than 4"
31
+ # ...rather than:
32
+ # # => "be bigger than 2"
33
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
34
+ end
35
+
36
+ # rspec-mocks config goes here. You can use an alternate test double
37
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
38
+ config.mock_with :rspec do |mocks|
39
+ # Prevents you from mocking or stubbing a method that does not exist on
40
+ # a real object. This is generally recommended, and will default to
41
+ # `true` in RSpec 4.
42
+ mocks.verify_partial_doubles = true
43
+ end
44
+
45
+ # The settings below are suggested to provide a good initial experience
46
+ # with RSpec, but feel free to customize to your heart's content.
47
+ =begin
48
+ # These two settings work together to allow you to limit a spec run
49
+ # to individual examples or groups you care about by tagging them with
50
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
51
+ # get run.
52
+ config.filter_run :focus
53
+ config.run_all_when_everything_filtered = true
54
+
55
+ # Limits the available syntax to the non-monkey patched syntax that is
56
+ # recommended. For more details, see:
57
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
58
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
59
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
60
+ config.disable_monkey_patching!
61
+
62
+ # This setting enables warnings. It's recommended, but in some cases may
63
+ # be too noisy due to issues in dependencies.
64
+ config.warnings = true
65
+
66
+ # Many RSpec users commonly either run the entire suite or an individual
67
+ # file, and it's useful to allow more verbose output when running an
68
+ # individual spec file.
69
+ if config.files_to_run.one?
70
+ # Use the documentation formatter for detailed output,
71
+ # unless a formatter has already been configured
72
+ # (e.g. via a command-line flag).
73
+ config.default_formatter = 'doc'
74
+ end
75
+
76
+ # Print the 10 slowest examples and example groups at the
77
+ # end of the spec run, to help surface which specs are running
78
+ # particularly slow.
79
+ config.profile_examples = 10
80
+
81
+ # Run specs in random order to surface order dependencies. If you find an
82
+ # order dependency and want to debug it, you can fix the order by providing
83
+ # the seed, which is printed after each run.
84
+ # --seed 1234
85
+ config.order = :random
86
+
87
+ # Seed global randomization in this process using the `--seed` CLI option.
88
+ # Setting this allows you to use `--seed` to deterministically reproduce
89
+ # test failures related to randomization by passing the same `--seed` value
90
+ # as the one that triggered the failure.
91
+ Kernel.srand config.seed
92
+ =end
93
+ end
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gcb
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Fredrik Persen Fostvedt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-06-01 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.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: git checkout +
42
+ email:
43
+ - fpfostvedt@gmail.com
44
+ executables:
45
+ - gcb
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - ".gitignore"
50
+ - ".rspec"
51
+ - Gemfile
52
+ - Guardfile
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - bin/gcb
57
+ - gcb.gemspec
58
+ - lib/gcb.rb
59
+ - lib/gcb/version.rb
60
+ - spec/Gemfile.lock
61
+ - spec/lib/gcb_spec.rb
62
+ - spec/spec_helper.rb
63
+ homepage: ''
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.4.5
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: git checkout +
87
+ test_files:
88
+ - spec/Gemfile.lock
89
+ - spec/lib/gcb_spec.rb
90
+ - spec/spec_helper.rb
91
+ has_rdoc: