jGIT Track File Location Change

25 views Asked by At

A GIT file location may change through GIT PULL or change of the branches. How can I track the file position change? I am using jGIT, an Eclipse library for GIT. Currently I do:

final PullCommand pullCommand = git.pull().setRemote("origin").setRemoteBranchName(git.getRepository().getBranch());
1

There are 1 answers

0
RĂ¼diger Herrmann On

It is worth to keep in mind, that Git (and thus JGit) tracks content, not files. When a file is moved or renamed, Git just sees that a file was added with the new name, and a file was deleted with the old name.

With DiffFormatter::scan a list of files that have been changed between two states of a repository (e.g. two commits, or a commit and the work dir) can be obtained. The method returns a list of DiffEntrys, each describing an added, deleted, or modified file.

The DiffFormatter may be configured with a FollowFilter or setDetectRenames(true) to use heuristics to detect renames. See the resulting DiffEntry's changeType or compare oldPath and newPath.

If you intend to track changes to the working directory, you may consider using a file watcher instead. This would also include changes made outside of your application.