0

I need to get the current revision of a local working copy.

So far I've come up with this: (EDITED)

private static long resolve(File workingDirectory) throws SVNException {
    SvnOperationFactory svnOpFactory = new SvnOperationFactory();
    SvnGetStatus svnGetStatus = svnOpFactory.createGetStatus();
    svnGetStatus.setSingleTarget(SvnTarget.fromFile(workingDirectory));
    svnGetStatus.setDepth(SVNDepth.EMPTY);
    SvnStatus status = svnGetStatus.run();
    return status.getRevision();
}

I can't find a place to actually specify the location of my working copy, not even in the documentation.

How can I tell SvnGetStatus where to look for the working copy?

j0ntech
  • 1,158
  • 3
  • 13
  • 27

1 Answers1

0

Try setting it as the target of the operation:

svnGetStatus.setSingleTarget(SvnTarget.fromFile(wcLocation))
Ian Roberts
  • 120,891
  • 16
  • 170
  • 183
  • That still returns the revision as `-1` just like with no target set. – j0ntech Dec 03 '13 at 14:09
  • 1
    @j0ntech You need to `run()` the operation and then fetch the revision number out of the response that `run` returns - `getRevision()` on the operation itself just gives you the revision number you passed as a parameter to the operation (or didn't pass, in this case, hence -1). – Ian Roberts Dec 03 '13 at 14:19
  • @j0ntech you should probably `setDepth(SVNDepth.EMPTY)` first so it just fetches the status for that particular item rather than recursing into all the descendants. – Ian Roberts Dec 03 '13 at 14:21
  • Okay, I didn't think of actually running the operation. I've modified it (see the edit), but now the `SvnStatus` object is null, `run()` returns nothing. – j0ntech Dec 03 '13 at 14:33
  • 1
    @j0ntech you may be better off using `SvnGetInfo` (the equivalent of `svn info` on the command line) rather than `SvnGetStatus` - by default the "status" operation doesn't return anything if the item you're asking about has no uncommitted changes. – Ian Roberts Dec 03 '13 at 15:07
  • @IanRoberts is right, "status" reports only locally changed files and directories. Use SvnGetInfo instead. – Dmitry Pavlenko Dec 03 '13 at 20:29