Skip to content
This repository has been archived by the owner on Dec 5, 2019. It is now read-only.

Correctly update repo to latest or requested version when cleaning git working dir #101

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/source_control/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def clean_checkout(revision = nil, stdout = $stdout)
# (-d) Directory clean
# (-q) Quiet, prevent git from writing unnecessary information to stdout/stderr
git('clean', ['-q', '-d', '-f'])
update(revision || latest_revision)
end

def latest_revision
Expand Down
6 changes: 6 additions & 0 deletions test/integration/git_integration_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def test_clean_checkout_should_not_remove_tracked_files
FileUtils.touch tracked_file
sandbox_git_add_and_commit(proj_dir, File.basename(tracked_file))
untracked_file = File.join(proj_dir, 'untracked.txt')
git.expects(:latest_revision).returns(:foo)
git.expects(:update).with(:foo)
git.clean_checkout
assert File.exist? tracked_file
assert_false File.exist? untracked_file
Expand All @@ -27,6 +29,8 @@ def test_clean_checkout_should_remove_untracked_directories
with_sandboxed_git do |proj_dir, git|
untracked_dirs = File.join(proj_dir, 'untracked/by/git')
FileUtils.mkdir_p untracked_dirs
git.expects(:latest_revision).returns(:foo)
git.expects(:update).with(:foo)
git.clean_checkout
assert_false File.directory? untracked_dirs
end
Expand All @@ -36,6 +40,8 @@ def test_clean_checkout_should_remove_untracked_files
with_sandboxed_git do |proj_dir, git|
untracked_file = File.join(proj_dir, 'untracked.txt')
FileUtils.touch untracked_file
git.expects(:latest_revision).returns(:foo)
git.expects(:update).with(:foo)
git.clean_checkout
assert_false File.exist? untracked_file
end
Expand Down
2 changes: 2 additions & 0 deletions test/unit/source_control/git_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ def test_clean_checkout_should_perform_git_clean
in_sandbox do
git = new_git(:repository => "git:/my_repo")
git.expects(:git).with("clean", ['-q', '-d', '-f'])
git.expects(:latest_revision).returns(:foo)
git.expects(:update).with(:foo)
git.clean_checkout
end
end
Expand Down