[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jgit-dev] Diff between working directory and commit

Hi Robert,

DirCacheIterator represents index (stage area), so your code shows
diffs between working tree (unstaged files) and the index (staged
files), ie what "git diff" with no params does.

Have a look at org.eclipse.egit.core.op.CreatePatchOperation.execute(IProgressMonitor)
from EGit where diffs for commits and working tree/index are
generated. It should give you an idea how to proceed. If not feel free
to drop me a line.

Cheers,
Tomasz

On Tue, Feb 7, 2012 at 23:22, Robert von Burg <eitch@xxxxxxxxxxx> wrote:
> Hi
>
> I've been trying to find a way to build a diff between the current
> working directory (unstaged items) and a certain commit.
>
> In git this seems trivial by adding just saying which commit, but in
> jgit i'm lost. This is what I have:
>
> // diff of working directory with last commit
> ByteArrayOutputStream out = new ByteArrayOutputStream();
> DiffFormatter df = new DiffFormatter(out);
> df.setRepository(repository);
> DirCacheIterator oldTree = new
> Â ÂDirCacheIterator(repository.readDirCache());
> FileTreeIterator newTree = new FileTreeIterator(repository);
> df.format(oldTree, newTree);
> df.flush();
> df.release();
> System.out.println("Diff:\n" + out.toString() + "\n\n");
>
> and building a diff when i have two objectIds is trivial.
>
> What am I mising?
>
> Kind regards
> --
> Robert von Burg <eitch@xxxxxxxxxxx>
> dipl. Informatiker in Softwareentwicklung HF / pBac-Eng ODEC
> software development
> system & network administration
>
> http://eitchnet.ch
> http://gsinet.ch
> _______________________________________________
> jgit-dev mailing list
> jgit-dev@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/jgit-dev