Class: Git::WorktreeInfo

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

Overview

Immutable value object for one entry of git worktree list

Each entry carries what git worktree list --porcelain reports for a worktree: its path, the checked-out HEAD and branch, and whether it is bare, detached, locked, or prunable, with the reason git gives for the last two.

Examples:

A locked linked worktree with a branch checked out

info = Git::WorktreeInfo.new(
  path: '/tmp/wt/linked',
  head: 'f3e2c1ffb860086504eeb27b77a1d0028b68fd8f',
  branch: 'refs/heads/linked',
  bare: false,
  detached: false,
  locked: true,
  lock_reason: 'on purpose',
  prunable: false,
  prune_reason: nil
)

info.path         # => '/tmp/wt/linked'
info.head         # => 'f3e2c1ffb860086504eeb27b77a1d0028b68fd8f'
info.branch       # => 'refs/heads/linked'
info.locked?      # => true
info.lock_reason  # => 'on purpose'
info.detached?    # => false
info.to_s         # => '/tmp/wt/linked'

Pass an entry back to a worktree operation

info = repo.worktree_list.find { |w| w.branch == 'refs/heads/linked' }
repo.worktree_remove(info)

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#bareBoolean (readonly)

Returns true if this is the main worktree of a bare repository.

Returns:

  • (Boolean)

    true if this is the main worktree of a bare repository



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/git/worktree_info.rb', line 72

WorktreeInfo = Data.define(
  :path,
  :head,
  :branch,
  :bare,
  :detached,
  :locked,
  :lock_reason,
  :prunable,
  :prune_reason
) do
  # Whether this is the main worktree of a bare repository
  #
  # @example
  #   info.bare? # => false
  #
  # @return [Boolean] true if the worktree is bare
  def bare? = bare

  # Whether HEAD is detached in this worktree
  #
  # @example
  #   info.detached? # => false
  #
  # @return [Boolean] true if HEAD is detached
  def detached? = detached

  # Whether the worktree is locked
  #
  # @example
  #   info.locked? # => true
  #
  # @return [Boolean] true if the worktree is locked
  def locked? = locked

  # Whether `git worktree prune` would remove this entry
  #
  # @example
  #   info.prunable? # => false
  #
  # @return [Boolean] true if the entry is prunable
  def prunable? = prunable

  # Returns the worktree path
  #
  # Lets an entry be passed directly to the worktree operations that take a
  # path, such as {Git::Repository::WorktreeOperations#worktree_remove}.
  #
  # @example Convert to string
  #   info.to_s # => '/tmp/wt/linked'
  #
  # @return [String] the worktree path
  def to_s
    path
  end
end

#branchString? (readonly)

Returns the full refname of the checked-out branch (e.g., 'refs/heads/main'), or nil when the worktree is bare or detached.

Returns:

  • (String, nil)

    the full refname of the checked-out branch (e.g., 'refs/heads/main'), or nil when the worktree is bare or detached



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/git/worktree_info.rb', line 72

WorktreeInfo = Data.define(
  :path,
  :head,
  :branch,
  :bare,
  :detached,
  :locked,
  :lock_reason,
  :prunable,
  :prune_reason
) do
  # Whether this is the main worktree of a bare repository
  #
  # @example
  #   info.bare? # => false
  #
  # @return [Boolean] true if the worktree is bare
  def bare? = bare

  # Whether HEAD is detached in this worktree
  #
  # @example
  #   info.detached? # => false
  #
  # @return [Boolean] true if HEAD is detached
  def detached? = detached

  # Whether the worktree is locked
  #
  # @example
  #   info.locked? # => true
  #
  # @return [Boolean] true if the worktree is locked
  def locked? = locked

  # Whether `git worktree prune` would remove this entry
  #
  # @example
  #   info.prunable? # => false
  #
  # @return [Boolean] true if the entry is prunable
  def prunable? = prunable

  # Returns the worktree path
  #
  # Lets an entry be passed directly to the worktree operations that take a
  # path, such as {Git::Repository::WorktreeOperations#worktree_remove}.
  #
  # @example Convert to string
  #   info.to_s # => '/tmp/wt/linked'
  #
  # @return [String] the worktree path
  def to_s
    path
  end
