module Git::Repository::ContextHelpers

Facade methods for block-based directory and index context helpers

The ‘with_*` helpers build a second {Git::Repository} bound to a different index file or working directory, yield it, and leave the receiver bound to its original index and working directory. Nothing on the receiver changes, so nothing on it is restored when the block exits. The working directory variants change the process working directory for the duration of the block and change it back afterward. The temporary variants remove the scratch directory they created, even if the block raises an exception.

The second repository is built with ‘self.class.new(execution_context:)`, so a subclass of {Git::Repository} must accept that constructor call for the helpers to yield an instance of the subclass.

Each ‘with_*` helper requires a block that declares a positional parameter for the yielded repository and raises `ArgumentError` otherwise. A block with no positional parameter is the v5.x form, which relied on the receiver being rebound; failing fast keeps that form from running against the original index or working directory.

{#set_index} and {#set_working} are deprecated and warn on every call through {Git::Deprecation}; UPGRADING.md explains why and shows the replacements.

Included by {Git::Repository}.

@api private