-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce Repository concept along with specs and module refactoring
An initialize file is introduced to aid in loading up the required classes and libraries. A spec_helper and basic specs (for Repository) exists, along with a RepositoryHelper to handle temporary git repos. Refactor classes to use nested modules. Change lib/git_evolution to be a module, thus executables had to change.
- Loading branch information
1 parent
24f6a50
commit 73b534c
Showing
10 changed files
with
79 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
require 'git_evolution' | ||
|
||
GitEvolution.new.run(ARGV) | ||
GitEvolution.run(ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
require 'git_evolution' | ||
|
||
GitEvolution.new.run(ARGV) | ||
GitEvolution.run(ARGV) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
require 'rugged' | ||
|
||
Dir.glob(File.dirname(__FILE__) + '/**/*.rb') { |file| require file } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module GitEvolution | ||
class Repository | ||
def initialize(directory_name) | ||
@git_repo = Rugged::Repository.discover(File.expand_path(directory_name)) | ||
end | ||
|
||
def dir | ||
@git_repo.workdir | ||
end | ||
|
||
def line_history(start_line, end_line, file) | ||
Dir.chdir(dir) do | ||
return `git --no-pager log -L#{start_line},#{end_line}:#{file} --follow #{file}` | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
class GitEvolution | ||
module GitEvolution | ||
VERSION = '0.0.1' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe GitEvolution::Repository do | ||
describe '.new' do | ||
context 'valid repository directory' do | ||
before(:each) { RepositoryHelper.create_repository } | ||
after(:each) { RepositoryHelper.delete_repository } | ||
|
||
it 'detects repository' do | ||
repo = described_class.new(RepositoryHelper.repository_dir) | ||
expect(repo.dir).to eq(RepositoryHelper.repository_dir) | ||
end | ||
end | ||
|
||
context 'invalid repository directory' do | ||
let!(:tmp_dir) { Dir.mktmpdir } | ||
after { FileUtils.rm_r(tmp_dir) } | ||
|
||
it 'detects no repository' do | ||
expect { described_class.new(tmp_dir) }.to raise_error(Rugged::RepositoryError) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
$LOAD_PATH.unshift File.expand_path('../lib', __FILE__) | ||
|
||
Bundler.require(:test) | ||
Bundler.require(:development) | ||
|
||
Dir.glob(Dir.pwd + '/spec/support/**/*.rb') { |file| require file } | ||
|
||
require 'git_evolution/initialize' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module RepositoryHelper | ||
module_function | ||
|
||
def create_repository | ||
@tmp_git_dir = Dir.mktmpdir | ||
Rugged::Repository.init_at(@tmp_git_dir) | ||
end | ||
|
||
def delete_repository | ||
FileUtils.rm_r(@tmp_git_dir) | ||
end | ||
|
||
def repository_dir | ||
File.realpath(@tmp_git_dir) + '/' | ||
end | ||
end |