end

#detachedBoolean (readonly)

Returns true if HEAD is detached in this worktree.

Returns:

  • (Boolean)

    true if HEAD is detached in this worktree



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/git/worktree_info.rb', line 72

WorktreeInfo = Data.define(
  :path,
  :head,
  :branch,
  :bare,
  :detached,
  :locked,
  :lock_reason,
  :prunable,
  :prune_reason
) do
  # Whether this is the main worktree of a bare repository
  #
  # @example
  #   info.bare? # => false
  #
  # @return [Boolean] true if the worktree is bare
  def bare? = bare

  # Whether HEAD is detached in this worktree
  #
  # @example
  #   info.detached? # => false
  #
  # @return [Boolean] true if HEAD is detached
  def detached? = detached

  # Whether the worktree is locked
  #
  # @example
  #   info.locked? # => true
  #
  # @return [Boolean] true if the worktree is locked
  def locked? = locked

  # Whether `git worktree prune` would remove this entry
  #
  # @example
  #   info.prunable? # => false
  #
  # @return [Boolean] true if the entry is prunable
  def prunable? = prunable

  # Returns the worktree path
  #
  # Lets an entry be passed directly to the worktree operations that take a
  # path, such as {Git::Repository::WorktreeOperations#worktree_remove}.
  #
  # @example Convert to string
  #   info.to_s # => '/tmp/wt/linked'
  #
  # @return [String] the worktree path
  def to_s
    path
  end
end

#headString? (readonly)

Returns the full object ID of the checked-out HEAD commit (the all-zero object ID when the branch has no commits yet), or nil for a bare main worktree.

Returns:

  • (String, nil)

    the full object ID of the checked-out HEAD commit (the all-zero object ID when the branch has no commits yet), or nil for a bare main worktree



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/git/worktree_info.rb', line 72

WorktreeInfo = Data.define(
  :path,
  :head,
  :branch,
  :bare,
  :detached,
  :locked,
  :lock_reason,
  :prunable,
  :prune_reason
) do
  # Whether this is the main worktree of a bare repository
  #
  # @example
  #   info.bare? # => false
  #
  # @return [Boolean] true if the worktree is bare
  def bare? = bare

  # Whether HEAD is detached in this worktree
  #
  # @example
  #   info.detached? # => false
  #
  # @return [Boolean] true if HEAD is detached
  def detached? = detached

  # Whether the worktree is locked
  #
  # @example
  #   info.locked? # => true
  #
  # @return [Boolean] true if the worktree is locked
  def locked? = locked

  # Whether `git worktree prune` would remove this entry
  #
  # @example
  #   info.prunable? # => false
  #
  # @return [Boolean] true if the entry is prunable
  def prunable? = prunable

  # Returns the worktree path
  #
  # Lets an entry be passed directly to the worktree operations that take a
  # path, such as {Git::Repository::WorktreeOperations#worktree_remove}.
  #
  # @example Convert to string
  #   info.to_s # => '/tmp/wt/linked'
  #
  # @return [String] the worktree path
  def to_s
    path
  end
end

#lock_reasonString? (readonly)

Returns the reason given when the worktree was locked, or nil when it is not locked or was locked without a reason.

Returns:

  • (String, nil)

    the reason given when the worktree was locked, or nil when it is not locked or was locked without a reason



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/git/worktree_info.rb', line 72

