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>
This commit is contained in:
parent
532421d989
commit
203bd66267
|
@ -324,7 +324,7 @@ protected int runHook(final Repository db, final File hook,
|
|||
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();
|
||||
|
|
|
@ -183,7 +183,7 @@ private void doCheckout(final Ref branch) throws IOException {
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -91,7 +91,7 @@ protected void run() throws Exception {
|
|||
}
|
||||
|
||||
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);
|
||||
|
|
|
@ -116,7 +116,7 @@ public void run() {
|
|||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
db = createWorkRepository();
|
||||
trash = db.getWorkDir();
|
||||
trash = db.getWorkTree();
|
||||
}
|
||||
|
||||
public void testCreateEmptyIndex() throws Exception {
|
||||
|
|
|
@ -100,20 +100,20 @@ public void testFastForwardWithFiles() throws Exception {
|
|||
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 void testMultipleHeads() throws Exception {
|
|||
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 @@ private void createBranch(ObjectId objectId, String branchName) throws IOExcepti
|
|||
}
|
||||
|
||||
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 @@ private void addNewFileToIndex(String filename) throws IOException,
|
|||
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();
|
||||
}
|
||||
|
|
|
@ -73,7 +73,7 @@ public void testWorkdirIsParentDir_CreateRepositoryFromDotGitGitDir()
|
|||
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 void testNotBare_CreateRepositoryFromGitDirOnlyWithBareConfigFalse()
|
|||
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 @@ private void assertGitdirPath(Repository repo, String... expected)
|
|||
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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -83,7 +83,7 @@ protected static void copyFile(final File src, final File dst)
|
|||
|
||||
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 @@ protected static void checkFile(File f, final String checkData)
|
|||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
db = createWorkRepository();
|
||||
trash = db.getWorkDir();
|
||||
trash = db.getWorkTree();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ public void test000_openrepo_default_gitDirSet() throws IOException {
|
|||
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 void test000_openrepo_default_gitDirAndWorkTreeSet() throws IOException {
|
|||
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 void test000_openrepo_default_workDirSet() throws IOException {
|
|||
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 void test000_openrepo_default_absolute_workdirconfig()
|
|||
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 void test000_openrepo_default_relative_workdirconfig()
|
|||
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 void test000_openrepo_alternate_index_file_and_objdirs()
|
|||
.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 void test30_stripWorkDir() {
|
|||
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));
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -163,7 +163,7 @@ private void checkoutNewHead(RevWalk revWalk, RevCommit headCommit,
|
|||
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,
|
||||
|
|
|
@ -89,7 +89,7 @@ public IndexDiff(Tree tree, GitIndex index) {
|
|||
* @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) {
|
||||
|
|
|
@ -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 RepositoryState getRepositoryState() {
|
|||
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 static String stripWorkDir(File workDir, File file) {
|
|||
* @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…
Reference in New Issue