From: Robin Rosenberg Date: Sat, 10 May 2008 20:53:50 GMT Subject: Re: [JGIT PATCH 19/22] Added the class AddRuleListFactory. Message-ID: <200805102253.50641.robin.rosenberg.lists@dewire.com> In-Reply-To: <1210424440-13886-20-git-send-email-florianskarten@web.de> lördagen den 10 maj 2008 15.00.37 skrev Florian Koeberle: > +class AddRuleListFactory { > + /* > + * The add command of git 1.5.2.5 behaves a little bit stange: "git add > + * a/\*z" adds the file "a/b/xyz" but "git add a/x\*" does not. > + * > + * The first is parsed as pattern "*z" for whole directory tree "a". The > + * second is parsed as an path. > + * What do *you* do? > + */ > + > + private static List getRelativePath(File projectDirectory, File file) > + throws PathNotInProjectDirectoryException, IOException { > + File currentFile = file.getCanonicalFile(); > + final LinkedList relativePath = new LinkedList(); > + while (!currentFile.equals(projectDirectory)) { > + relativePath.addFirst(currentFile.getName()); > + currentFile = currentFile.getParentFile(); > + if (currentFile == null) { > + throw new PathNotInProjectDirectoryException(); > + } > + } > + return relativePath; > + } Would be nice to have this logic in a utility class. -- robin