WorktreeInfo = Data.define(
  :path,
  :head,
  :branch,
  :bare,
  :detached,
  :locked,
  :lock_reason,
  :prunable,
  :prune_reason
) do
  # Whether this is the main worktree of a bare repository
  #
  # @example
  #   info.bare? # => false
  #
  # @return [Boolean] true if the worktree is bare
  def bare? = bare

  # Whether HEAD is detached in this worktree
  #
  # @example
  #   info.detached? # => false
  #
  # @return [Boolean] true if HEAD is detached
  def detached? = detached

  # Whether the worktree is locked
  #
  # @example
  #   info.locked? # => true
  #
  # @return [Boolean] true if the worktree is locked
  def locked? = locked

  # Whether `git worktree prune` would remove this entry
  #
  # @example
  #   info.prunable? # => false
  #
  # @return [Boolean] true if the entry is prunable
  def prunable? = prunable

  # Returns the worktree path
  #
  # Lets an entry be passed directly to the worktree operations that take a
  # path, such as {Git::Repository::WorktreeOperations#worktree_remove}.
  #
  # @example Convert to string
  #   info.to_s # => '/tmp/wt/linked'
  #
  # @return [String] the worktree path
  def to_s
    path
  end
end

#lockedBoolean (readonly)

Returns true if the worktree is locked.

Returns:

  • (Boolean)

    true if the worktree is locked



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/git/worktree_info.rb', line 72

WorktreeInfo = Data.define(
  :path,
  :head,
  :branch,
  :bare,
  :detached,
  :locked,
  :lock_reason,
  :prunable,
  :prune_reason
) do
  # Whether this is the main worktree of a bare repository
  #
  # @example
  #   info.bare? # => false
  #
  # @return [Boolean] true if the worktree is bare
  def bare? = bare

  # Whether HEAD is detached in this worktree
  #
  # @example
  #   info.detached? # => false
  #
  # @return [Boolean] true if HEAD is detached
  def detached? = detached

  # Whether the worktree is locked
  #
  # @example
  #   info.locked? # => true
  #
  # @return [Boolean] true if the worktree is locked
  def locked? = locked

  # Whether `git worktree prune` would remove this entry
  #
  # @example
  #   info.prunable? # => false
  #
  # @return [Boolean] true if the entry is prunable
  def prunable? = prunable

  # Returns the worktree path
  #
  # Lets an entry be passed directly to the worktree operations that take a
  # path, such as {Git::Repository::WorktreeOperations#worktree_remove}.
  #
  # @example Convert to string
  #   info.to_s # => '/tmp/wt/linked'
  #
  # @return [String] the worktree path
  def to_s
    path
  end
end

#pathString (readonly)

Returns the worktree directory as git reports it.

Returns:

  • (String)

    the worktree directory as git reports it



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/git/worktree_info.rb', line 72

WorktreeInfo = Data.define(
  :path,
  :head,
  :branch,
  :bare,
  :detached,
  :locked,
  :lock_reason,
  :prunable,
  :prune_reason
) do
  # Whether this is the main worktree of a bare repository
  #
  # @example
  #   info.bare? # => false
  #
  # @return [Boolean] true if the worktree is bare
  def bare? = bare

  # Whether HEAD is detached in this worktree
  #
  # @example
  #   info.detached? # => false
  #
  # @return [Boolean] true if HEAD is detached
  def detached? = detached

  # Whether the worktree is locked
  #
  # @example
  #   info.locked? # => true
  #
  # @return [Boolean] true if the worktree is locked
  def locked? = locked

  # Whether `git worktree prune` would remove this entry
  #
  # @example
  #   info.prunable? # => false
  #
  # @return [Boolean] true if the entry is prunable
  def prunable? = prunable

  # Returns the worktree path
  #
  # Lets an entry be passed directly to the worktree operations that take a
  # path, such as {Git::Repository::WorktreeOperations#worktree_remove}.
  #
  # @example Convert to string
  #   info.to_s # => '/tmp/wt/linked'
  #
  # @return [String] the worktree path
  def to_s
    path
  end
end

#prunableBoolean (readonly)

Returns true if git worktree prune would remove this entry.

Returns:

  • (Boolean)

    true if git worktree prune would remove this entry



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/git/worktree_info.rb', line 72

