In this example we create a brand-new repository. Then populate it with a greek tree not using file system trees. Then checkout a working copy. Then make text changes in two files and set a property on a directory. The we diff our working copy against the repository.
1 /*
2 * ====================================================================
3 * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
4 *
5 * This software is licensed as described in the file COPYING, which
6 * you should have received as part of this distribution. The terms
7 * are also available at http://svnkit.com/license.html.
8 * If newer versions of this license are posted there, you may use a
9 * newer version instead, at your option.
10 * ====================================================================
11 */
12 package org.tmatesoft.svn.examples.wc;
13 import java.io.File;
14 import java.io.IOException;
15 import org.tmatesoft.svn.core.SVNCommitInfo;
16 import org.tmatesoft.svn.core.SVNDepth;
17 import org.tmatesoft.svn.core.SVNException;
18 import org.tmatesoft.svn.core.SVNPropertyValue;
19 import org.tmatesoft.svn.core.SVNURL;
20 import org.tmatesoft.svn.core.wc.SVNClientManager;
21 import org.tmatesoft.svn.core.wc.SVNDiffClient;
22 import org.tmatesoft.svn.core.wc.SVNRevision;
23 import org.tmatesoft.svn.core.wc.SVNWCClient;
24 /**
25 * This examples demonstrate how you can run WORKING:HEAD diff.
26 *
27 * @version 1.2.0
28 * @author TMate Software Ltd.
29 */
30 public class DiffWCToRepository {
31
32 /**
33 * Pass the absolute path of the base directory where all example data will be created in
34 * arg[0]. The sample will create:
35 *
36 * - arg[0]/exampleRepository - repository with some test data
37 * - arg[0]/exampleWC - working copy checked out from exampleRepository
38 */
39 public static void main (String[] args) {
40 //initialize SVNKit to work through file:/// protocol
41 SamplesUtility.initializeFSFSprotocol();
42
43 File baseDirectory = new File(args[0]);
44 File reposRoot = new File(baseDirectory, "exampleRepository");
45 File wcRoot = new File(baseDirectory, "exampleWC");
46
47 try {
48 //first create a repository and fill it with data
49 SamplesUtility.createRepository(reposRoot);
50 SVNCommitInfo info = SamplesUtility.createRepositoryTree(reposRoot);
51 System.out.println(info);
52
53 //checkout the entire repository tree
54 SVNURL reposURL = SVNURL.fromFile(reposRoot);
55 SamplesUtility.checkOutWorkingCopy(reposURL, wcRoot);
56
57 //now make some changes to the working copy
58 SamplesUtility.writeToFile(new File(wcRoot, "iota"), "New text appended to 'iota'", true);
59 SamplesUtility.writeToFile(new File(wcRoot, "A/mu"), "New text in 'mu'", false);
60
61 SVNClientManager clientManager = SVNClientManager.newInstance();
62 SVNWCClient wcClient = SVNClientManager.newInstance().getWCClient();
63 wcClient.doSetProperty(new File(wcRoot, "A/B"), "spam", SVNPropertyValue.create("egg"), false,
64 SVNDepth.EMPTY, null, null);
65
66 //now run diff the working copy against the repository
67 SVNDiffClient diffClient = clientManager.getDiffClient();
68 /*
69 * This corresponds to 'svn diff -rHEAD'.
70 */
71 diffClient.doDiff(wcRoot, SVNRevision.UNDEFINED, SVNRevision.WORKING, SVNRevision.HEAD,
72 SVNDepth.INFINITY, true, System.out, null);
73 } catch (SVNException svne) {
74 System.out.println(svne.getErrorMessage());
75 System.exit(1);
76 } catch (IOException ioe) {
77 ioe.printStackTrace();
78 System.exit(1);
79 }
80 }
81
82 }