Skip to main content

StagedOnly

Struct StagedOnly 

Source
pub struct StagedOnly { /* private fields */ }
Expand description

Unstaged changes, set aside for the duration of a stage.

Implementations§

Source§

impl StagedOnly

Why COPIES and not git stash --keep-index, and not a patch either.

Saving is the easy half; restoring is the whole problem.

stash pop MERGES into a tree that already holds the staged content, so it writes conflict markers into the user’s file. Measured on the first attempt.

git diff + git apply is deterministic on Unix and is what pre-commit does — but it applies PATCH semantics to text, and Git for Windows converts line endings by default. Measured on the second attempt: every restore test failed on Windows and passed everywhere else, which is the worst possible shape for the one routine in this codebase that can lose somebody’s work.

So: byte-exact copies. Read the file, put it back. No patch to apply, no newline policy to agree about, and binary files need no special case. It costs a temporary copy of only the files that have unstaged changes.

Source

pub fn enter() -> Result<StagedOnly, String>

The three early exits, and THE ORDER IS THE DESIGN.

Both of the first two used to return “nothing held” with NO OUTPUT, which meant the checks silently judged the working tree — the exact failure this module exists to prevent, announced as a clean run. docs/index-fidelity-and-run-modes.md §1 says conflicted paths ABORT the stage; they did not.

  1. Conflicts first, and they are an Err: a conflicted path has no staged and unstaged halves to separate, so there is nothing this can honestly do. pre_commit turns the Err into a printed message and Verdict::Block. Safe by construction: git itself refuses a commit with unmerged entries, so nothing that would have succeeded now fails.
  2. Nothing unstaged ⇒ nothing held, SILENTLY. The common case must stay free, and it is not a degraded run: there is no unstaged content for a check to be confused by.
  3. Mid-operation LAST, and only when there IS unstaged content, with one printed line. Checked after the conflict test rather than before it, deliberately: the other order made the ordinary conflicted-merge case take the mid-operation branch and warn instead of aborting. Checked after the emptiness test because with a clean tree fidelity is not actually off, and registry.rs:64-67 calls out on purpose that a resolution commit still runs its checks.
Source

pub fn restore()

Put them back. Idempotent, and safe to call from the watcher thread install_signal_handler starts — never from the signal handler itself.

Trait Implementations§

Source§

impl Drop for StagedOnly

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.