Skip to content

Respect staged files when adding local files (avoid adding all files by default) #38

@a-magdy

Description

@a-magdy

Summary

  • When adding files locally, if there are files already staged in the index, git-artifact should respect that and include only those staged files instead of adding all files.
  • Optionally, detect interactive shell and prompt, or require an explicit flag when no files are staged to avoid surprises.

Current behavior

  • Adding local files appears to add all changes/files by default, regardless of what is currently staged.

Expected behavior

  • If there are staged files (git diff --name-only --cached is non-empty), use that set as the source of files to include.
  • If there are no staged files, keep current behavior (e.g., add all), but consider:
    • prompting in interactive shells, or
    • requiring an explicit --all flag to add everything, to prevent accidental mass adds.

Proposed approach

  • Check for staged entries: git diff --name-only --cached
    • If non-empty: operate only on that list.
    • If empty: fallback to existing behavior.
  • Add flags to override behavior:
    • --respect-staged (default true?)
    • --all (force adding all even if staged is present)
  • Interactive safety: when stdout is a TTY (test -t 1), optionally prompt if adding all files due to empty staged set.

Edge cases to consider

  • Partially staged files (hunks): include the staged blob only.
  • Renames/deletes present in the index.
  • Submodules and subdirectory pathspecs.
  • Empty repo or no index entries.

Rationale

  • Aligns with typical git user expectations: staging is an explicit selection mechanism that tools should respect when possible.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions