Skip to content

Commit

Permalink
Recover scripts when git clone fails for dirty dir
Browse files Browse the repository at this point in the history
Fixes #6
  • Loading branch information
spajus committed Dec 25, 2013
1 parent 611d54b commit 675a594
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/models/git_sync.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ def init
temp = File.join(Dir.tmpdir, 'script_migrate')
FileUtils.mkdir_p(temp)
Shell.system "mv -f #{repo_dir}/* #{temp}"
Git.clone(repo, repo_name, path: repo_parent_dir)
Shell.system "mv -f #{temp}/* #{repo_dir}"
Shell.system "rm -rf #{temp}"
begin
Git.clone(repo, repo_name, path: repo_parent_dir)
ensure
Shell.system "mv -f #{temp}/* #{repo_dir}"
Shell.system "rm -rf #{temp}"
end
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/models/git_sync_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,22 @@
end

specify { subject }

context 'scripts moved back after git error' do
before do
Git.stub(:clone).and_raise('no permissions')
expect(Shell).to receive(:system).exactly(4).times
end

specify do
begin
subject
fail 'should have raised "no permissions"'
rescue
# expected
end
end
end
end
end

Expand Down

0 comments on commit 675a594

Please sign in to comment.