WorktreeInfo = Data.define(
  :path,
  :head,
  :branch,
  :bare,
  :detached,
  :locked,
  :lock_reason,
  :prunable,
  :prune_reason
) do
  # Whether this is the main worktree of a bare repository
  #
  # @example
  #   info.bare? # => false
  #
  # @return [Boolean] true if the worktree is bare
  def bare? = bare

  # Whether HEAD is detached in this worktree
  #
  # @example
  #   info.detached? # => false
  #
  # @return [Boolean] true if HEAD is detached
  def detached? = detached

  # Whether the worktree is locked
  #
  # @example
  #   info.locked? # => true
  #
  # @return [Boolean] true if the worktree is locked
  def locked? = locked

  # Whether `git worktree prune` would remove this entry
  #
  # @example
  #   info.prunable? # => false
  #
  # @return [Boolean] true if the entry is prunable
  def prunable? = prunable

  # Returns the worktree path
  #
  # Lets an entry be passed directly to the worktree operations that take a
  # path, such as {Git::Repository::WorktreeOperations#worktree_remove}.
  #
  # @example Convert to string
  #   info.to_s # => '/tmp/wt/linked'
  #
  # @return [String] the worktree path
  def to_s
    path
  end
end

#prune_reasonString? (readonly)

Returns git's explanation of why the entry is prunable, or nil when it is not prunable.

Returns:

  • (String, nil)

    git's explanation of why the entry is prunable, or nil when it is not prunable



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/git/worktree_info.rb', line 72

WorktreeInfo = Data.define(
  :path,
  :head,
  :branch,
  :bare,
  :detached,
  :locked,
  :lock_reason,
  :prunable,
  :prune_reason
) do
  # Whether this is the main worktree of a bare repository
  #
  # @example
  #   info.bare? # => false
  #
  # @return [Boolean] true if the worktree is bare
  def bare? = bare

  # Whether HEAD is detached in this worktree
  #
  # @example
  #   info.detached? # => false
  #
  # @return [Boolean] true if HEAD is detached
  def detached? = detached

  # Whether the worktree is locked
  #
  # @example
  #   info.locked? # => true
  #
  # @return [Boolean] true if the worktree is locked
  def locked? = locked

  # Whether `git worktree prune` would remove this entry
  #
  # @example
  #   info.prunable? # => false
  #
  # @return [Boolean] true if the entry is prunable
  def prunable? = prunable

  # Returns the worktree path
  #
  # Lets an entry be passed directly to the worktree operations that take a
  # path, such as {Git::Repository::WorktreeOperations#worktree_remove}.
  #
  # @example Convert to string
  #   info.to_s # => '/tmp/wt/linked'
  #
  # @return [String] the worktree path
  def to_s
    path
  end
end

Instance Method Details

#bare?Boolean

Whether this is the main worktree of a bare repository

Examples:

info.bare? # => false

Returns:

  • (Boolean)

    true if the worktree is bare



89
# File 'lib/git/worktree_info.rb', line 89

def bare? = bare

#detached?Boolean

Whether HEAD is detached in this worktree

Examples:

info.detached? # => false

Returns:

  • (Boolean)

    true if HEAD is detached



97
# File 'lib/git/worktree_info.rb', line 97

def detached? = detached

#locked?Boolean

Whether the worktree is locked

Examples:

info.locked? # => true

Returns:

  • (Boolean)

    true if the worktree is locked



105
# File 'lib/git/worktree_info.rb', line 105

def locked? = locked

#prunable?Boolean

Whether git worktree prune would remove this entry

Examples:

info.prunable? # => false

Returns:

  • (Boolean)

    true if the entry is prunable



113
# File 'lib/git/worktree_info.rb', line 113

def prunable? = prunable

#to_sString

Returns the worktree path

Lets an entry be passed directly to the worktree operations that take a path, such as Repository::WorktreeOperations#worktree_remove.

Examples:

Convert to string

info.to_s # => '/tmp/wt/linked'

Returns:

  • (String)

    the worktree path



124
125
126
# File 'lib/git/worktree_info.rb', line 124

def to_s
  path
end