Browse Source

Rename Repository getWorkDir to getWorkTree

This better matches with the name used in the environment
(GIT_WORK_TREE), in the configuration file (core.worktree),
and in our builder object.

Since we are already breaking a good chunk of other code
related to repository access, and this fairly easy to fix
in an application's code base, I'm not going to offer the
wrapper getWorkDir() method.

Change-Id: Ib698ba4bbc213c48114f342378cecfe377e37bb7
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.9
Shawn O. Pearce 15 years ago
parent
commit
203bd66267
  1. 2
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java
  2. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java
  3. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java
  4. 2
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/eclipse/Ipzilla.java
  5. 2
      org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java
  6. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
  7. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositorySetupWorkDirTest.java
  8. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java
  9. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java
  10. 2
      org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java
  11. 2
      org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java
  12. 17
      org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

2
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java

@ -324,7 +324,7 @@ public abstract class LocalDiskRepositoryTestCase extends TestCase {
putPersonIdent(env, "AUTHOR", author);
putPersonIdent(env, "COMMITTER", committer);
final File cwd = db.getWorkDir();
final File cwd = db.getWorkTree();
final Process p = Runtime.getRuntime().exec(argv, toEnvArray(env), cwd);
p.getOutputStream().close();
p.getErrorStream().close();

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Clone.java

@ -183,7 +183,7 @@ class Clone extends AbstractFetchCommand {
final Tree tree = commit.getTree();
final WorkDirCheckout co;
co = new WorkDirCheckout(db, db.getWorkDir(), index, tree);
co = new WorkDirCheckout(db, db.getWorkTree(), index, tree);
co.checkout();
index.write();
}

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/Rm.java

@ -67,7 +67,7 @@ class Rm extends TextBuiltin {
@Override
protected void run() throws Exception {
root = db.getWorkDir();
root = db.getWorkTree();
final DirCache dirc = DirCache.lock(db);
final DirCacheBuilder edit = dirc.builder();

2
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/eclipse/Ipzilla.java

@ -91,7 +91,7 @@ class Ipzilla extends TextBuiltin {
}
if (output == null)
output = new File(db.getWorkDir(), IpLogMeta.IPLOG_CONFIG_FILE);
output = new File(db.getWorkTree(), IpLogMeta.IPLOG_CONFIG_FILE);
IpLogMeta meta = new IpLogMeta();
meta.syncCQs(output, ipzilla, username, password);

2
org.eclipse.jgit.test/exttst/org/eclipse/jgit/lib/T0007_GitIndexTest.java

@ -116,7 +116,7 @@ public class T0007_GitIndexTest extends LocalDiskRepositoryTestCase {
protected void setUp() throws Exception {
super.setUp();
db = createWorkRepository();
trash = db.getWorkDir();
trash = db.getWorkTree();
}
public void testCreateEmptyIndex() throws Exception {

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java

@ -100,20 +100,20 @@ public class MergeCommandTest extends RepositoryTestCase {
addNewFileToIndex("file1");
RevCommit first = git.commit().setMessage("initial commit").call();
assertTrue(new File(db.getWorkDir(), "file1").exists());
assertTrue(new File(db.getWorkTree(), "file1").exists());
createBranch(first, "refs/heads/branch1");
addNewFileToIndex("file2");
RevCommit second = git.commit().setMessage("second commit").call();
assertTrue(new File(db.getWorkDir(), "file2").exists());
assertTrue(new File(db.getWorkTree(), "file2").exists());
checkoutBranch("refs/heads/branch1");
assertFalse(new File(db.getWorkDir(), "file2").exists());
assertFalse(new File(db.getWorkTree(), "file2").exists());
MergeResult result = git.merge().include(db.getRef(Constants.MASTER)).call();
assertTrue(new File(db.getWorkDir(), "file1").exists());
assertTrue(new File(db.getWorkDir(), "file2").exists());
assertTrue(new File(db.getWorkTree(), "file1").exists());
assertTrue(new File(db.getWorkTree(), "file2").exists());
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead());
}
@ -132,8 +132,8 @@ public class MergeCommandTest extends RepositoryTestCase {
git.commit().setMessage("third commit").call();
checkoutBranch("refs/heads/branch1");
assertFalse(new File(db.getWorkDir(), "file2").exists());
assertFalse(new File(db.getWorkDir(), "file3").exists());
assertFalse(new File(db.getWorkTree(), "file2").exists());
assertFalse(new File(db.getWorkTree(), "file3").exists());
MergeCommand merge = git.merge();
merge.include(second.getId());
@ -152,7 +152,7 @@ public class MergeCommandTest extends RepositoryTestCase {
}
private void checkoutBranch(String branchName) throws Exception {
File workDir = db.getWorkDir();
File workDir = db.getWorkTree();
if (workDir != null) {
WorkDirCheckout workDirCheckout = new WorkDirCheckout(db,
workDir, db.mapCommit(Constants.HEAD).getTree(),
@ -176,7 +176,7 @@ public class MergeCommandTest extends RepositoryTestCase {
File writeTrashFile = writeTrashFile(filename, filename);
GitIndex index = db.getIndex();
Entry entry = index.add(db.getWorkDir(), writeTrashFile);
Entry entry = index.add(db.getWorkTree(), writeTrashFile);
entry.update(writeTrashFile);
index.write();
}

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositorySetupWorkDirTest.java

@ -73,7 +73,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
throws Exception {
File gitDir = getFile("workdir", Constants.DOT_GIT);
Repository repo = new FileRepository(gitDir);
String workdir = repo.getWorkDir().getName();
String workdir = repo.getWorkTree().getName();
assertEquals(workdir, "workdir");
}
@ -132,7 +132,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
public void testExceptionThrown_BareRepoGetWorkDir() throws Exception {
File gitDir = getFile("workdir");
try {
new FileRepository(gitDir).getWorkDir();
new FileRepository(gitDir).getWorkTree();
fail("Expected IllegalStateException missing");
} catch (IllegalStateException e) {
// expected
@ -202,7 +202,7 @@ public class RepositorySetupWorkDirTest extends LocalDiskRepositoryTestCase {
private void assertWorkdirPath(Repository repo, String... expected)
throws IOException {
File exp = getFile(expected).getCanonicalFile();
File act = repo.getWorkDir().getCanonicalFile();
File act = repo.getWorkTree().getCanonicalFile();
assertEquals("Wrong working Directory", exp, act);
}
}

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryTestCase.java

@ -83,7 +83,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
protected File writeTrashFile(final String name, final String data)
throws IOException {
File path = new File(db.getWorkDir(), name);
File path = new File(db.getWorkTree(), name);
write(path, data);
return path;
}
@ -111,6 +111,6 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
protected void setUp() throws Exception {
super.setUp();
db = createWorkRepository();
trash = db.getWorkDir();
trash = db.getWorkTree();
}
}

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0003_Basic.java

@ -104,7 +104,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent, r.getWorkDir());
assertEqualsPath(repo1Parent, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
}
@ -125,7 +125,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir)
.setWorkTree(repo1Parent.getParentFile()).build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent.getParentFile(), r.getWorkDir());
assertEqualsPath(repo1Parent.getParentFile(), r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
}
@ -145,7 +145,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setWorkTree(repo1Parent).build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent, r.getWorkDir());
assertEqualsPath(repo1Parent, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
}
@ -170,7 +170,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(workdir, r.getWorkDir());
assertEqualsPath(workdir, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
}
@ -195,7 +195,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(workdir, r.getWorkDir());
assertEqualsPath(workdir, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectsDirectory());
}
@ -223,7 +223,7 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
.setIndexFile(indexFile) //
.build();
assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(theDir.getParentFile(), r.getWorkDir());
assertEqualsPath(theDir.getParentFile(), r.getWorkTree());
assertEqualsPath(indexFile, r.getIndexFile());
assertEqualsPath(objDir, r.getObjectsDirectory());
assertNotNull(r.mapCommit("6db9c2ebf75590eef973081736730a9ea169a0c4"));
@ -726,10 +726,10 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
assertEquals("", Repository.stripWorkDir(relBase, relNonFile));
assertEquals("", Repository.stripWorkDir(absBase, absNonFile));
assertEquals("", Repository.stripWorkDir(db.getWorkDir(), db.getWorkDir()));
assertEquals("", Repository.stripWorkDir(db.getWorkTree(), db.getWorkTree()));
File file = new File(new File(db.getWorkDir(), "subdir"), "File.java");
assertEquals("subdir/File.java", Repository.stripWorkDir(db.getWorkDir(), file));
File file = new File(new File(db.getWorkTree(), "subdir"), "File.java");
assertEquals("subdir/File.java", Repository.stripWorkDir(db.getWorkTree(), file));
}

2
org.eclipse.jgit/src/org/eclipse/jgit/api/MergeCommand.java

@ -163,7 +163,7 @@ public class MergeCommand extends GitCommand<MergeResult> {
RevCommit newHeadCommit) throws IOException, CheckoutConflictException {
GitIndex index = repo.getIndex();
File workDir = repo.getWorkDir();
File workDir = repo.getWorkTree();
if (workDir != null) {
WorkDirCheckout workDirCheckout = new WorkDirCheckout(repo,
workDir, headCommit.asCommit(revWalk).getTree(), index,

2
org.eclipse.jgit/src/org/eclipse/jgit/lib/IndexDiff.java

@ -89,7 +89,7 @@ public class IndexDiff {
* @throws IOException
*/
public boolean diff() throws IOException {
final File root = index.getRepository().getWorkDir();
final File root = index.getRepository().getWorkTree();
new IndexTreeWalker(index, tree, root, new AbstractIndexTreeVisitor() {
public void visitEntry(TreeEntry treeEntry, Entry indexEntry, File file) {
if (treeEntry == null) {

17
org.eclipse.jgit/src/org/eclipse/jgit/lib/Repository.java

@ -96,7 +96,7 @@ public abstract class Repository {
static private final List<RepositoryListener> allListeners = new Vector<RepositoryListener>(); // thread safe
/** If not bare, the top level directory of the working files. */
private final File workDir;
private final File workTree;
/** If not bare, the index file caching the working file states. */
private final File indexFile;
@ -110,7 +110,7 @@ public abstract class Repository {
protected Repository(final BaseRepositoryBuilder options) {
gitDir = options.getGitDir();
fs = options.getFS();
workDir = options.getWorkTree();
workTree = options.getWorkTree();
indexFile = options.getIndexFile();
}
@ -886,7 +886,7 @@ public abstract class Repository {
return RepositoryState.BARE;
// Pre Git-1.6 logic
if (new File(getWorkDir(), ".dotest").exists())
if (new File(getWorkTree(), ".dotest").exists())
return RepositoryState.REBASING;
if (new File(getDirectory(), ".dotest-merge").exists())
return RepositoryState.REBASING_INTERACTIVE;
@ -1011,19 +1011,20 @@ public abstract class Repository {
* @return the "bare"-ness of this Repository
*/
public boolean isBare() {
return workDir == null;
return workTree == null;
}
/**
* @return the workdir file, i.e. where the files are checked out
* @return the root directory of the working tree, where files are checked
* out for viewing and editing.
* @throws IllegalStateException
* if the repository is "bare"
* if the repository is bare and has no working directory.
*/
public File getWorkDir() throws IllegalStateException {
public File getWorkTree() throws IllegalStateException {
if (isBare())
throw new IllegalStateException(
JGitText.get().bareRepositoryNoWorkdirAndIndex);
return workDir;
return workTree;
}
/**

Loading…
Cancel
Save