Class: ActiveRepo

Inherits:
Repo
  • Object
show all
Defined in:
lib/sfb_scripts/repositories/active_repo.rb

Instance Attribute Summary

Attributes inherited from Repo

#shell

Instance Method Summary collapse

Methods inherited from Repo

#changed?, #current_branch, #find_files, #grep, #initialize, root_dir, #status_files

Constructor Details

This class inherits a constructor from Repo

Instance Method Details

#fetch_originObject



45
46
47
# File 'lib/sfb_scripts/repositories/active_repo.rb', line 45

def fetch_origin
  shell.run 'git fetch origin'
end

#files_changedObject



34
35
36
# File 'lib/sfb_scripts/repositories/active_repo.rb', line 34

def files_changed
  @files_changed
end

#move_to_master!Object



53
54
55
# File 'lib/sfb_scripts/repositories/active_repo.rb', line 53

def move_to_master!
  shell.run "git checkout master"
end

#pull_origin_master!Object



38
39
40
41
42
43
# File 'lib/sfb_scripts/repositories/active_repo.rb', line 38

def pull_origin_master!
  up do
    fetch_origin
    reset_hard_origin_master!
  end
end

#rebase_on_master!Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/sfb_scripts/repositories/active_repo.rb', line 3

def rebase_on_master!
  shell.notify "\nRebasing current branch on master:"
  up do
    # will raise an error with merge conflicts
    begin
      shell.run "git pull --rebase origin master"
    rescue ShellRunner::CommandFailureError
      puts "Unable to rebase.  Maybe you need to stash local changes, or there are rebase conflicts"
      puts `git status`
      exit
    end
  end
end

#reset_hard_origin_master!Object



49
50
51
# File 'lib/sfb_scripts/repositories/active_repo.rb', line 49

def reset_hard_origin_master!
  shell.run "git reset --hard origin/master"
end

#set_files_changed(old_sha) ⇒ Object



29
30
31
32
# File 'lib/sfb_scripts/repositories/active_repo.rb', line 29

def set_files_changed(old_sha)
  shell.notify "\nIdentifying changed files:"
  @files_changed = (shell.run "git diff --name-only #{old_sha}").split("\n")
end

#upObject



22
23
24
25
26
27
# File 'lib/sfb_scripts/repositories/active_repo.rb', line 22

def up
  old_sha = current_sha
  yield

  set_files_changed(old_sha)
end

#up_master!Object



17
18
19
20
# File 'lib/sfb_scripts/repositories/active_repo.rb', line 17

def up_master!
  move_to_master!
  rebase_on_master!
end