Commit e1ed1bd8 authored by Valery Sizov's avatar Valery Sizov

Gracefully recover from previously failed rebase

parent 66917e3e
......@@ -785,7 +785,16 @@ class MergeRequest < ActiveRecord::Base
end
def rebase_in_progress?
File.exist?(rebase_dir_path)
File.exist?(rebase_dir_path) && !clean_stuck_rebase
end
def clean_stuck_rebase
expiration_time = Time.now - 15.minutes
if File.new(rebase_dir_path).mtime < expiration_time
FileUtils.rm_rf(rebase_dir_path)
true
end
end
def diverged_commits_count
......
---
title: Gracefully recover from previously failed rebase
merge_request:
author:
......@@ -751,6 +751,25 @@ describe MergeRequest, models: true do
subject { create :merge_request, :simple }
end
describe '#rebase_in_progress?' do
it 'return true' do
allow(File).to receive(:exist?).and_return(true)
allow(File).to receive(:new).and_return(double(:file, mtime: Time.now))
expect(subject.rebase_in_progress?).to be_truthy
end
it 'return false' do
allow(File).to receive(:exist?).with(subject.rebase_dir_path).and_return(false)
expect(subject.rebase_in_progress?).to be_falsey
end
it 'return false if temporary file exists by is expired' do
allow(File).to receive(:exist?).and_return(true)
allow(File).to receive(:new).and_return(double(:file, mtime: Time.now - 2.hours))
expect(subject.rebase_in_progress?).to be_falsey
end
end
describe '#commits_sha' do
let(:commit0) { double('commit0', sha: 'sha1') }
let(:commit1) { double('commit1', sha: 'sha2') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment