Class: Propel::GitRepository

Inherits:
Object
  • Object
show all
Defined in:
lib/propel/git_repository.rb

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGitRepository

Returns a new instance of GitRepository.



7
8
9
# File 'lib/propel/git_repository.rb', line 7

def initialize
  @options = { :verbose => false }
end

Instance Attribute Details

#loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/propel/git_repository.rb', line 5

def logger
  @logger
end

#optionsObject

Returns the value of attribute options.



5
6
7
# File 'lib/propel/git_repository.rb', line 5

def options
  @options
end

Class Method Details

.changed?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/propel/git_repository.rb', line 11

def self.changed?
  new.changed?
end

Instance Method Details

#changed?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/propel/git_repository.rb', line 19

def changed?
  local_last_commit != remote_last_commit
end

#ensure_attached_head!Object



23
24
25
# File 'lib/propel/git_repository.rb', line 23

def ensure_attached_head!
  exit_with_error('You are operating with a detached HEAD, aborting.') if current_branch == '(no branch)'
end

#fetch!Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/propel/git_repository.rb', line 64

def fetch!
  logger.report_operation "Retrieving remote objects"

  git(verbosity_for('fetch')).tap do |result|
    if result.exitstatus != 0
      exit_with_error "Fetch of remote repository failed, exiting."
    end

    logger.report_status("DONE", :green)
  end
end

#merge_configObject



55
56
57
58
59
60
61
62
# File 'lib/propel/git_repository.rb', line 55

def merge_config
  git("config branch.#{current_branch}.merge").result.tap do |merge|
    if merge.empty?
      exit_with_error  "We could not determine the remote branch for local branch '#{current_branch}.' " +
                       "Please set it with git config branch.#{current_branch}.merge REMOTE_BRANCH."
    end
  end
end

#project_rootObject



15
16
17
# File 'lib/propel/git_repository.rb', line 15

def project_root
  git("rev-parse --show-toplevel").result
end

#pull(rebase) ⇒ Object



27
28
29
30
31
# File 'lib/propel/git_repository.rb', line 27

def pull(rebase)
  pull_cmd = 'pull'
  pull_cmd << ' --rebase' if rebase
  git pull_cmd
end

#pushObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/propel/git_repository.rb', line 33

def push
  logger.report_operation "Pushing to #{remote_config} #{merge_config}"

  git(verbosity_for('push')).tap do |result|
    if result.exitstatus != 0
      logger.report_status("FAILING", :red)
      exit_with_error "Your push failed!  Please try again later."
    end

    logger.report_status('DONE', :green)
  end
end

#remote_configObject



46
47
48
49
50
51
52
53
# File 'lib/propel/git_repository.rb', line 46

def remote_config
  git("config branch.#{current_branch}.remote").result.tap do |remote|
    if remote.empty?
      exit_with_error  "We could not determine the remote repository for branch '#{current_branch}.' " +
                       "Please set it with git config branch.#{current_branch}.remote REMOTE_REPO."
    end
  end
end