-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
12 changed files
with
224 additions
and
96 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
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
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
Large diffs are not rendered by default.
Oops, something went wrong.
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,51 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe PathList do | ||
within_temp_dir | ||
|
||
let(:root) { Dir.pwd } | ||
|
||
shared_examples 'gitignore' do | ||
let(:parent_repo) { RealGit.new('./parent_repo') } | ||
let(:submodule_foo) { RealGit.new('./submodule_foo') } | ||
let(:submodule_bar) { RealGit.new('./submodule_bar') } | ||
|
||
before do | ||
submodule_bar.commit('--allow-empty') | ||
submodule_foo.add_submodule(submodule_bar.path) | ||
submodule_foo.commit | ||
parent_repo.add_submodule(submodule_foo.path) | ||
end | ||
|
||
# NOTE: .git is a file when a submodule | ||
it 'ignore .git in submodule' do | ||
subject | ||
|
||
Dir.chdir(parent_repo.path) do | ||
expect(subject).to match_files( | ||
'.git/WHATEVER', | ||
'submodule_foo/.git', | ||
'submodule_foo/submodule_bar/.git', | ||
'fake_submodule/.git', | ||
'fake_other_repo/.git/WHATEVER' | ||
) | ||
|
||
expect(subject).not_to match_files( | ||
'.gitmodules', 'submodule_foo/.gitmodules', 'WHATEVER' | ||
) | ||
end | ||
end | ||
end | ||
|
||
describe '.gitignore' do | ||
subject { described_class.gitignore(root: './parent') } | ||
|
||
it_behaves_like 'gitignore' | ||
end | ||
|
||
describe 'git ls-files', :real_git do | ||
subject { parent_repo } | ||
|
||
it_behaves_like 'gitignore' | ||
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
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 was deleted.
Oops, something went wrong.
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,66 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'tempfile' | ||
|
||
class RealGit | ||
attr_reader :path | ||
|
||
def initialize(path = '.') | ||
@path = ::File.expand_path(path) | ||
FileUtils.mkpath(@path) | ||
git('init') | ||
end | ||
|
||
def git(*subcommand, chdir: @path, out: File::NULL, err: File::NULL, **options) | ||
system( | ||
'git', | ||
'-c', "core.hooksPath=''", | ||
'-c', "core.excludesFile=''", | ||
*subcommand, | ||
out: out, | ||
err: err, | ||
chdir: chdir, | ||
**options | ||
) | ||
end | ||
|
||
def add(*args) | ||
git('add', '.', *args) | ||
end | ||
|
||
def commit(*args) | ||
add | ||
git('commit', '-m', 'Commit', *args) | ||
end | ||
|
||
def add_submodule(path) | ||
git('submodule', 'add', path) | ||
fetch_submodules | ||
end | ||
|
||
def fetch_submodules | ||
git('submodule', 'update', '--remote', '--merge', '--init', '--recursive') | ||
end | ||
|
||
def ls_files | ||
out = Tempfile.new('ls-fils-output') | ||
# unfortunately git likes to output path names with quotes and escaped backslashes. | ||
# we need the string without quotes and without escaped backslashes. | ||
git('ls-files', '--recurse-submodules', '-z', out: out) | ||
out.rewind | ||
out.read.split("\0") | ||
.map do |path| | ||
next path unless path[0] == '"' && path[-1] == '"' | ||
|
||
path[1..-2].gsub('\\\\', '\\') | ||
end | ||
ensure | ||
out.close | ||
out.unlink | ||
end | ||
|
||
def to_a | ||
add('-N') | ||
ls_files | ||
end | ||
end |