Module: Gitcycle::Pull

Included in:
Gitcycle
Defined in:
lib/gitcycle/pull.rb

Instance Method Summary collapse

Instance Method Details

#pull(*args) ⇒ Object



4
5
6
7
8
9
10
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
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/gitcycle/pull.rb', line 4

def pull(*args)
  exec_git(:pull, args) if args.length > 0

  require_git && require_config

  current_branch = branches(:current => true)

  puts "\nRetrieving branch information from gitcycle.\n".green
  branch = get('branch',
    'branch[name]' => current_branch,
    'include' => [ 'repo' ],
    'create' => 0
  )

  if branch && branch['collab']
    # Merge from collab
    merge_remote_branch(
      :owner => owner = branch['home'],
      :repo => branch['repo']['name'],
      :branch => branch['source']
    )
  elsif branch
    # Merge from upstream source branch
    merge_remote_branch(
      :owner => owner = branch['repo']['owner'],
      :repo => branch['repo']['name'],
      :branch => branch['source']
    )
  else
    puts "\nRetrieving repo information from gitcycle.\n".green
    repo = get('repo')

    # Merge from upstream branch with same name
    merge_remote_branch(
      :owner => owner = repo['owner'],
      :repo => repo['name'],
      :branch => current_branch
    )
  end

  unless branch && branch['collab'] || owner == @git_login
    # Merge from origin
    merge_remote_branch(
      :owner => @git_login,
      :repo => @git_repo,
      :branch => current_branch
    )
  end

  branch
end