Class: Gitlab::Git::Push

Inherits:
Object
  • Object
show all
Includes:
Utils::StrongMemoize
Defined in:
lib/gitlab/git/push.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::StrongMemoize

#clear_memoization, #strong_memoize, #strong_memoized?

Constructor Details

#initialize(project, oldrev, newrev, ref) ⇒ Push

Returns a new instance of Push.


10
11
12
13
14
15
# File 'lib/gitlab/git/push.rb', line 10

def initialize(project, oldrev, newrev, ref)
  @project = project
  @oldrev = oldrev.presence || Gitlab::Git::BLANK_SHA
  @newrev = newrev.presence || Gitlab::Git::BLANK_SHA
  @ref = ref
end

Instance Attribute Details

#newrevObject (readonly)

Returns the value of attribute newrev


8
9
10
# File 'lib/gitlab/git/push.rb', line 8

def newrev
  @newrev
end

#oldrevObject (readonly)

Returns the value of attribute oldrev


8
9
10
# File 'lib/gitlab/git/push.rb', line 8

def oldrev
  @oldrev
end

#refObject (readonly)

Returns the value of attribute ref


8
9
10
# File 'lib/gitlab/git/push.rb', line 8

def ref
  @ref
end

Instance Method Details

#branch_added?Boolean

Returns:

  • (Boolean)

23
24
25
# File 'lib/gitlab/git/push.rb', line 23

def branch_added?
  Gitlab::Git.blank_ref?(@oldrev)
end

#branch_nameObject


17
18
19
20
21
# File 'lib/gitlab/git/push.rb', line 17

def branch_name
  strong_memoize(:branch_name) do
    Gitlab::Git.branch_name(@ref)
  end
end

#branch_push?Boolean

Returns:

  • (Boolean)

39
40
41
42
43
# File 'lib/gitlab/git/push.rb', line 39

def branch_push?
  strong_memoize(:branch_push) do
    Gitlab::Git.branch_ref?(@ref)
  end
end

#branch_removed?Boolean

Returns:

  • (Boolean)

27
28
29
# File 'lib/gitlab/git/push.rb', line 27

def branch_removed?
  Gitlab::Git.blank_ref?(@newrev)
end

#branch_updated?Boolean

Returns:

  • (Boolean)

31
32
33
# File 'lib/gitlab/git/push.rb', line 31

def branch_updated?
  branch_push? && !branch_added? && !branch_removed?
end

#force_push?Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/gitlab/git/push.rb', line 35

def force_push?
  Gitlab::Checks::ForcePush.force_push?(@project, @oldrev, @newrev)
end

#modified_pathsObject


45
46
47
48
49
50
51
52
53
# File 'lib/gitlab/git/push.rb', line 45

def modified_paths
  unless branch_updated?
    raise ArgumentError, 'Unable to calculate modified paths!'
  end

  strong_memoize(:modified_paths) do
    @project.repository.diff_stats(@oldrev, @newrev).paths
  end
end