Java源码示例:org.eclipse.jgit.errors.NoWorkTreeException
示例1
private void checkout() throws NoWorkTreeException, IOException {
// Iterate in reverse so that "folder/file" is deleted before
// "folder". Otherwise this could result in a failing path because
// of a non-empty directory, for which delete() would fail.
for (int i = toBeDeleted.size() - 1; i >= 0; i--) {
String fileName = toBeDeleted.get(i);
File f = new File(nonNullRepo().getWorkTree(), fileName);
if (!f.delete())
if (!f.isDirectory())
failingPaths.put(fileName,
MergeFailureReason.COULD_NOT_DELETE);
modifiedFiles.add(fileName);
}
for (Map.Entry<String, DirCacheEntry> entry : toBeCheckedOut
.entrySet()) {
DirCacheEntry cacheEntry = entry.getValue();
if (cacheEntry.getFileMode() == FileMode.GITLINK) {
new File(nonNullRepo().getWorkTree(), entry.getKey()).mkdirs();
} else {
DirCacheCheckout.checkoutEntry(db, cacheEntry, reader, false,
checkoutMetadata.get(entry.getKey()));
modifiedFiles.add(entry.getKey());
}
}
}
示例2
/**
* Reverts the worktree after an unsuccessful merge. We know that for all
* modified files the old content was in the old index and the index
* contained only stage 0. In case if inCore operation just clear the
* history of modified files.
*
* @throws java.io.IOException
* @throws org.eclipse.jgit.errors.CorruptObjectException
* @throws org.eclipse.jgit.errors.NoWorkTreeException
* @since 3.4
*/
protected void cleanUp() throws NoWorkTreeException,
CorruptObjectException,
IOException {
if (inCore) {
modifiedFiles.clear();
return;
}
DirCache dc = nonNullRepo().readDirCache();
Iterator<String> mpathsIt=modifiedFiles.iterator();
while(mpathsIt.hasNext()) {
String mpath = mpathsIt.next();
DirCacheEntry entry = dc.getEntry(mpath);
if (entry != null) {
DirCacheCheckout.checkoutEntry(db, entry, reader, false,
checkoutMetadata.get(mpath));
}
mpathsIt.remove();
}
}
示例3
private void deleteIfUnversioned(DirCache cache, String path, WorkingTreeIterator f, Repository repository, TreeWalk treeWalk) throws IOException, NoWorkTreeException {
if (cache.getEntry(path) == null && // not in index
!f.isEntryIgnored() && // not ignored
!Utils.isFromNested(f.getEntryFileMode().getBits()))
{
File file = new File(repository.getWorkTree().getAbsolutePath() + File.separator + path);
if(file.isDirectory()) {
String[] s = file.list();
if(s != null && s.length > 0) { // XXX is there no better way to find out if empty?
// not empty
return;
}
}
file.delete();
listener.notifyFile(file, treeWalk.getPathString());
}
}
示例4
public static void main(final String[] args) throws NoWorkTreeException,
NoHeadException, IOException, GitAPIException {
if (args.length != 4) {
System.err
.println("Usage <datafile> <prefix> <repositoryDir> <outputFilePrefix>");
System.exit(-1);
}
final SvnToGitMapper mapper = new SvnToGitMapper(args[2]);
final RepentDataParser rdp = new RepentDataParser(new File(args[0]),
mapper.mapSvnToGit(), args[1], new Predicate<Integer>() {
@Override
public boolean test(final Integer t) {
return t > 250;
}
});
final List<Renaming> renamings = rdp.parse();
final Multimap<String, Renaming> renamingsPerSha = mapRenamingsToTargetSha(renamings);
final BindingExtractor be = new BindingExtractor(args[2],
renamingsPerSha);
be.doWalk();
writeJson(args[3], "_variables.json", be.renamedVariablesDatapoints);
writeJson(args[3], "_methoddeclarations.json",
be.renamedMethodDeclarationsDatapoints);
}
示例5
/**
* @param args
* @throws IOException
* @throws GitAPIException
* @throws NoHeadException
* @throws NoWorkTreeException
*/
public static void main(final String[] args) throws IOException,
NoWorkTreeException, NoHeadException, GitAPIException {
if (args.length != 3) {
System.err.println("Usage <datafile> <prefix> <repositoryDir>");
System.exit(-1);
}
final SvnToGitMapper mapper = new SvnToGitMapper(args[2]);
final RepentDataParser rdp = new RepentDataParser(new File(args[0]),
mapper.mapSvnToGit(), args[1], new Predicate<Integer>() {
@Override
public boolean test(final Integer t) {
return t < 250;
}
});
final List<Renaming> renamings = rdp.parse();
for (final Renaming renaming : renamings) {
System.out.println(renaming);
}
System.out.println("Num Renamings: " + renamings.size());
}
示例6
public BiMap<Integer, String> mapSvnToGit() throws IOException,
NoWorkTreeException, NoHeadException, GitAPIException {
final BiMap<Integer, String> mappings = HashBiMap.create();
final Git repository = GitCommitUtils
.getGitRepository(repositoryDirectory);
for (final RevCommit commit : GitCommitUtils
.getAllCommitsTopological(repository)) {
final String message = commit.getFullMessage();
if (!message.contains("git-svn-id")) {
continue;
}
final Matcher matcher = svnIdMatcher.matcher(message);
matcher.find();
mappings.put(Integer.parseInt(matcher.group(1)), commit.name());
}
return mappings;
}
示例7
@Nullable
private Set<String> parseStagedTestNames() {
try {
final Status status = git.status().call();
return Stream.of(
status.getAdded(),
status.getChanged(),
status.getRemoved())
.flatMap(Set::stream)
.distinct()
.map(s -> parseTestName(testDefinitionsDirectory, s))
.filter(Objects::nonNull)
.collect(Collectors.toSet());
} catch (final GitAPIException | NoWorkTreeException e) {
LOGGER.warn("Failed to call git status", e);
return null;
}
}
示例8
public SemverVersion createVersion(Repository repo, Integer buildNumber, boolean topo)
throws MissingObjectException, IncorrectObjectTypeException, IOException,
NoWorkTreeException, GitAPIException {
if (repo == null) {
throw new SemverGitflowPlugin.VersionApplicationException(
"Project is not in a Git repository. Cannot use semver versioning in a non repository.");
}
TagVersionAndCount latestTagAndCount;
if (topo) {
latestTagAndCount = Tags.getTopoTagVersionAndCount(repo, prefix);
} else {
latestTagAndCount = Tags.getLatestTagVersionAndCount(repo, prefix);
}
String headCommitAbbreviation = GitRepos.getHeadCommitIdAbbreviation(repo);
boolean isDirty = GitRepos.isDirty(repo);
return generateVersion(latestTagAndCount, headCommitAbbreviation, buildNumber, isDirty);
}
示例9
private void validateUnstable(String expectedVersion,
int commitCount,
RevCommit headCommit,
Dirty dirty,
String firstModifier)
throws NoWorkTreeException, IOException, GitAPIException {
String headCommitId = headCommit.getId().abbreviate(7).name();
String dirtyText = (dirty == Dirty.YES) ? ".dirty" : "";
String expected = expectedVersion + firstModifier + commitCount + "+g"
+ headCommitId + dirtyText;
SemverVersion version = versionFactory.createVersion(repo, null);
Assert.assertEquals(expected, version.toString());
Integer buildNumber = 123;
String expectedWithBuildNumber = expectedVersion + firstModifier
+ commitCount + "+g" + headCommitId + ".b" + buildNumber
+ dirtyText;
Assert.assertEquals(
expectedWithBuildNumber,
versionFactory.createVersion(repo, buildNumber).toString());
}
示例10
/**
* Resolve the conflicts.
*
* @param conflicts the collection of current existing conflicts in the
* repository
*/
private void resolveConflicts(final Collection<String> conflicts) {
final List<String> conflicts2 = new ArrayList<>();
conflicts2.addAll(conflicts);
boolean isFixedOrCanceled = false;
while (!isFixedOrCanceled) {
switch (resolveConflictsByUser(conflicts2)) {
case OPEN_REPOSITORY:
MergeProcessorUtil.openFile(repo.getRepository().getWorkTree().toString());
break;
case RETRY:
try {
final Status call = repo.status().call();
if (call.getConflicting().isEmpty()) {
isFixedOrCanceled = true;
} else {
conflicts2.clear();
conflicts2.addAll(call.getConflicting());
}
} catch (NoWorkTreeException | GitAPIException e) {
exception = new MergeUnitException(
String.format("Could not check the status of the local repository '%s'.", repo), e); //$NON-NLS-1$
return;
}
break;
case CANCEL:
default:
monitor.setCanceled(true);
isFixedOrCanceled = true;
break;
}
}
}
示例11
private boolean hasUncommittedChanges() {
try {
return git.status().call().hasUncommittedChanges();
} catch ( NoWorkTreeException | GitAPIException e ) {
e.printStackTrace();
return false;
}
}
示例12
@Nonnull
@Override
public File getWorkTree() throws NoWorkTreeException {
if(workTree == null)
throw new NoWorkTreeException();
return workTree;
}
示例13
/**
* @param args
* @throws GitAPIException
* @throws IOException
* @throws NoHeadException
* @throws NoWorkTreeException
*/
public static void main(final String[] args) throws NoWorkTreeException,
NoHeadException, IOException, GitAPIException {
if (args.length != 1) {
System.err.println("Usage <repository>");
System.exit(-1);
}
final SvnToGitMapper mapper = new SvnToGitMapper(args[0]);
System.out.println(mapper.mapSvnToGit());
}
示例14
@Nonnull
@Override
public File getWorkTree() throws NoWorkTreeException {
if(workTree == null)
throw new NoWorkTreeException();
return workTree;
}
示例15
protected void refreshStatus() {
try {
//
// Grab our working repository
//
Path repoPath = ((XacmlAdminUI)getUI()).getUserGitPath();
final Git git = Git.open(repoPath.toFile());
//
// Get our status
//
final String base;
Status status;
if (target == null) {
base = ".";
} else {
Path relativePath = repoPath.relativize(Paths.get(target.getPath()));
base = relativePath.toString();
}
if (logger.isDebugEnabled()) {
logger.debug("Status on base: " + base);
}
status = git.status().addPath(base).call();
//
// Pass it to our container
//
this.container.refreshStatus(status);
this.tableChanges.refreshRowCache();
} catch (NoWorkTreeException | IOException | GitAPIException e) {
String error = "Failed to refresh status: " + e.getLocalizedMessage();
logger.error(error);
}
}
示例16
@Override
public void apply(Project project) {
try {
SemverConvention convention = new SemverConvention(project);
project.getConvention().getPlugins().put("semver", convention);
} catch (NoWorkTreeException e) {
throw new VersionApplicationException(e);
}
}
示例17
public static SemverVersion getRepoVersion(Project project, String prefix)
throws NoWorkTreeException, IOException, GitAPIException {
String repoLocation = project.getProjectDir().getAbsolutePath()
+ "/.git";
Integer buildNumber = getBuildNumber();
return RepoSemanticVersions.getRepoVersion(repoLocation, buildNumber, prefix);
}
示例18
public static SemverVersion getRepoVersion(Project project)
throws NoWorkTreeException, IOException, GitAPIException {
String repoLocation = project.getProjectDir().getAbsolutePath()
+ "/.git";
Integer buildNumber = getBuildNumber();
return RepoSemanticVersions.getRepoVersion(repoLocation, buildNumber);
}
示例19
public static SemverVersion getRepoTopoVersion(Project project)
throws NoWorkTreeException, IOException, GitAPIException {
String repoLocation = project.getProjectDir().getAbsolutePath()
+ "/.git";
Integer buildNumber = getBuildNumber();
return RepoSemanticVersions.getRepoTopoVersion(repoLocation, buildNumber);
}
示例20
public static SemverVersion getRepoTopoVersion(Project project, String prefix)
throws NoWorkTreeException, IOException, GitAPIException {
String repoLocation = project.getProjectDir().getAbsolutePath()
+ "/.git";
Integer buildNumber = getBuildNumber();
return RepoSemanticVersions.getRepoTopoVersion(repoLocation, buildNumber, prefix);
}
示例21
public static Repository getRepo(String repoLocation)
throws NoWorkTreeException, IOException, GitAPIException {
Repository repo;
try {
repo = new FileRepositoryBuilder().readEnvironment()
.findGitDir(new File(repoLocation)).build();
} catch (IllegalArgumentException iae) {
throw new SemverGitflowPlugin.VersionApplicationException(
"Project is not in a Git repository. Cannot use semver versioning in a non repository.",
iae);
}
return repo;
}
示例22
public static SemverVersion getRepoVersion(String repoLocation, Integer buildNumber, String prefix)
throws NoWorkTreeException, IOException, GitAPIException {
Repository repo = getRepo(repoLocation);
TagBasedVersionFactory versionFactory;
if (prefix == null)
versionFactory = new TagBasedVersionFactory();
else
versionFactory = new TagBasedVersionFactory(prefix);
return versionFactory.createVersion(repo, buildNumber);
}
示例23
public static SemverVersion getRepoTopoVersion(String repoLocation, Integer buildNumber, String prefix)
throws NoWorkTreeException, IOException, GitAPIException {
Repository repo = getRepo(repoLocation);
TagBasedVersionFactory versionFactory;
if (prefix == null) {
versionFactory = new TagBasedVersionFactory();
} else {
versionFactory = new TagBasedVersionFactory(prefix);
}
return versionFactory.createTopoVersion(repo, buildNumber);
}
示例24
@TaskAction
public void printStatus() throws NoWorkTreeException, IOException,
GitAPIException {
String repoLocation = project.getProjectDir().getAbsolutePath() + "/.git";
Repository repo = RepoSemanticVersions.getRepo(repoLocation);
GitRepos.printJgitStatus(repo);
}
示例25
@Test
public void testHeadPointsAtStable() throws ConcurrentRefUpdateException,
InvalidTagNameException, NoHeadException, GitAPIException,
NoWorkTreeException, MissingObjectException,
IncorrectObjectTypeException, IOException {
tag("v1.0.0");
validateStableTag("1.0.0");
}
示例26
@Test
public void testHeadPointsAtStableWhenUsingPrefix() throws ConcurrentRefUpdateException,
InvalidTagNameException, NoHeadException, GitAPIException,
NoWorkTreeException, MissingObjectException,
IncorrectObjectTypeException, IOException {
versionFactory = new TagBasedVersionFactory("myPrefix");
tag("myPrefix-v1.0.0");
validateStableTag("1.0.0");
}
示例27
@Test
public void testHeadPointsOneAboveStable()
throws ConcurrentRefUpdateException, InvalidTagNameException,
NoHeadException, GitAPIException, NoWorkTreeException,
MissingObjectException, IncorrectObjectTypeException, IOException {
tag("v1.0.0");
RevCommit head = makeCommit();
validateUnstable("1.0.0", 1, head, Dirty.NO, DOT);
}
示例28
@Test
public void testHeadPointsAtUnstableTag() throws NoWorkTreeException,
IOException, GitAPIException {
RevCommit head = makeCommit();
tag("v0.1.0-dev");
validateUnstable("0.1.0-dev", 0, head, Dirty.NO, DOT);
}
示例29
@Test
public void testHeadPointsAtCommitAboveStable() throws NoWorkTreeException,
IOException, GitAPIException {
tag("1.0.0");
makeCommit();
RevCommit commit = makeCommit();
validateUnstable("1.0.0", 2, commit, Dirty.NO, DASH);
}
示例30
@Test
public void testCommitCount() throws NoHeadException, NoMessageException,
UnmergedPathsException, ConcurrentRefUpdateException,
WrongRepositoryStateException, GitAPIException,
NoWorkTreeException, IOException {
tag("v0.1.1-rc");
makeCommit();
makeCommit();
RevCommit head = makeCommit();
validateUnstable("0.1.1-rc", 3, head, Dirty.NO, DOT);
}