Class: Git::BranchDeleteResult

Inherits:
Data
  • Object
show all
Defined in:
lib/git/branch_delete_result.rb

Overview

Represents the result of a branch delete operation

This is an immutable data object returned by Commands::Branch::Delete#call. It contains information about which branches were successfully deleted and which failed to be deleted, along with the reason for each failure.

Git's git branch -d command uses "best effort" semantics - it deletes as many branches as possible and reports errors for those that couldn't be deleted. This result object reflects that behavior, allowing callers to inspect both successes and failures.

Examples:

Successful deletion of all branches

result = branch_delete.call('feature-1', 'feature-2')
result.success?            #=> true
result.deleted.map(&:name) #=> ['feature-1', 'feature-2']
result.not_deleted         #=> []

Partial failure (some branches deleted, some not found)

result = branch_delete.call('feature-1', 'nonexistent', 'feature-2')
result.success?                    #=> false
result.deleted.map(&:name)         #=> ['feature-1', 'feature-2']
result.not_deleted.first.name          #=> 'nonexistent'
result.not_deleted.first.error_message #=> "branch 'nonexistent' not found."

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#deletedObject (readonly)

Returns the value of attribute deleted

Returns:

  • (Object)

    the current value of deleted



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/git/branch_delete_result.rb', line 45

BranchDeleteResult = Data.define(:deleted, :not_deleted) do
  # Returns true if all requested branches were successfully deleted
  #
  # @return [Boolean] true if no branches failed to delete, false otherwise
  #
  # @example
  #   result = branch_delete.call('feature-branch')
  #   if result.success?
  #     puts "All branches deleted successfully"
  #   else
  #     puts "Some branches could not be deleted:"
  #     result.not_deleted.each { |f| puts "  #{f.name}: #{f.error_message}" }
  #   end
  #
  def success?
    not_deleted.empty?
  end
end

#not_deletedObject (readonly)

Returns the value of attribute not_deleted

Returns:

  • (Object)

    the current value of not_deleted



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/git/branch_delete_result.rb', line 45

BranchDeleteResult = Data.define(:deleted, :not_deleted) do
  # Returns true if all requested branches were successfully deleted
  #
  # @return [Boolean] true if no branches failed to delete, false otherwise
  #
  # @example
  #   result = branch_delete.call('feature-branch')
  #   if result.success?
  #     puts "All branches deleted successfully"
  #   else
  #     puts "Some branches could not be deleted:"
  #     result.not_deleted.each { |f| puts "  #{f.name}: #{f.error_message}" }
  #   end
  #
  def success?
    not_deleted.empty?
  end
end

Instance Method Details

#success?Boolean

Returns true if all requested branches were successfully deleted

Examples:

result = branch_delete.call('feature-branch')
if result.success?
  puts "All branches deleted successfully"
else
  puts "Some branches could not be deleted:"
  result.not_deleted.each { |f| puts "  #{f.name}: #{f.error_message}" }
end

Returns:

  • (Boolean)

    true if no branches failed to delete, false otherwise



59
60
61
# File 'lib/git/branch_delete_result.rb', line 59

def success?
  not_deleted.empty?
end