-
Notifications
You must be signed in to change notification settings - Fork 3
Add dotfiles option #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,59 @@ | ||
require "rspec" | ||
require "rails/diff/cli" | ||
|
||
RSpec.describe Rails::Diff::CLI do | ||
let(:cli) { described_class.new } | ||
let(:mock_diff) { "Mocked diff output" } | ||
|
||
before do | ||
allow(Rails::Diff).to receive(:file).and_return(mock_diff) | ||
end | ||
|
||
describe "#file" do | ||
context "when no files are provided" do | ||
it "aborts with an error message" do | ||
expect { cli.file }.to raise_error(SystemExit, "Please provide at least one file to compare") | ||
end | ||
end | ||
|
||
context "when files are provided" do | ||
it "outputs the diff if differences exist" do | ||
expect { cli.file("file1.rb", "file2.rb") }.to output("#{mock_diff}\n").to_stdout | ||
end | ||
|
||
it "aborts if differences exist and fail option is set" do | ||
cli.options = { fail: true } | ||
expect { cli.file("file1.rb", "file2.rb") }.to raise_error(SystemExit, mock_diff) | ||
end | ||
end | ||
end | ||
|
||
describe "#dotfiles" do | ||
let(:mock_dotfiles) { [".env", ".gitignore"] } | ||
|
||
before do | ||
allow(Dir).to receive(:glob).with("**/.*").and_return(mock_dotfiles) | ||
allow(mock_dotfiles).to receive(:reject).and_return(mock_dotfiles) | ||
end | ||
|
||
context "when no dotfiles are found" do | ||
before do | ||
allow(Dir).to receive(:glob).with("**/.*").and_return([]) | ||
end | ||
|
||
it "does not output anything" do | ||
expect { cli.dotfiles }.to_not output.to_stdout | ||
end | ||
end | ||
|
||
context "when dotfiles are found and differences exist" do | ||
before do | ||
allow(Rails::Diff).to receive(:file).and_return(mock_diff) | ||
end | ||
|
||
it "outputs the diff" do | ||
expect { cli.dotfiles }.to output("#{mock_diff}\n").to_stdout | ||
end | ||
end | ||
end | ||
end |
This file contains hidden or 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 |
---|---|---|
|
@@ -4,28 +4,38 @@ | |
class GitRepo | ||
attr_reader :remote_repo, :commits | ||
|
||
# Executes a shell command, suppressing output if successful, but capturing errors if it fails | ||
def run_command(command) | ||
result = `#{command} 2>&1` | ||
raise "Command failed: #{result}" unless $?.success? | ||
result | ||
end | ||
|
||
# Initializes and creates a bare remote repo and a working repo with main branch | ||
def initialize | ||
@remote_dir = Dir.mktmpdir | ||
@remote_repo = File.join(@remote_dir, "origin.git") | ||
Dir.chdir(@remote_dir) { `git init --bare --initial-branch=main origin.git > /dev/null 2>&1` } | ||
|
||
|
||
run_command("git init --bare #{@remote_repo}") | ||
|
||
Dir.chdir(@remote_repo) do | ||
`git symbolic-ref HEAD refs/heads/main` | ||
end | ||
|
||
@commits = [] | ||
@work_dir = Dir.mktmpdir | ||
Dir.chdir(@work_dir) do | ||
`git clone #{@remote_repo} . > /dev/null 2>&1` | ||
`git checkout -b main > /dev/null 2>&1` | ||
run_command("git clone #{@remote_repo} .") | ||
run_command("git checkout -b main") | ||
FileUtils.mkdir_p("railties") | ||
File.write("railties/README", "keep") | ||
`git add railties > /dev/null 2>&1` | ||
run_command("git add railties") | ||
|
||
`git config user.email '[email protected]'` | ||
`git config user.name 'Test User'` | ||
run_command("git config user.email '[email protected]'") | ||
run_command("git config user.name 'Test User'") | ||
|
||
commit_result = `git commit -m "add railties dir" 2>&1` | ||
raise "Initial commit failed: #{commit_result}" unless $?.success? | ||
@commits << `git rev-parse HEAD`.strip | ||
`git push -u origin main > /dev/null 2>&1` | ||
commit_result = run_command("git commit -m 'add railties dir'") | ||
@commits << run_command("git rev-parse HEAD").strip | ||
end | ||
end | ||
|
||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't exactly what I had in mind. It should be all dotfiles in the toplevel dir. It should also include files inside folders like
.github
and similar.I'd like to reject files in .gitignore too.
Maybe we should delegate this to Git?
git ls-files --cached --others --exclude-standard -- '.*'