Skip to content

Commit 98b4a6e

Browse files
committed
Fixed normalized paths bug that prevented copying class in IDE. Issue 8497.
If both repo and project paths were symlinks or network drive paths, copying with refactoring caused exceptions to be thrown. Other actions may have resulted in the same. A normalized file path canNOT be passed into getIgnores because getIgnores creates and executes a StatusCommand. Executing the StatusCommand passes the repository and the source file. StatusCommand gets the repository path by calling repository.getWorkTree(), which returns a non-normalized path. If both the repository and the source file are referenced via a symlink or network drive, referencing file paths via normalizing and non-normaling causes file path mismatches. The normalized file path points to another location on the system, but repository.getWorkTree() will provide a non-normalized file path. Signed-off-by: Hunter Schoonover <hunter@skoonie.com>
1 parent 5780a4c commit 98b4a6e

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

ide/libs.git/src/org/netbeans/libs/git/jgit/commands/MoveTreeCommand.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,22 @@ protected void run() throws GitException {
7777
}
7878
sourceFile = tryNormalizeSymlink(sourceFile);
7979
targetFile = tryNormalizeSymlink(targetFile);
80-
Repository repository = getRepository();
80+
81+
Repository repository = getRepository();
82+
83+
File repoWorkTreeNormalized = tryNormalizeSymlink(repository.getWorkTree());
84+
8185
try {
8286
DirCache cache = repository.lockDirCache();
8387
try {
84-
List<String> ignoredTargets = getIgnores(targetFile);
88+
89+
List<String> ignoredTargets = getIgnores(this.source);
90+
8591
boolean retried = false;
8692
DirCacheBuilder builder = cache.builder();
8793
TreeWalk treeWalk = new TreeWalk(repository);
88-
PathFilter sourceFilter = PathFilter.create(Utils.getRelativePath(repository.getWorkTree(), sourceFile));
89-
PathFilter targetFilter = PathFilter.create(Utils.getRelativePath(repository.getWorkTree(), targetFile));
94+
PathFilter sourceFilter = PathFilter.create(Utils.getRelativePath(repoWorkTreeNormalized, sourceFile));
95+
PathFilter targetFilter = PathFilter.create(Utils.getRelativePath(repoWorkTreeNormalized, targetFile));
9096
treeWalk.setFilter(PathFilterGroup.create(Arrays.asList(sourceFilter, targetFilter)));
9197
treeWalk.setRecursive(true);
9298
treeWalk.reset();

0 commit comments

Comments
 (0)