Add support for git worktrees
ClosedPublic

Authored by tnorth on Mar 11 2017, 1:52 PM.

Details

Summary

This patch adds support for the git worktree feature (see https://git-scm.com/docs/git-worktree ).
In a worktree, there is no .git/ folder, rather a .git file which contains a path to the corresponding worktree within the .git folder of the repository.
Also see the bug report here: https://bugs.kde.org/show_bug.cgi?id=375849

The only change required in kdevplatform is a modification of the isValidDirectory() function, which currently checks that a file called HEAD actually exists in the .git/ directory. In the case of a worktree, .git is a file instead, on the function returns false.

With this modification, isValidDirectory now also checks if .git is a file. If it is, the content is retrieved. If the file content matches the typical format of a worktree .git file, the directory is said to be valid.
Sources that lie in a git worktree are now detected as being in a git directory, and the git integration is functional (git, commit, annotate, etc.).

Test Plan
  • clone some git repository
  • checkout some branch in a new worktree
  • open the worktree location in Kdevelop
  • ensure that the branch is visible in the projects tab
  • ensure that the Git menu is available when right-clicking on an item in the document view
  • ensure that the annotation feature works

Diff Detail

Repository
R33 KDevPlatform
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
tnorth created this revision.Mar 11 2017, 1:52 PM
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptMar 11 2017, 1:52 PM
tnorth edited the summary of this revision. (Show Details)Mar 11 2017, 1:54 PM
brauch added a subscriber: brauch.Mar 11 2017, 2:01 PM

Looks good except what is noted below, thanks!

plugins/git/gitplugin.cpp
281

I think you need to check !f.isDir() too, no?

286

I'd just call readAll() here

295

not a warning

tnorth updated this revision to Diff 12385.Mar 11 2017, 2:25 PM

Address comments of @brauch

tnorth marked 3 inline comments as done.Mar 11 2017, 2:27 PM

Thanks for the feedback! I hope that this revision is better now.

brauch accepted this revision.Mar 11 2017, 2:45 PM

Looks good to me. Should I submit this for you or do you have commit access yourself?

This revision is now accepted and ready to land.Mar 11 2017, 2:45 PM

Thanks!
Please commit it as I don't have commit rights.

This revision was automatically updated to reflect the committed changes.