import java.io.IOException;
import org.eclipse.jgit.errors.ConfigInvalidException;
+import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.lib.ConfigConstants;
import org.eclipse.jgit.lib.Constants;
File gitDir = getFile("workdir");
try {
new FileRepository(gitDir).getWorkTree();
- fail("Expected IllegalStateException missing");
- } catch (IllegalStateException e) {
+ fail("Expected NoWorkTreeException missing");
+ } catch (NoWorkTreeException e) {
// expected
}
}
File gitDir = getFile("workdir");
try {
new FileRepository(gitDir).getIndex();
- fail("Expected IllegalStateException missing");
- } catch (IllegalStateException e) {
+ fail("Expected NoWorkTreeException missing");
+ } catch (NoWorkTreeException e) {
// expected
}
}
File gitDir = getFile("workdir");
try {
new FileRepository(gitDir).getIndexFile();
- fail("Expected Exception missing");
- } catch (IllegalStateException e) {
+ fail("Expected NoWorkTreeException missing");
+ } catch (NoWorkTreeException e) {
// expected
}
}
import org.eclipse.jgit.JGitText;
import org.eclipse.jgit.errors.CorruptObjectException;
+import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.errors.UnmergedPathException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
* repository the caller wants to read the default index of.
* @return a cache representing the contents of the specified index file (if
* it exists) or an empty cache if the file does not exist.
- * @throws IllegalStateException
+ * @throws NoWorkTreeException
* if the repository is bare (lacks a working directory).
* @throws IOException
* the index file is present but could not be read.
* library does not support.
*/
public static DirCache read(final Repository db)
- throws CorruptObjectException, IOException {
+ throws NoWorkTreeException, CorruptObjectException, IOException {
return read(db.getIndexFile());
}
* repository the caller wants to read the default index of.
* @return a cache representing the contents of the specified index file (if
* it exists) or an empty cache if the file does not exist.
- * @throws IllegalStateException
+ * @throws NoWorkTreeException
* if the repository is bare (lacks a working directory).
* @throws IOException
* the index file is present but could not be read, or the lock
* library does not support.
*/
public static DirCache lock(final Repository db)
- throws CorruptObjectException, IOException {
+ throws NoWorkTreeException, CorruptObjectException, IOException {
return lock(db.getIndexFile());
}
--- /dev/null
+/*
+ * Copyright (C) 2010, Google Inc.
+ * and other copyright owners as documented in the project's IP log.
+ *
+ * This program and the accompanying materials are made available
+ * under the terms of the Eclipse Distribution License v1.0 which
+ * accompanies this distribution, is reproduced below, and is
+ * available at http://www.eclipse.org/org/documents/edl-v10.php
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the following
+ * conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * - Redistributions in binary form must reproduce the above
+ * copyright notice, this list of conditions and the following
+ * disclaimer in the documentation and/or other materials provided
+ * with the distribution.
+ *
+ * - Neither the name of the Eclipse Foundation, Inc. nor the
+ * names of its contributors may be used to endorse or promote
+ * products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+package org.eclipse.jgit.errors;
+
+import org.eclipse.jgit.JGitText;
+import org.eclipse.jgit.lib.Repository;
+
+/**
+ * Indicates a {@link Repository} has no working directory, and is thus bare.
+ */
+public class NoWorkTreeException extends IllegalStateException {
+ private static final long serialVersionUID = 1L;
+
+ /** Creates an exception indicating there is no work tree for a repository. */
+ public NoWorkTreeException() {
+ super(JGitText.get().bareRepositoryNoWorkdirAndIndex);
+ }
+}
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.errors.IncorrectObjectTypeException;
import org.eclipse.jgit.errors.MissingObjectException;
+import org.eclipse.jgit.errors.NoWorkTreeException;
import org.eclipse.jgit.errors.RevisionSyntaxException;
import org.eclipse.jgit.events.ListenerList;
import org.eclipse.jgit.events.RepositoryEvent;
* {@link Repository}
* @throws IOException
* if the index can not be read
- * @throws IllegalStateException
+ * @throws NoWorkTreeException
* if this is bare (see {@link #isBare()})
*/
- public GitIndex getIndex() throws IOException, IllegalStateException {
+ public GitIndex getIndex() throws IOException, NoWorkTreeException {
if (isBare())
- throw new IllegalStateException(
- JGitText.get().bareRepositoryNoWorkdirAndIndex);
+ throw new NoWorkTreeException();
if (index == null) {
index = new GitIndex(this);
index.read();
/**
* @return the index file location
- * @throws IllegalStateException
+ * @throws NoWorkTreeException
* if this is bare (see {@link #isBare()})
*/
- public File getIndexFile() throws IllegalStateException {
+ public File getIndexFile() throws NoWorkTreeException {
if (isBare())
- throw new IllegalStateException(
- JGitText.get().bareRepositoryNoWorkdirAndIndex);
+ throw new NoWorkTreeException();
return indexFile;
}
/**
* @return the root directory of the working tree, where files are checked
* out for viewing and editing.
- * @throws IllegalStateException
+ * @throws NoWorkTreeException
* if the repository is bare and has no working directory.
*/
- public File getWorkTree() throws IllegalStateException {
+ public File getWorkTree() throws NoWorkTreeException {
if (isBare())
- throw new IllegalStateException(
- JGitText.get().bareRepositoryNoWorkdirAndIndex);
+ throw new NoWorkTreeException();
return workTree;
}
* @return a String containing the content of the MERGE_MSG file or
* {@code null} if this file doesn't exist
* @throws IOException
- * @throws IllegalStateException
+ * @throws NoWorkTreeException
* if the repository is "bare"
*/
- public String readMergeCommitMsg() throws IOException {
+ public String readMergeCommitMsg() throws IOException, NoWorkTreeException {
if (isBare() || getDirectory() == null)
- throw new IllegalStateException(
- JGitText.get().bareRepositoryNoWorkdirAndIndex);
+ throw new NoWorkTreeException();
File mergeMsgFile = new File(getDirectory(), Constants.MERGE_MSG);
try {
* file or {@code null} if this file doesn't exist. Also if the file
* exists but is empty {@code null} will be returned
* @throws IOException
- * @throws IllegalStateException
+ * @throws NoWorkTreeException
* if the repository is "bare"
*/
- public List<ObjectId> readMergeHeads() throws IOException {
+ public List<ObjectId> readMergeHeads() throws IOException, NoWorkTreeException {
if (isBare() || getDirectory() == null)
- throw new IllegalStateException(
- JGitText.get().bareRepositoryNoWorkdirAndIndex);
+ throw new NoWorkTreeException();
File mergeHeadFile = new File(getDirectory(), Constants.MERGE_HEAD);
byte[] raw;