examples: check index errors in add by demrom · Pull Request #7422 · libgit2/libgit2 · GitHub
Skip to content

examples: check index errors in add - #7422

Open
demrom wants to merge 1 commit into
libgit2:mainfrom
demrom:examples/add-index-write-error
Open

demrom wants to merge 1 commit into
libgit2:mainfrom
demrom:examples/add-index-write-error

Conversation

@demrom

@demrom demrom commented Oct 13, 2026

Copy link
Copy Markdown

lg2 add returns success when adding files to the index or writing it fails.

Check git_index_add_all, git_index_update_all and git_index_write with the existing check_lg2 helper. The commit example already checks the write.

mkdir repro && cd repro
lg2 init .
echo sample > f
touch .git/index.lock
lg2 add f; echo $?

This prints 0 before the change and 1 afterward, with "Could not write index" and the lock error. An unreadable file also changes from exit 0 to 1 with "Could not add files to index". --dry-run still reaches the write, so a held lock now makes it fail too.

examples/ has no test suite, so no automated test is added.

Check errors while adding or updating files and writing the index so that
lg2 add reports failure instead of silently returning success. Reuse
check_lg2 to print the libgit2 error and exit with a nonzero status; the
commit example already checks the index write this way.
@demrom
demrom marked this pull request as ready for review October 14, 2026 17:45

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant