Skip to content
Snippets Groups Projects
Commit e1ed1bd8 authored by Valery Sizov's avatar Valery Sizov
Browse files

Gracefully recover from previously failed rebase

parent 66917e3e
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -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
Loading
Loading
---
title: Gracefully recover from previously failed rebase
merge_request:
author:
Loading
Loading
@@ -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') }
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment