3

I read the question and answer for staging files in a non-bare repository. However, I am working with a bare repository and I would like to stage files.

I tried using the test for DirCacheBuilder, but the code Repository.lockDirCache() or Repository.readDirCache() fails because this is a bare repository.

org.eclipse.jgit.errors.NoWorkTreeException: Bare Repository has neither a working tree, nor an index at org.eclipse.jgit.lib.Repository.getIndexFile(Repository.java:993) at org.eclipse.jgit.dircache.DirCache.read(DirCache.java:166) at org.eclipse.jgit.lib.Repository.readDirCache(Repository.java:1017)

So, how could I stage files in a bare repository using JGit? is this even possible?

Community
  • 1
  • 1
Vince
  • 1,570
  • 3
  • 27
  • 48
  • 1
    If you ultimately want to commit to a bare repository (and this is really what you want do) this question might be of interest to you: http://stackoverflow.com/questions/22320996/jgit-bare-commit-tree-construction – Rüdiger Herrmann Aug 28 '14 at 13:23

2 Answers2

6

how could I stage files in a bare repository using JGit?

You wouldn't, as the error states:

Bare Repository has neither a working tree, nor an index

No index, means no staging.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
1

You can't "stage" files, but you can still add new file and commits to a bare repository. Here's a good snippet.

Ned Twigg
  • 2,159
  • 2
  • 22
  • 38