当前位置: 首页>>代码示例>>Java>>正文


Java GitException类代码示例

本文整理汇总了Java中org.eclipse.che.api.git.exception.GitException的典型用法代码示例。如果您正苦于以下问题:Java GitException类的具体用法?Java GitException怎么用?Java GitException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


GitException类属于org.eclipse.che.api.git.exception包,在下文中一共展示了GitException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseName

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
private static ConfigKey parseName(String name) throws GitException {
  ConfigKey key = new ConfigKey();
  // Split the qualified name
  String[] parts = name.split("\\.");
  switch (parts.length) {
    case 1:
      throw new GitException("error: key does not contain a section: " + name + lineSeparator());
    case 2:
      key.section = parts[0];
      key.name = parts[1];
      break;
    case 3:
      key.section = parts[0];
      key.subsection = parts[1];
      key.name = parts[2];
      break;
    default:
      throw new GitException("Invalid configuration key " + name);
  }
  return key;
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:JGitConfigImpl.java

示例2: JGitStatusImpl

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
/**
 * @param branchName current repository branch name
 * @param statusCommand Jgit status command
 * @throws GitException when any error occurs
 */
public JGitStatusImpl(String branchName, StatusCommand statusCommand) throws GitException {
  this.branchName = branchName;

  org.eclipse.jgit.api.Status gitStatus;
  try {
    gitStatus = statusCommand.call();
  } catch (GitAPIException exception) {
    throw new GitException(exception.getMessage(), exception);
  }

  clean = gitStatus.isClean();
  added = new ArrayList<>(gitStatus.getAdded());
  changed = new ArrayList<>(gitStatus.getChanged());
  removed = new ArrayList<>(gitStatus.getRemoved());
  missing = new ArrayList<>(gitStatus.getMissing());
  modified = new ArrayList<>(gitStatus.getModified());
  untracked = new ArrayList<>(gitStatus.getUntracked());
  untrackedFolders = new ArrayList<>(gitStatus.getUntrackedFolders());
  conflicting = new ArrayList<>(gitStatus.getConflicting());
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:JGitStatusImpl.java

示例3: shouldAddToIndexOnlySpecifiedFile

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
@Test(
  dataProvider = "GitConnectionFactory",
  dataProviderClass = GitConnectionFactoryProvider.class
)
public void shouldAddToIndexOnlySpecifiedFile(GitConnectionFactory connectionFactory)
    throws GitException, IOException {
  // given
  GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
  addFile(connection, "README.txt", CONTENT);
  connection.add(AddParams.create(ImmutableList.of("README.txt", "CHANGELOG.txt")));
  connection.commit(CommitParams.create("Initial add"));

  // when
  deleteFile(connection, "README.txt");
  addFile(connection, "CHANGELOG.txt", "WE'VE FIXED ALL BUGS");
  connection.add(AddParams.create(singletonList("CHANGELOG.txt")));

  // then
  List<String> notStagedDeletedFiles = connection.status(emptyList()).getMissing();
  assertEquals(notStagedDeletedFiles.size(), 1);
  assertEquals(notStagedDeletedFiles.get(0), "README.txt");

  List<String> stagedFiles = connection.status(emptyList()).getAdded();
  assertEquals(stagedFiles.size(), 1);
  assertEquals(stagedFiles.get(0), "CHANGELOG.txt");
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:AddTest.java

示例4: mock

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
/** Test for workaround related to https://bugs.eclipse.org/bugs/show_bug.cgi?id=510685. */
@Test(
  expectedExceptions = GitException.class,
  expectedExceptionsMessageRegExp =
      "Changes are present but not changed path was specified for commit."
)
public void
    testCommitNotChangedSpecifiedPathsWithAmendAndWithAllWhenOtherUnstagedChangesArePresent()
        throws Exception {
  // given
  Status status = mock(Status.class);
  when(status.getModified()).thenReturn(singletonList("ChangedNotSpecified"));
  doReturn(status).when(jGitConnection).status(anyObject());

  // when
  jGitConnection.commit(
      CommitParams.create("message")
          .withFiles(singletonList("NotChangedSpecified"))
          .withAmend(true)
          .withAll(true));
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:JGitConnectionTest.java

示例5: getConfig

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
@GET
@Path("config")
@Produces(MediaType.APPLICATION_JSON)
public Map<String, String> getConfig(@QueryParam("requestedConfig") List<String> requestedConfig)
    throws ApiException {
  Map<String, String> result = new HashMap<>();
  try (GitConnection gitConnection = getGitConnection()) {
    Config config = gitConnection.getConfig();
    if (requestedConfig == null || requestedConfig.isEmpty()) {
      for (String row : config.getList()) {
        String[] keyValues = row.split("=", 2);
        result.put(keyValues[0], keyValues[1]);
      }
    } else {
      for (String entry : requestedConfig) {
        try {
          String value = config.get(entry);
          result.put(entry, value);
        } catch (GitException exception) {
          // value for this config property non found. Do nothing
        }
      }
    }
  }
  return result;
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:GitService.java

示例6: unsetConfig

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
@DELETE
@Path("config")
public void unsetConfig(@QueryParam("requestedConfig") List<String> requestedConfig)
    throws ApiException {
  try (GitConnection gitConnection = getGitConnection()) {
    Config config = gitConnection.getConfig();
    if (requestedConfig != null && !requestedConfig.isEmpty()) {
      for (String entry : requestedConfig) {
        try {
          config.unset(entry);
        } catch (GitException exception) {
          // value for this config property non found. Do nothing
        }
      }
    }
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:GitService.java

示例7: testUpdateBranches

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
@Test(
  dataProvider = "GitConnectionFactory",
  dataProviderClass = GitConnectionFactoryProvider.class
)
public void testUpdateBranches(GitConnectionFactory connectionFactory)
    throws GitException, IOException {
  // given
  GitConnection connection = connectToGitRepositoryWithContent(connectionFactory, repository);
  addInitialRemote(connection);
  // when
  // change branch1 to branch2
  RemoteUpdateParams request =
      RemoteUpdateParams.create("newRemote").withBranches(singletonList("branch2"));
  connection.remoteUpdate(request);
  // then
  assertEquals(
      parseAllConfig(connection).get("remote.newRemote.fetch").get(0),
      "+refs/heads/branch2:refs/remotes/newRemote/branch2");
}
 
开发者ID:eclipse,项目名称:che,代码行数:20,代码来源:RemoteUpdateTest.java

示例8: testInit

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
@Test(
  dataProvider = "GitConnectionFactory",
  dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class
)
public void testInit(GitConnectionFactory connectionFactory)
    throws GitException, URISyntaxException, IOException {
  GitConnection connection = getTestUserConnection(connectionFactory, repository);

  // check git is not initialized
  assertFalse(new File(repository, ".git").exists());

  // when
  connection.init(false);

  // then
  assertTrue(new File(repository, ".git").exists());
}
 
开发者ID:eclipse,项目名称:che,代码行数:18,代码来源:InitTest.java

示例9: testWhenThereAreNoAnyRemotes

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
@Test(
  dataProvider = "GitConnectionFactory",
  dataProviderClass = GitConnectionFactoryProvider.class,
  expectedExceptions = GitException.class,
  expectedExceptionsMessageRegExp =
      "No remote repository specified.  "
          + "Please, specify either a URL or a remote name from which new revisions should be fetched in request."
)
public void testWhenThereAreNoAnyRemotes(GitConnectionFactory connectionFactory)
    throws Exception {
  // given
  GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);

  // when
  connection.push(PushParams.create(null));
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:PushTest.java

示例10: getStatus

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
@Override
public VcsStatus getStatus(String wsPath) throws ServerException {
  try {
    RegisteredProject project =
        projectManager
            .getClosest(wsPath)
            .orElseThrow(() -> new NotFoundException("Can't find project"));
    String projectFsPath = pathTransformer.transform(project.getPath()).toString();
    wsPath = wsPath.substring(wsPath.startsWith(SEPARATOR) ? 1 : 0);
    String itemPath = wsPath.substring(wsPath.indexOf(SEPARATOR) + 1);
    Status status =
        gitConnectionFactory.getConnection(projectFsPath).status(singletonList(itemPath));
    if (status.getUntracked().contains(itemPath)) {
      return UNTRACKED;
    } else if (status.getAdded().contains(itemPath)) {
      return ADDED;
    } else if (status.getModified().contains(itemPath)
        || status.getChanged().contains(itemPath)) {
      return MODIFIED;
    } else {
      return NOT_MODIFIED;
    }
  } catch (GitException | NotFoundException e) {
    throw new ServerException(e.getMessage());
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:GitStatusProvider.java

示例11: fetchBranch

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
private void fetchBranch(GitConnection gitConnection, String remote, String branch)
    throws UnauthorizedException, GitException {

  final List<String> refSpecs =
      Collections.singletonList(
          String.format("refs/heads/%1$s:refs/remotes/origin/%1$s", branch));
  try {
    fetchRefSpecs(gitConnection, remote, refSpecs);
  } catch (GitException e) {
    LOG.warn("Git exception on branch fetch", e);
    throw new GitException(
        String.format(
            "Unable to fetch remote branch %s. Make sure it exists and can be accessed.", branch),
        e);
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:GitProjectImporter.java

示例12: parseAllConfig

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
private Map<String, List<String>> parseAllConfig(GitConnection connection) throws GitException {
  Map<String, List<String>> config = new HashMap<>();
  List<String> lines = connection.getConfig().getList();
  for (String outLine : lines) {
    String[] pair = outLine.split("=");
    List<String> list = config.get(pair[0]);
    if (list == null) {
      list = new LinkedList<>();
    }
    if (pair.length == 2) {
      list.add(pair[1]);
    }
    config.put(pair[0], list);
  }
  return config;
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:RemoteUpdateTest.java

示例13: getUserCredential

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
/**
 * Searches for CredentialsProvider instances and if needed instance exists, it return given
 * credentials, else null;
 *
 * @param url given URL
 * @return credentials from provider
 * @throws GitException when it is not possible to store credentials
 */
public UserCredential getUserCredential(String url) throws GitException {
  for (CredentialsProvider cp : credentialsProviders.values()) {
    if (url != null && cp.canProvideCredentials(url)) {
      UserCredential commandCredentials = cp.getUserCredential();
      if (commandCredentials != null && !commandCredentials.getProviderId().equals(cp.getId())) {
        throw new GitException(
            "Provider "
                + cp.getId()
                + " returned credential with wrong id "
                + commandCredentials.getProviderId());
      }
      LOG.debug("Url {} user {}", url, commandCredentials);
      return commandCredentials;
    }
  }

  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:CredentialsLoader.java

示例14: testDiffNameOnly

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
@Test(
  dataProvider = "GitConnectionFactory",
  dataProviderClass = org.eclipse.che.git.impl.GitConnectionFactoryProvider.class
)
public void testDiffNameOnly(GitConnectionFactory connectionFactory)
    throws GitException, IOException {
  // given
  GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
  makeCommitInMaster(connection);

  // when
  List<String> diff =
      readDiff(
          DiffParams.create()
              .withFileFilter(null)
              .withType(DiffType.NAME_ONLY)
              .withNoRenames(false)
              .withRenameLimit(0),
          connection);

  // then
  assertEquals(diff.size(), 1);
  assertTrue(diff.contains("aaa"));
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:DiffTest.java

示例15: testAddDeletedFile

import org.eclipse.che.api.git.exception.GitException; //导入依赖的package包/类
@Test(
  dataProvider = "GitConnectionFactory",
  dataProviderClass = GitConnectionFactoryProvider.class
)
public void testAddDeletedFile(GitConnectionFactory connectionFactory)
    throws GitException, IOException {
  // given
  GitConnection connection = connectToInitializedGitRepository(connectionFactory, repository);
  addFile(connection, "README.txt", CONTENT);
  addFile(connection, "CHANGELOG.txt", "WE'VE FIXED ALL BUGS");
  connection.add(AddParams.create(ImmutableList.of("README.txt", "CHANGELOG.txt")));
  connection.commit(CommitParams.create("Initial add"));

  // when
  // remove file from disk
  deleteFile(connection, "CHANGELOG.txt");
  // add all files to index
  connection.add(AddParams.create(AddRequest.DEFAULT_PATTERN));

  // then
  // the deleted file is added to index, so it becomes removed for git
  List<String> stagedDeletedFiles = connection.status(emptyList()).getRemoved();
  assertEquals(stagedDeletedFiles.size(), 1);
  assertEquals(stagedDeletedFiles.get(0), "CHANGELOG.txt");
}
 
开发者ID:eclipse,项目名称:che,代码行数:26,代码来源:AddTest.java


注:本文中的org.eclipse.che.api.git.exception.GitException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。