简体   繁体   中英

JGit sparse checkout keeps adding files

In Java, I'm working with JGit for performing some actions with a remote repository. However when I sequentially do a sparse checkout between versions with:

checkout.
  setCreateBranch(false).
  setName(tag).
  addPath("server/scripts/").
  setStartPoint(tag);

It keeps the last checkout file and adds new one. It only happens when the name of the files inside the directory are not the same. How could I avoid that when using checkout command this way?

I thought about deleting files inside folder that is being checkout ( scripts , in this case), however I don't know if it will bring conflict when the file being 'downloaded' has the same name.

First note that setCreateBranch() is false by default, hence there is no need to explicitly call setCreateBranch( false ) .

Furthermore, you cannot mix addPath() and setName() The JavaDoc for addPath() says:

If this option is set, neither the setCreateBranch(boolean) nor setName(String) option is considered. In other words, these options are exclusive.

However, I am not sure if the behavior that you see is correct. In doubt check with command-line git to see if it shows the same results and file a bug report if JGit differs.

To work around the orphan files, you can use the StatusCommand to manually delete all untracked files:

Status status = git.status().call();
for( String fileName : status.getUntracked() ) {
  // delete fileName
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM