javagit/src/main/java/edu/nyu/cs/javagit/api/GitFileSystemObject.java
public static File getRelativePath(File in, File repositoryPath) throws JavaGitException {
    String path = in.getPath();
    String absolutePath = in.getAbsolutePath();

    //check if the path is relative or absolute
    if(path.equals(absolutePath)) {
      //if absolute, make sure it belongs to working tree
      String workingTreePath = repositoryPath.getAbsolutePath();
      if(!path.startsWith(workingTreePath)) {
        throw new JavaGitException(999, "Invalid path :" + path 
            + ". Does not belong to the git working tree/ repository: " + workingTreePath);
      }

      //make path relative
      if(!path.equals(workingTreePath)) {
        path = path.substring(workingTreePath.length()+1);
      }
    }
    
    return new File(path);
  }
public static File getRelativePath(File in, File repositoryPath) throws JavaGitException {
    String path = in.getPath();
    String absolutePath = in.getAbsolutePath();

    //check if the path is relative or absolute
    if(path.equals(absolutePath)) {
      //if absolute, make sure it belongs to working tree
      String workingTreePath = repositoryPath.getAbsolutePath();
      if(!path.startsWith(workingTreePath)) {
        throw new JavaGitException(999, "Invalid path :" + path 
            + ". Does not belong to the git working tree/ repository: " + workingTreePath);
      }

      //make path relative
      if(!path.equals(workingTreePath)) {
        path = path.substring(workingTreePath.length()+1);
      }
    }
    
    return new File(path);
  }
Returns a file, with path relative to git working tree

@param in
input <code>File</code> object
repositoryPath
path to git repository
@return
<code>File</code> object with relative path
@throws JavaGitException
input file does not belong to git working tree/ repo