libgit2

git_diff_tree_to_workdir

Version:

Create a diff list between a tree and the working directory.

The tree you provide will be used for the "old_file" side of the delta, and the working directory will be used for the "new_file" side.

Please note: this is NOT the same as git diff <treeish>. Running git diff HEAD or the like actually uses information from the index, along with the tree and working directory info.

This function returns strictly the differences between the tree and the files contained in the working directory, regardless of the state of files in the index. It may come as a surprise, but there is no direct equivalent in core git.

To emulate git diff <treeish>, call both git_diff_tree_to_index and git_diff_index_to_workdir, then call git_diff_merge on the results. That will yield a git_diff_list that matches the git output.

If this seems confusing, take the case of a file with a staged deletion where the file has then been put back into the working dir and modified. The tree-to-workdir diff for that file is 'modified', but core git would show status 'deleted' since there is a pending deletion in the index.

Signature

int git_diff_tree_to_workdir(git_diff_list **diff, git_repository *repo, git_tree *old_tree, const git_diff_options *opts);

Parameters

In
diff

A pointer to a git_diff_list pointer that will be allocated.

In
repo

The repository containing the tree.

In
old_tree

A git_tree object to diff from, or NULL for empty tree.

In
opts

Structure with options to influence diff or NULL for defaults.

Returns

int

Versions