modifiles 0.0.2

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --format documentation --color
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rspec'
4
+
5
+ # Specify your gem's dependencies in modifiles.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 masaori
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.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # Modifiles
2
+
3
+ Check and detect modified files using `git diff`.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'modifiles'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install modifiles
18
+
19
+ ## Usage
20
+
21
+ Stamp first:
22
+
23
+ Modifiles::Checker.stamp_file_path = '/your/stamp/file_path'
24
+ Modifiles::Checker.stamp # Record latest git commit SHA
25
+
26
+ Collect modified files after some commits:
27
+
28
+ Modifiles::Checker.modified_files # => ['/GIT_ROOT/files_modified', '/GIT_ROOT/since', '/GIT_ROOT/latest_commit_stamp']
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,57 @@
1
+ require 'pathname'
2
+
3
+ module Modifiles
4
+
5
+ class Checker
6
+
7
+ class << self
8
+ attr_accessor :stamp_file_path
9
+
10
+ def stamp
11
+ File.open(@stamp_file_path, "w") { |io| io.write `git log -1 --pretty=format:%H` }
12
+ end
13
+
14
+ def last_stamp
15
+ if File.exists? @stamp_file_path
16
+ File.open(@stamp_file_path) { |io| io.read }
17
+ else
18
+ `git log --pretty=format:%H | tail -1`
19
+ end
20
+ end
21
+
22
+ def diff_list(filter=nil)
23
+ if filter
24
+ `git diff --name-only --diff-filter=#{filter} #{last_stamp} HEAD`.split("\n").map {|e| File.join(GIT_ROOT, e)}
25
+ else
26
+ `git diff --name-only #{last_stamp} HEAD`.split("\n").map {|e| File.join(GIT_ROOT, e)}
27
+ end
28
+ end
29
+
30
+ def modified_files
31
+ diff_list('M')
32
+ end
33
+
34
+ def added_files
35
+ diff_list('A')
36
+ end
37
+
38
+ def deleted_files
39
+ diff_list('D')
40
+ end
41
+
42
+ def modified?(file_path)
43
+ modified_files.include? file_path
44
+ end
45
+
46
+ def added?(file_path)
47
+ added_files.include? file_path
48
+ end
49
+
50
+ def deleted?(file_path)
51
+ deleted_files.include? file_path
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,3 @@
1
+ module Modifiles
2
+ VERSION = "0.0.2"
3
+ end
data/lib/modifiles.rb ADDED
@@ -0,0 +1,6 @@
1
+ require "modifiles/version"
2
+ require "modifiles/checker"
3
+
4
+ module Modifiles
5
+ # Your code goes here...
6
+ end
data/modifiles.gemspec ADDED
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'modifiles/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "modifiles"
8
+ gem.version = Modifiles::VERSION
9
+ gem.authors = ["masaori"]
10
+ gem.email = ["masaori@pankaku.com"]
11
+ gem.description = "Check and detect modified files using `git diff`"
12
+ gem.summary = "Check and detect modified files using `git diff`"
13
+ gem.homepage = ""
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
data/spec/.DS_Store ADDED
Binary file
@@ -0,0 +1,82 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require_relative 'spec_helper'
4
+
5
+ describe Modifiles::Checker do
6
+ before do
7
+ @root_path = File.dirname(File.expand_path("#{__FILE__}/../"))
8
+ @stamp_file_path = File.join(File.dirname(__FILE__), 'test_sha1.txt');
9
+ @base_sha1 = 'c47ff4646902feb0a1ebd14309c7919dc5246ca6'
10
+
11
+ File.open(@stamp_file_path, "w") { |io| io.write @base_sha1 }
12
+
13
+ Modifiles::Checker.stamp_file_path = @stamp_file_path
14
+
15
+ @added = `git diff --name-only --diff-filter=A #{@base_sha1} HEAD`.split("\n").map {|e| File.join(GIT_ROOT, e)}
16
+ @deleted = `git diff --name-only --diff-filter=D #{@base_sha1} HEAD`.split("\n").map {|e| File.join(GIT_ROOT, e)}
17
+ @modified = `git diff --name-only --diff-filter=M #{@base_sha1} HEAD`.split("\n").map {|e| File.join(GIT_ROOT, e)}
18
+ end
19
+
20
+ describe '#stamp' do
21
+ it 'records latest commit SHA1' do
22
+ Modifiles::Checker.stamp
23
+ Modifiles::Checker.last_stamp.should eql `git log -1 --pretty=format:%H`
24
+ end
25
+ end
26
+
27
+ describe '#last_stamp' do
28
+ it 'returns the latest recorded commit SHA1' do
29
+ Modifiles::Checker.last_stamp.should eql @base_sha1
30
+ end
31
+
32
+ context 'when stamp file does not exist' do
33
+ before do
34
+ File.delete(@stamp_file_path) if File.exists?(@stamp_file_path)
35
+ end
36
+
37
+ it 'returns SHA1 of the first commit' do
38
+ Modifiles::Checker.last_stamp.should eql `git log --pretty=format:%H | tail -1`
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '#added_files' do
44
+ it 'returns new added files(absolute path) since latest stamp.' do
45
+ Modifiles::Checker.added_files.each {|e| @added.should include e}
46
+ Modifiles::Checker.added_files.length.should eql @added.length
47
+ end
48
+ end
49
+
50
+ describe '#modified_files' do
51
+ it 'returns new modified files(absolute path) since latest stamp.' do
52
+ Modifiles::Checker.modified_files.each {|e| @modified.should include e}
53
+ Modifiles::Checker.modified_files.length.should eql @modified.length
54
+ end
55
+ end
56
+
57
+ describe '#deleted_files' do
58
+ it 'returns new deleted files(absolute path) since latest stamp.' do
59
+ Modifiles::Checker.deleted_files.each {|e| @deleted.should include e}
60
+ Modifiles::Checker.deleted_files.length.should eql @deleted.length
61
+ end
62
+ end
63
+
64
+ describe '#added?' do
65
+ it 'checks if the given file has been added after last_stamp commit' do
66
+ @added.each {|e| Modifiles::Checker.added?(e).should be_true }
67
+ end
68
+ end
69
+
70
+ describe '#modified?' do
71
+ it 'checks if the given file has been modified after last_stamp commit' do
72
+ @modified.each {|e| Modifiles::Checker.modified?(e).should be_true }
73
+ end
74
+ end
75
+
76
+ describe '#deleted?' do
77
+ it 'checks if the given file has been deleted after last_stamp commit' do
78
+ @deleted.each {|e| Modifiles::Checker.deleted?(e).should be_true }
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1 @@
1
+ require File.expand_path "#{File.basename(__FILE__)}/../lib/modifiles.rb"
@@ -0,0 +1 @@
1
+ c47ff4646902feb0a1ebd14309c7919dc5246ca6
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: modifiles
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - masaori
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-19 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Check and detect modified files using `git diff`
15
+ email:
16
+ - masaori@pankaku.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - .rspec
23
+ - .rvmrc
24
+ - Gemfile
25
+ - LICENSE.txt
26
+ - README.md
27
+ - Rakefile
28
+ - lib/modifiles.rb
29
+ - lib/modifiles/checker.rb
30
+ - lib/modifiles/version.rb
31
+ - modifiles.gemspec
32
+ - spec/.DS_Store
33
+ - spec/checker_spec.rb
34
+ - spec/spec_helper.rb
35
+ - spec/test_sha1.txt
36
+ homepage: ''
37
+ licenses: []
38
+ post_install_message:
39
+ rdoc_options: []
40
+ require_paths:
41
+ - lib
42
+ required_ruby_version: !ruby/object:Gem::Requirement
43
+ none: false
44
+ requirements:
45
+ - - ! '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ requirements: []
55
+ rubyforge_project:
56
+ rubygems_version: 1.8.25
57
+ signing_key:
58
+ specification_version: 3
59
+ summary: Check and detect modified files using `git diff`
60
+ test_files:
61
+ - spec/.DS_Store
62
+ - spec/checker_spec.rb
63
+ - spec/spec_helper.rb
64
+ - spec/test_sha1.txt
65
+ has_rdoc: