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

#fetch!Object



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/propel/git_repository.rb', line 60

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



51
52
53
54
55
56
57
58
# File 'lib/propel/git_repository.rb', line 51

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



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

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

#pushObject



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/propel/git_repository.rb', line 29

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



42
43
44
45
46
47
48
49
# File 'lib/propel/git_repository.rb', line 42

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