big_stash 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 47a1bae3f3f0a915402741535734b173058aa631
4
+ data.tar.gz: e3e88fcbe58c6716bfda43aab3142cdc23217aba
5
+ SHA512:
6
+ metadata.gz: a93bd133394c82a04cc99485cd9d09bdd41d4b91be3d94a5e44ff67abe6c72de363e9e7becfc1a1ef4518915175b97e25b4d744d40df1634783158c0e3615edf
7
+ data.tar.gz: 6d250bfc65bad21fb8ee20be690fae4a8a0dd5c569d7f52109b0a21378631f2cf379eaa7a4eab2c2d2eb879ecf1d031414e0ca3ae832ad9b4a409dc232d223f2
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://ruby.taobao.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in big_stash.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 mmoaay
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,61 @@
1
+ # BigStash
2
+
3
+ big-stash is an enhancement for `git stash` command, you can use it to add and apply a stash with the name you have specified before.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'big_stash'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install big_stash
20
+
21
+ ## Usage
22
+
23
+ Run `bin/big-stash` to learn how to use big-stash.
24
+
25
+ ### Add a stash with name
26
+
27
+ If you want to add a stash for a git repository, run following command:
28
+
29
+ ``` ruby
30
+ bin/big-stash -p [root path for a git repository] add [name of the stash]
31
+ ```
32
+
33
+ ### Apply a stash with name
34
+
35
+ If you want to apply a stash for a git repository, run following command:
36
+
37
+ ``` ruby
38
+ bin/big-stash -p [root path for a git repository] apply [name of the stash]
39
+ ```
40
+
41
+ ### List all the stashes
42
+
43
+ If you want to list all the stashes for a git repository, run following command:
44
+
45
+ ``` ruby
46
+ bin/big-stash -p [root path for a git repository] list
47
+ ```
48
+
49
+ ## Development
50
+
51
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
52
+
53
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
54
+
55
+ ## Contributing
56
+
57
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/big_stash.
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/big_stash.gemspec ADDED
@@ -0,0 +1,37 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "big_stash/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "big_stash"
8
+ spec.version = BigStash::VERSION
9
+ spec.authors = ["mmoaay"]
10
+ spec.email = ["mmoaay@sina.com"]
11
+
12
+ spec.summary = %q{Enhancement for git stash.}
13
+ spec.description = %q{Enhancement for git stash that you can give a name to the stash.}
14
+ spec.homepage = "https://github.com/mmoaay/big-stash"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "bin"
30
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.15"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ spec.add_development_dependency "gli", "~> 2.16"
36
+
37
+ end
data/bin/big-stash ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "big_stash"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/lib/big_stash.rb ADDED
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'big_stash/version'
4
+ require 'big_stash/stash_operator'
5
+
6
+ require 'gli'
7
+
8
+ include GLI::App
9
+
10
+ module BigStash
11
+ # Your code goes here...
12
+ program_desc 'Enhancement for git stash'
13
+
14
+ flag [:p,:path], :default_value => './'
15
+
16
+ path = ''
17
+
18
+ pre do |global_options,command,options,args|
19
+ path = global_options[:path]
20
+ end
21
+
22
+ desc 'Add a stash with name'
23
+ command :add do |c|
24
+ c.action do |global_options, options, args|
25
+ help_now!('stash name is required') if args.empty?
26
+ BigStash::StashOperator.new(path).stash(args.first)
27
+ end
28
+ end
29
+
30
+ desc 'Apply a stash with name'
31
+ command :apply do |c|
32
+ c.action do |global_options, options, args|
33
+ help_now!('stash name is required') if args.empty?
34
+ BigStash::StashOperator.new(path).apply_stash(args.first)
35
+ end
36
+ end
37
+
38
+ desc 'List all the stashes'
39
+ command :list do |c|
40
+ c.action do
41
+ p BigStash::StashOperator.new(path).stashes
42
+ end
43
+ end
44
+
45
+ exit run(ARGV)
46
+ end
@@ -0,0 +1,52 @@
1
+ # git stash enhancement module
2
+ module BigStash
3
+ # git stash enhancement operator
4
+ class StashOperator
5
+ attr_reader :stashes
6
+
7
+ def initialize(path)
8
+ @stashes = {}
9
+ @path = path
10
+ IO.popen("cd #{@path}; git stash list") do |io|
11
+ io.each do |line|
12
+ items = line.chop.split(/: /)
13
+ @stashes[items.last] = items.first
14
+ end
15
+ end
16
+ end
17
+
18
+ def stash(name)
19
+ if can_stash
20
+ p `cd #{@path}; git stash save -a #{name}`
21
+ else
22
+ p 'Nothing to stash, working tree clean, continue...'
23
+ end
24
+ end
25
+
26
+ def can_stash
27
+ can_stash = true
28
+ clear_flag = 'nothing to commit, working tree clean'
29
+ IO.popen("cd #{@path}; git status") do |io|
30
+ io.each do |line|
31
+ can_stash = false if line.include? clear_flag
32
+ end
33
+ end
34
+ can_stash
35
+ end
36
+
37
+ def apply_stash(name)
38
+ stash = @stashes[name]
39
+ if stash
40
+ p `cd #{@path}; git stash apply #{stash}`
41
+ else
42
+ p %(Nothing to apply, can not find the stash with name '#{name}', continue...)
43
+ end
44
+ end
45
+
46
+ def stash_for_name(name)
47
+ @stashes[name]
48
+ end
49
+
50
+ private :can_stash
51
+ end
52
+ end
@@ -0,0 +1,3 @@
1
+ module BigStash
2
+ VERSION = '0.1.0'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: big_stash
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mmoaay
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-28 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.15'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.15'
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
+ - !ruby/object:Gem::Dependency
42
+ name: gli
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.16'
55
+ description: Enhancement for git stash that you can give a name to the stash.
56
+ email:
57
+ - mmoaay@sina.com
58
+ executables:
59
+ - big-stash
60
+ - setup
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - ".gitignore"
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - big_stash.gemspec
70
+ - bin/big-stash
71
+ - bin/setup
72
+ - lib/big_stash.rb
73
+ - lib/big_stash/stash_operator.rb
74
+ - lib/big_stash/version.rb
75
+ homepage: https://github.com/mmoaay/big-stash
76
+ licenses:
77
+ - MIT
78
+ metadata:
79
+ allowed_push_host: https://rubygems.org
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.5.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Enhancement for git stash.
100
+ test_files: []