I need to commit the current state of the workdir (i.e. the files and their content as stored on the filesystem) into a non-checked out branch. It is important that this is done in a stateless way because the user may have local modifications or may have staged some files. That means that the files should not be staged through the index before being committed. (The rest of the application already operates in a stateless way.)
One straightforward way to achieve this would be to build that Tree recursively while descending the directory. But I assume that such a common task is very likely already implemented in Rugged/libgit2 (for example, Index#add_all does something very similar).
Does Rugged provide a way to create a Tree object from the current workdir (respecting .gitignore & Co.) without changing the index?
There is a way to have a staging area that doesn't affect your current index: use a separate
GIT_INDEX_FILE.It is part of
gitcli and my guess is it is supported bylibgit2(I will let you confirm this point though).You can then use the two plumbing commands
write-treeandcommit-treeto create a commit that isn't a descendant ofHEAD.Here is an example using git cli: