Class: Git::Daily::Pull

Inherits:
Command show all
Defined in:
lib/git-daily/command/pull.rb

Instance Method Summary collapse

Methods inherited from Command

branches, clean?, current_branch, develop, has_branch?, has_remote_branch?, #initialize, logurl, master, merged_branches, pull_request_url, release_branches, remote, remote_branch, remotes

Constructor Details

This class inherits a constructor from Git::Daily::Command

Instance Method Details

#helpObject



7
8
9
# File 'lib/git-daily/command/pull.rb', line 7

def help
  "pull\tPull remote to local (for only same branch)"
end

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/git-daily/command/pull.rb', line 11

def run
  remote = Command.remote
  if remote.empty?
    raise "no remote setting"
  end

  current_branch = Command.current_branch
  unless current_branch
    raise "not on any branches"
  end

  remote_branch = Command.remote_branch(remote, current_branch)
  unless remote_branch
    raise "note remote branch named: #{current_branch}"
  end

  rebase = false
  OptionParser.new do |opt|
    opt.on('--rebase') { |v| rebase = true }
    opt.parse!(ARGV)
  end

  puts "run git pull #{remote} #{current_branch}#{ rebase ? ' (rebase)' : ''}"
  r = `git pull #{rebase ? '--rebase' : ''} #{remote} #{current_branch}`
  puts r
  unless $?.success?
    $stderr.puts "git pull failed:"
    raise "git pull failed"
  end
  puts "pull completed"
end

#usageObject



43
44
45
46
47
48
# File 'lib/git-daily/command/pull.rb', line 43

def usage
  <<-EOS
Usage: git daily pull
   or: git daily pull --rebase
EOS
end