peacock 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +1 -1
- data/README.md +44 -16
- data/Rakefile +2 -0
- data/lib/git/base.rb +18 -0
- data/lib/git/error.rb +5 -0
- data/lib/git/lib.rb +33 -0
- data/lib/git.rb +50 -0
- data/lib/peacock/{parser.rb → cli.rb} +8 -8
- data/lib/peacock/cli_hash.rb +57 -0
- data/lib/peacock/engine/engine.rb +45 -0
- data/lib/peacock/engine/extractor.rb +64 -0
- data/lib/peacock/engine/ignorer.rb +66 -0
- data/lib/peacock/{peacock_exception.rb → error.rb} +0 -0
- data/lib/peacock/logger.rb +19 -0
- data/lib/peacock/startup_manager.rb +2 -22
- data/lib/peacock/version.rb +1 -1
- data/lib/peacock.rb +9 -8
- data/peacock.gemspec +3 -3
- metadata +17 -11
- data/lib/peacock/ignorer.rb +0 -67
- data/lib/peacock/parse_hash.rb +0 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 84ea91580dc4505136482f503da3b8bc0fb36749
|
4
|
+
data.tar.gz: 1feb55166e087b89c66fa7684debe05f636b1070
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7356035129eec6ba016805660e380f278cab400e7e22f047dbbed419e7ade6402372eec6bd680e96f4076d3d69933555f1b3ad23c9584d4406ec64522739d582
|
7
|
+
data.tar.gz: 28e4d4a38b0a25b201b6374146bfb807af7bba7d16ba87599b0c3b1dce0781e85676dad571b117c8ef602e2649aee69130c18a8b3b72395633314b0794d0d5b7
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,14 +2,15 @@
|
|
2
2
|
|
3
3
|
Peacock is a small tool to easily manage your .gitignore written in ruby.
|
4
4
|
|
5
|
-
|
5
|
+
It lets you ignore and extract files and directories using .gitignore in your current git repository.
|
6
6
|
|
7
|
-
|
8
|
-
and perform a commit before and after you execute peacock.
|
7
|
+
Note that while ignoring files and directories peacock will perform safety commits to make sure your work is not lost. It will commit all your uncommited work (if there is any) before and after adding files to .gitignore.
|
9
8
|
|
10
|
-
|
9
|
+
While extracting, peacock leaves everything untouched.
|
10
|
+
|
11
|
+
Note that at the moment you can't combine options with one hyphen (e.g.: -ev for --extract and --verbose) but you have to pass them separated (e.g.: -e -v)
|
11
12
|
|
12
|
-
|
13
|
+
## Installation
|
13
14
|
|
14
15
|
Install by executing:
|
15
16
|
|
@@ -17,23 +18,50 @@ Install by executing:
|
|
17
18
|
|
18
19
|
## Usage
|
19
20
|
|
20
|
-
Usage:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
-
|
27
|
-
-
|
21
|
+
Usage:
|
22
|
+
|
23
|
+
peacock [options] [files/directories]
|
24
|
+
|
25
|
+
Options:
|
26
|
+
|
27
|
+
-h, [--help] # show this text
|
28
|
+
-r, [--root] # use root .gitignore
|
29
|
+
-v, [--verbose] # surpress output
|
30
|
+
-e, [--extract] # extract file from .gitignore
|
31
|
+
|
32
|
+
## Example
|
33
|
+
|
34
|
+
$ git status
|
35
|
+
...
|
36
|
+
Untracked files:
|
37
|
+
these
|
38
|
+
are
|
39
|
+
some
|
40
|
+
files
|
41
|
+
|
42
|
+
$ peacock are some
|
43
|
+
added are to .gitignore
|
44
|
+
added some to .gitignore
|
45
|
+
|
46
|
+
$ git status
|
47
|
+
On branch master
|
48
|
+
nothing to commit, working directory clean
|
49
|
+
|
50
|
+
$ peacock -e are
|
51
|
+
removed are from .gitignore
|
52
|
+
|
53
|
+
$ git status
|
54
|
+
...
|
55
|
+
Untracked files:
|
56
|
+
are
|
28
57
|
|
58
|
+
|
29
59
|
## TODO
|
30
60
|
|
31
|
-
- ruby-git does not recognize a repo unless you are in the root directory. a different mechanism is needed
|
32
|
-
- implement own small git library for peacock
|
33
|
-
- create a test environment and better tests
|
34
61
|
- add functionalities
|
35
62
|
- custom commit messages
|
36
63
|
- comments in .gitignore
|
64
|
+
- options can't be combined (e.g. -ev for extract and surpress)
|
37
65
|
|
38
66
|
## Contributing
|
39
67
|
|
data/Rakefile
CHANGED
data/lib/git/base.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
module Git
|
2
|
+
class Base
|
3
|
+
|
4
|
+
# wrapper for command method which returns the output
|
5
|
+
def self.command_output(command = '', opts = '')
|
6
|
+
f = command(command, opts)
|
7
|
+
output = f.readlines.join
|
8
|
+
f.close
|
9
|
+
output
|
10
|
+
end
|
11
|
+
|
12
|
+
# wrapper for git commands
|
13
|
+
def self.command(command = '', opts = '')
|
14
|
+
IO.popen("git #{command} #{opts} 2>&1") # 2>&1 surpresses stderr
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
data/lib/git/error.rb
ADDED
data/lib/git/lib.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# Available Git commands
|
2
|
+
module Git
|
3
|
+
|
4
|
+
module Lib
|
5
|
+
|
6
|
+
def self.git
|
7
|
+
Git::Base.command_output
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.init
|
11
|
+
Git::Base.command_output('init')
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.status
|
15
|
+
Git::Base.command_output('status')
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.commit_all(message)
|
19
|
+
Git::Base.command_output('add', '-A')
|
20
|
+
Git::Base.command_output('commit', "-m '#{message}'")
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.clear_cache
|
24
|
+
Git::Base.command_output('rm', '-r --cached .')
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.log
|
28
|
+
Git::Base.command_output('log')
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/git.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'git/base'
|
2
|
+
require 'git/error'
|
3
|
+
require 'git/lib'
|
4
|
+
|
5
|
+
module Git
|
6
|
+
|
7
|
+
# checks if git is installed
|
8
|
+
def self.check_git_existance
|
9
|
+
output = git
|
10
|
+
|
11
|
+
unless /\Ausage: git/ =~ output
|
12
|
+
raise NoGitInstalledError, 'git was not found. make sure you have it installed'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# checks if current directory is a git repository
|
17
|
+
def self.check_repo_existance
|
18
|
+
output = status
|
19
|
+
|
20
|
+
unless /\AOn branch/ =~ output
|
21
|
+
raise NoGitRepositoryError, 'you are not in a git repository.'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# so Git calls follow the Git.<command> pattern
|
26
|
+
def self.git
|
27
|
+
Git::Lib.git
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.init
|
31
|
+
Git::Lib.init
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.status
|
35
|
+
Git::Lib.status
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.commit_all(message)
|
39
|
+
Git::Lib.commit_all(message)
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.clear_cache
|
43
|
+
Git::Lib.clear_cache
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.log
|
47
|
+
Git::Lib.log
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
module Peacock
|
2
2
|
|
3
|
-
class
|
3
|
+
class CLI
|
4
4
|
|
5
5
|
def self.parse
|
6
|
-
parser =
|
6
|
+
parser = CLI.new
|
7
7
|
parser.check_if_help_text
|
8
|
-
parser.parse_args
|
8
|
+
parser.parse_args
|
9
9
|
end
|
10
10
|
|
11
11
|
def parse_args
|
12
|
-
return_hash = Peacock::
|
12
|
+
return_hash = Peacock::CLIHash.new
|
13
13
|
|
14
14
|
ARGV.each do |arg|
|
15
15
|
type = determine_type arg
|
@@ -49,14 +49,14 @@ module Peacock
|
|
49
49
|
|
50
50
|
Options:
|
51
51
|
\t-h, [--help] # show this text
|
52
|
-
\t-r, [--root] # use root .gitignore
|
53
|
-
\t-
|
54
|
-
\t-
|
52
|
+
\t-r, [--root] # use root .gitignore
|
53
|
+
\t-v, [--verbose] # surpress output
|
54
|
+
\t-e, [--extract] # extract file from .gitignore
|
55
55
|
EOF
|
56
56
|
end
|
57
57
|
|
58
58
|
def options
|
59
|
-
|
59
|
+
%w(-r --root -e --extract -v --verbose)
|
60
60
|
end
|
61
61
|
|
62
62
|
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Peacock
|
2
|
+
|
3
|
+
class CLIHash
|
4
|
+
|
5
|
+
attr_reader :hash
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@hash = Hash.new
|
9
|
+
@hash[:opts] = Array.new
|
10
|
+
@hash[:files] = Array.new
|
11
|
+
@hash[:dirs] = Array.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def push(type, str)
|
15
|
+
if type == :dirs
|
16
|
+
str = str + '/' unless str =~ /\/$/ # add backlash to dir name if it does not exist yet
|
17
|
+
str = '/' + str unless str =~ /^\// # add backlash to beginning of dir name if it does not exist yet
|
18
|
+
end
|
19
|
+
|
20
|
+
@hash[type].push(str)
|
21
|
+
end
|
22
|
+
|
23
|
+
def opts
|
24
|
+
@hash[:opts]
|
25
|
+
end
|
26
|
+
|
27
|
+
def files
|
28
|
+
@hash[:files]
|
29
|
+
end
|
30
|
+
|
31
|
+
def dirs
|
32
|
+
@hash[:dirs]
|
33
|
+
end
|
34
|
+
|
35
|
+
def to_s
|
36
|
+
hash.to_s
|
37
|
+
end
|
38
|
+
|
39
|
+
def root_ignore?
|
40
|
+
opts.include?('-r') || opts.include?('--root')
|
41
|
+
end
|
42
|
+
|
43
|
+
def verbose?
|
44
|
+
opts.include?('-v') || opts.include?('--verbose')
|
45
|
+
end
|
46
|
+
|
47
|
+
def engine
|
48
|
+
if opts.include?('-e')
|
49
|
+
return Peacock::Engine::Extractor
|
50
|
+
else
|
51
|
+
return Peacock::Engine::Ignorer
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
# some general engine code
|
2
|
+
|
3
|
+
module Peacock
|
4
|
+
|
5
|
+
module Engine
|
6
|
+
|
7
|
+
def self.execute(opt_hash)
|
8
|
+
opt_hash.engine.start_engine(opt_hash) # opt_hash.engine returns the engine as a class on which we will call the general method start_engine
|
9
|
+
end
|
10
|
+
|
11
|
+
module Engine
|
12
|
+
|
13
|
+
def check_and_return_hash(opt_hash)
|
14
|
+
raise PeacockError, '#{self.class} expects an instance of Peacock::CLIHash' unless opt_hash.class == CLIHash
|
15
|
+
opt_hash
|
16
|
+
end
|
17
|
+
|
18
|
+
def determine_git_ignore_path
|
19
|
+
if @hash.root_ignore?
|
20
|
+
determine_root_dir
|
21
|
+
else
|
22
|
+
'.gitignore'
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def determine_root_dir
|
27
|
+
old_path = Dir.pwd
|
28
|
+
while not Dir.exists? '.git'
|
29
|
+
Dir.chdir '..'
|
30
|
+
end
|
31
|
+
|
32
|
+
path = Dir.pwd() + '/.gitignore'
|
33
|
+
Dir.chdir(old_path)
|
34
|
+
path
|
35
|
+
end
|
36
|
+
|
37
|
+
def git_ignore_exists?(path)
|
38
|
+
raise PeacockError, '#{self.class} expects .gitignore to exist at #{path}' unless File.exists?(path)
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
module Peacock
|
2
|
+
|
3
|
+
module Engine
|
4
|
+
|
5
|
+
class Extractor
|
6
|
+
include Peacock::Engine::Engine
|
7
|
+
|
8
|
+
def self.start_engine(opt_hash)
|
9
|
+
extractor = Extractor.new(opt_hash)
|
10
|
+
extractor.workflow
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(opt_hash)
|
14
|
+
@hash = check_and_return_hash(opt_hash)
|
15
|
+
@logger = Peacock::Logger.new(@hash.verbose?)
|
16
|
+
path = determine_git_ignore_path
|
17
|
+
git_ignore_exists?(path)
|
18
|
+
|
19
|
+
# open in mode read-write (beginning of file)
|
20
|
+
@git_ignore = File.open(path, 'r')
|
21
|
+
end
|
22
|
+
|
23
|
+
def workflow
|
24
|
+
extract_files_and_directories
|
25
|
+
@git_ignore.close
|
26
|
+
end
|
27
|
+
|
28
|
+
def extract_files_and_directories
|
29
|
+
delete_list = []
|
30
|
+
ignore_lines = @git_ignore.readlines
|
31
|
+
|
32
|
+
# determine delete_list (cant use delete_if cause of logger logic)
|
33
|
+
determine_delete_list(ignore_lines, delete_list)
|
34
|
+
|
35
|
+
delete_list.each do |entry|
|
36
|
+
ignore_lines.delete_at(entry)
|
37
|
+
end
|
38
|
+
|
39
|
+
# reopen in writable mode and input all new git ignore entries
|
40
|
+
@git_ignore.reopen(@git_ignore.path, 'w')
|
41
|
+
|
42
|
+
ignore_lines.each do |line|
|
43
|
+
@git_ignore.write(line)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def determine_delete_list(ignore_lines, delete_list)
|
48
|
+
ignore_lines.each_with_index do |line,index|
|
49
|
+
if hash_includes_line?(line)
|
50
|
+
delete_list.push(index)
|
51
|
+
@logger.extract(line.chomp("\n"))
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def hash_includes_line?(line)
|
57
|
+
@hash.dirs.include?(line.chomp("\n")) || @hash.files.include?(line.chomp("\n"))
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Peacock
|
2
|
+
|
3
|
+
module Engine
|
4
|
+
|
5
|
+
class Ignorer
|
6
|
+
include Peacock::Engine::Engine
|
7
|
+
|
8
|
+
def self.start_engine(opt_hash)
|
9
|
+
ignorer = Ignorer.new(opt_hash)
|
10
|
+
ignorer.workflow
|
11
|
+
end
|
12
|
+
|
13
|
+
def initialize(opt_hash)
|
14
|
+
@hash = check_and_return_hash(opt_hash)
|
15
|
+
@logger = Peacock::Logger.new(@hash.verbose?)
|
16
|
+
path = determine_git_ignore_path
|
17
|
+
@git_ignore = File.open(path, 'a+')
|
18
|
+
end
|
19
|
+
|
20
|
+
def workflow
|
21
|
+
Git.commit_all('peacock: before .gitignore commit')
|
22
|
+
ignore_files_and_directories
|
23
|
+
Git.clear_cache
|
24
|
+
Git.commit_all('peacock: after .gitignore commit')
|
25
|
+
@git_ignore.close
|
26
|
+
end
|
27
|
+
|
28
|
+
def ignore_files_and_directories
|
29
|
+
ignore_files
|
30
|
+
ignore_directories
|
31
|
+
end
|
32
|
+
|
33
|
+
def ignore_directories
|
34
|
+
@hash.dirs.each do |dir|
|
35
|
+
check_and_write(dir)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def ignore_files
|
40
|
+
@hash.files.each do |file|
|
41
|
+
check_and_write(file)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_and_write(str)
|
46
|
+
unless entry_exists?(str)
|
47
|
+
@git_ignore.write(str + "\n")
|
48
|
+
@logger.ignore(str)
|
49
|
+
end
|
50
|
+
|
51
|
+
@git_ignore.rewind
|
52
|
+
end
|
53
|
+
|
54
|
+
def entry_exists?(entry)
|
55
|
+
@git_ignore.each do |line|
|
56
|
+
return true if line.chomp == entry
|
57
|
+
end
|
58
|
+
false
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
File without changes
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Peacock
|
2
|
+
|
3
|
+
class Logger
|
4
|
+
|
5
|
+
def initialize(verbose)
|
6
|
+
@verbose = verbose
|
7
|
+
end
|
8
|
+
|
9
|
+
def ignore(string)
|
10
|
+
puts "added #{string} to .gitignore" unless @verbose
|
11
|
+
end
|
12
|
+
|
13
|
+
def extract(string)
|
14
|
+
puts "removed #{string} from .gitignore" unless @verbose
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -3,28 +3,8 @@ module Peacock
|
|
3
3
|
class StartupManager
|
4
4
|
|
5
5
|
def self.check_peacock_requirements
|
6
|
-
|
7
|
-
|
8
|
-
begin
|
9
|
-
startup.check_git_repository
|
10
|
-
rescue PeacockError
|
11
|
-
puts 'An error occured. Make sure you are in a git repository and git is installed.'
|
12
|
-
exit 1
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
def check_git_repository
|
17
|
-
raise PeacockError unless git_repository?
|
18
|
-
end
|
19
|
-
|
20
|
-
# checks if current directory is a git repository
|
21
|
-
def git_repository?
|
22
|
-
begin
|
23
|
-
Git.open Dir.pwd
|
24
|
-
true
|
25
|
-
rescue
|
26
|
-
false
|
27
|
-
end
|
6
|
+
Git.check_git_existance
|
7
|
+
Git.check_repo_existance
|
28
8
|
end
|
29
9
|
|
30
10
|
end
|
data/lib/peacock/version.rb
CHANGED
data/lib/peacock.rb
CHANGED
@@ -1,20 +1,21 @@
|
|
1
1
|
require 'git'
|
2
|
-
require '
|
3
|
-
|
2
|
+
require 'peacock/logger'
|
4
3
|
require 'peacock/version'
|
5
|
-
require 'peacock/
|
4
|
+
require 'peacock/error'
|
6
5
|
require 'peacock/startup_manager'
|
7
|
-
require 'peacock/
|
8
|
-
require 'peacock/
|
9
|
-
require 'peacock/
|
6
|
+
require 'peacock/cli_hash'
|
7
|
+
require 'peacock/cli'
|
8
|
+
require 'peacock/engine/engine'
|
9
|
+
require 'peacock/engine/extractor'
|
10
|
+
require 'peacock/engine/ignorer'
|
10
11
|
|
11
12
|
|
12
13
|
module Peacock
|
13
14
|
|
14
15
|
def self.execute
|
16
|
+
cli_hash = Peacock::CLI.parse
|
15
17
|
Peacock::StartupManager.check_peacock_requirements
|
16
|
-
|
17
|
-
Peacock::Ignorer.ignore(parse_hash)
|
18
|
+
Peacock::Engine.execute(cli_hash)
|
18
19
|
end
|
19
20
|
|
20
21
|
end
|
data/peacock.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Christian Paling"]
|
10
10
|
spec.email = ["christian.paling@googlemail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{Peacock
|
13
|
-
spec.description = %q{
|
12
|
+
spec.summary = %q{Peacock is a small tool to easily manage your .gitignore}
|
13
|
+
spec.description = %q{Peacock is a small tool to easily manage your .gitignore}
|
14
14
|
spec.homepage = "https://github.com/bakku/peacock"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -21,5 +21,5 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_development_dependency "bundler", "~> 1.9"
|
23
23
|
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
-
spec.add_development_dependency "
|
24
|
+
spec.add_development_dependency "minitest"
|
25
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peacock
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christian Paling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-11-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '10.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -52,7 +52,7 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
description:
|
55
|
+
description: Peacock is a small tool to easily manage your .gitignore
|
56
56
|
email:
|
57
57
|
- christian.paling@googlemail.com
|
58
58
|
executables:
|
@@ -67,11 +67,18 @@ files:
|
|
67
67
|
- README.md
|
68
68
|
- Rakefile
|
69
69
|
- exe/peacock
|
70
|
+
- lib/git.rb
|
71
|
+
- lib/git/base.rb
|
72
|
+
- lib/git/error.rb
|
73
|
+
- lib/git/lib.rb
|
70
74
|
- lib/peacock.rb
|
71
|
-
- lib/peacock/
|
72
|
-
- lib/peacock/
|
73
|
-
- lib/peacock/
|
74
|
-
- lib/peacock/
|
75
|
+
- lib/peacock/cli.rb
|
76
|
+
- lib/peacock/cli_hash.rb
|
77
|
+
- lib/peacock/engine/engine.rb
|
78
|
+
- lib/peacock/engine/extractor.rb
|
79
|
+
- lib/peacock/engine/ignorer.rb
|
80
|
+
- lib/peacock/error.rb
|
81
|
+
- lib/peacock/logger.rb
|
75
82
|
- lib/peacock/startup_manager.rb
|
76
83
|
- lib/peacock/version.rb
|
77
84
|
- peacock.gemspec
|
@@ -95,9 +102,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
95
102
|
version: '0'
|
96
103
|
requirements: []
|
97
104
|
rubyforge_project:
|
98
|
-
rubygems_version: 2.4.5
|
105
|
+
rubygems_version: 2.4.5.1
|
99
106
|
signing_key:
|
100
107
|
specification_version: 4
|
101
|
-
summary: Peacock
|
102
|
-
to .gitignore
|
108
|
+
summary: Peacock is a small tool to easily manage your .gitignore
|
103
109
|
test_files: []
|
data/lib/peacock/ignorer.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
module Peacock
|
2
|
-
|
3
|
-
class Ignorer
|
4
|
-
|
5
|
-
def self.ignore(opt_hash)
|
6
|
-
ignorer = Ignorer.new(opt_hash)
|
7
|
-
ignorer.commit_all('peacock: before .gitignore commit')
|
8
|
-
ignorer.ignore_files_and_directories
|
9
|
-
ignorer.clear_cache
|
10
|
-
ignorer.commit_all('peacock: after .gitignore commit')
|
11
|
-
end
|
12
|
-
|
13
|
-
def initialize(opt_hash)
|
14
|
-
@hash = opt_hash
|
15
|
-
@git_ignore = File.open('.gitignore', 'a+')
|
16
|
-
@repo = Git.open Dir.pwd
|
17
|
-
end
|
18
|
-
|
19
|
-
def clear_cache
|
20
|
-
# totally ugly, but ruby-git does not support git rm -r --cached
|
21
|
-
Open3.popen3('git rm -r --cached .') do |stdin, stdout, stderr, thread|
|
22
|
-
# ignore output
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def commit_all(message)
|
27
|
-
begin
|
28
|
-
@repo.add(all: true)
|
29
|
-
@repo.commit_all(message)
|
30
|
-
rescue
|
31
|
-
# do nothing
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
def ignore_files_and_directories
|
36
|
-
ignore_files
|
37
|
-
ignore_directories
|
38
|
-
end
|
39
|
-
|
40
|
-
def ignore_directories
|
41
|
-
@hash[:dirs].each do |dir|
|
42
|
-
dir = dir + '/' unless dir =~ /\/$/ # add backlash to dir name if it does not exist yet
|
43
|
-
check_and_write(dir)
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def ignore_files
|
48
|
-
@hash[:files].each do |file|
|
49
|
-
check_and_write(file)
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
def check_and_write(str)
|
54
|
-
@git_ignore.write(str + "\n") unless entry_exists?(str)
|
55
|
-
@git_ignore.rewind
|
56
|
-
end
|
57
|
-
|
58
|
-
def entry_exists?(entry)
|
59
|
-
@git_ignore.each do |line|
|
60
|
-
return true if line.chomp == entry
|
61
|
-
end
|
62
|
-
false
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
data/lib/peacock/parse_hash.rb
DELETED
@@ -1,24 +0,0 @@
|
|
1
|
-
module Peacock
|
2
|
-
|
3
|
-
class ParseHash
|
4
|
-
|
5
|
-
attr_reader :hash
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@hash = Hash.new
|
9
|
-
@hash[:opts] = Array.new
|
10
|
-
@hash[:files] = Array.new
|
11
|
-
@hash[:dirs] = Array.new
|
12
|
-
end
|
13
|
-
|
14
|
-
def push(type, str)
|
15
|
-
@hash[type].push(str)
|
16
|
-
end
|
17
|
-
|
18
|
-
def to_s
|
19
|
-
hash.to_s
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|