Class: Gitlab::Git::ChangedPath

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab/git/changed_path.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status:, path:, old_mode:, new_mode:, new_blob_id: nil, old_blob_id: nil, old_path: nil, commit_id: nil) ⇒ ChangedPath

Returns a new instance of ChangedPath.



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/gitlab/git/changed_path.rb', line 8

def initialize(
  status:, path:, old_mode:, new_mode:, new_blob_id: nil, old_blob_id: nil, old_path: nil,
  commit_id: nil)
  @status = status
  @path = path
  @old_mode = old_mode
  @new_mode = new_mode
  @old_blob_id = old_blob_id
  @new_blob_id = new_blob_id
  @old_path = old_path.presence || @path
  @commit_id = commit_id
end

Instance Attribute Details

#commit_idObject (readonly)

Returns the value of attribute commit_id.



6
7
8
# File 'lib/gitlab/git/changed_path.rb', line 6

def commit_id
  @commit_id
end

#new_blob_idObject (readonly)

Returns the value of attribute new_blob_id.



6
7
8
# File 'lib/gitlab/git/changed_path.rb', line 6

def new_blob_id
  @new_blob_id
end

#new_modeObject (readonly)

Returns the value of attribute new_mode.



6
7
8
# File 'lib/gitlab/git/changed_path.rb', line 6

def new_mode
  @new_mode
end

#old_blob_idObject (readonly)

Returns the value of attribute old_blob_id.



6
7
8
# File 'lib/gitlab/git/changed_path.rb', line 6

def old_blob_id
  @old_blob_id
end

#old_modeObject (readonly)

Returns the value of attribute old_mode.



6
7
8
# File 'lib/gitlab/git/changed_path.rb', line 6

def old_mode
  @old_mode
end

#old_pathObject (readonly)

Returns the value of attribute old_path.



6
7
8
# File 'lib/gitlab/git/changed_path.rb', line 6

def old_path
  @old_path
end

#pathObject (readonly)

Returns the value of attribute path.



6
7
8
# File 'lib/gitlab/git/changed_path.rb', line 6

def path
  @path
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/gitlab/git/changed_path.rb', line 6

def status
  @status
end

Instance Method Details

#deleted_file?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/gitlab/git/changed_path.rb', line 25

def deleted_file?
  status == :DELETED
end

#modified_file?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/gitlab/git/changed_path.rb', line 33

def modified_file?
  status == :MODIFIED
end

#new_file?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/gitlab/git/changed_path.rb', line 21

def new_file?
  status == :ADDED
end

#renamed_file?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/gitlab/git/changed_path.rb', line 29

def renamed_file?
  status == :RENAMED
end

#submodule_change?Boolean

Returns:

  • (Boolean)


37
38
39
40
41
42
43
44
45
# File 'lib/gitlab/git/changed_path.rb', line 37

def submodule_change?
  # The file mode 160000 represents a "Gitlink" or a git submodule.
  # The first two digits can be used to distinguish it from regular files.
  #
  # 160000 -> 16 -> gitlink
  # 100644 -> 10 -> regular file

  [old_mode, new_mode].any? { |mode| mode.starts_with?('16') }
end