@Override
  @Before
  public void beforeTestCase() throws Exception {
    workdir = testUtils.createTempDir("Repository1");
    workdir2 = testUtils.createTempDir("Repository2");

    repository1 = new TestRepository(new File(workdir, DOT_GIT));

    repository1.createInitialCommit("setUp");

    Repository repository = repository1.getRepository();
    new InitOperation(repository).execute(null);

    // now we create a project in repo1
    IProject project = testUtils.createProjectInLocalFileSystem(workdir, projectName);
    testUtils.addFileToProject(project, "folder1/file1.txt", "Hello world");

    repository1.connect(project);
    repository1.trackAllFiles(project);
    repository1.commit("Initial commit");

    // let's get rid of the project
    project.delete(false, false, null);

    // let's clone repository1 to repository2
    URIish uri = repository1.getUri();
    CloneOperation clop =
        new CloneOperation(uri, true, null, workdir2, R_HEADS + MY_MASTER, DEFAULT_REMOTE_NAME, 0);
    clop.run(null);

    Repository repo2 =
        Activator.getDefault().getRepositoryCache().lookupRepository(new File(workdir2, DOT_GIT));
    repository2 = new TestRepository(repo2);
  }
예제 #2
0
 /**
  * Create a MergeOperation object
  *
  * @param repository
  * @param refName name of a commit which should be merged
  * @param mergeStrategyName the strategy to use for merge. If not registered, the default merge
  *     strategy according to preferences will be used.
  */
 public MergeOperation(
     @NonNull Repository repository, @NonNull String refName, @NonNull String mergeStrategyName) {
   this.repository = repository;
   this.refName = refName;
   MergeStrategy strategy = null;
   strategy = MergeStrategy.get(mergeStrategyName);
   this.mergeStrategy =
       strategy != null ? strategy : Activator.getDefault().getPreferredMergeStrategy();
 }
예제 #3
0
 private UserPasswordCredentials getCredentialsFromSecureStore(final URIish uri) {
   UserPasswordCredentials credentials = null;
   try {
     credentials = Activator.getDefault().getSecureStore().getCredentials(uri);
   } catch (StorageException e) {
     Activator.logError(UIText.EGitCredentialsProvider_errorReadingCredentials, e);
   }
   return credentials;
 }
예제 #4
0
  private void map(final RepositoryMapping m) {
    final IResource r;
    final File git;
    final IResource dotGit;
    IContainer c = null;

    m.clear();
    r = getProject().findMember(m.getContainerPath());
    if (r instanceof IContainer) {
      c = (IContainer) r;
    } else if (r != null) {
      c = Utils.getAdapter(r, IContainer.class);
    }

    if (c == null) {
      logAndUnmapGoneMappedResource(m);
      return;
    }
    m.setContainer(c);

    IPath absolutePath = m.getGitDirAbsolutePath();
    if (absolutePath == null) {
      logAndUnmapGoneMappedResource(m);
      return;
    }
    git = absolutePath.toFile();
    if (!git.isDirectory() || !new File(git, "config").isFile()) { // $NON-NLS-1$
      logAndUnmapGoneMappedResource(m);
      return;
    }

    try {
      m.setRepository(Activator.getDefault().getRepositoryCache().lookupRepository(git));
    } catch (IOException ioe) {
      logAndUnmapGoneMappedResource(m);
      return;
    }

    m.fireRepositoryChanged();

    trace(
        "map " //$NON-NLS-1$
            + c
            + " -> " //$NON-NLS-1$
            + m.getRepository());
    try {
      c.setSessionProperty(MAPPING_KEY, m);
    } catch (CoreException err) {
      Activator.logError(CoreText.GitProjectData_failedToCacheRepoMapping, err);
    }

    dotGit = c.findMember(Constants.DOT_GIT);
    if (dotGit != null && dotGit.getLocation().toFile().equals(git)) {
      protect(dotGit);
    }
  }
예제 #5
0
파일: Activator.java 프로젝트: jlulwd/egit
    @Override
    protected IStatus run(IProgressMonitor monitor) {
      // The core plugin might have been stopped before we could cancel
      // this job.
      RepositoryCache repositoryCache =
          org.eclipse.egit.core.Activator.getDefault().getRepositoryCache();
      if (repositoryCache == null) return Status.OK_STATUS;

      Repository[] repos = repositoryCache.getAllRepositories();
      if (repos.length == 0) return Status.OK_STATUS;

      // When people use Git from the command line a lot of changes
      // may happen. Don't scan when inactive depending on the user's
      // choice.

      if (Activator.getDefault()
          .getPreferenceStore()
          .getBoolean(UIPreferences.REFESH_ONLY_WHEN_ACTIVE)) {
        if (!isActive()) {
          monitor.done();
          if (doReschedule) schedule(REPO_SCAN_INTERVAL);
          return Status.OK_STATUS;
        }
      }

      monitor.beginTask(UIText.Activator_scanningRepositories, repos.length);
      try {
        for (Repository repo : repos) {
          if (monitor.isCanceled()) break;
          if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
            GitTraceLocation.getTrace()
                .trace(
                    GitTraceLocation.REPOSITORYCHANGESCANNER.getLocation(),
                    "Scanning " + repo + " for changes"); // $NON-NLS-1$ //$NON-NLS-2$

          repo.scanForRepoChanges();
          monitor.worked(1);
        }
      } catch (IOException e) {
        if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
          GitTraceLocation.getTrace()
              .trace(
                  GitTraceLocation.REPOSITORYCHANGESCANNER.getLocation(),
                  "Stopped rescheduling " + getName() + "job"); // $NON-NLS-1$ //$NON-NLS-2$
        return createErrorStatus(UIText.Activator_scanError, e);
      } finally {
        monitor.done();
      }
      if (GitTraceLocation.REPOSITORYCHANGESCANNER.isActive())
        GitTraceLocation.getTrace()
            .trace(
                GitTraceLocation.REPOSITORYCHANGESCANNER.getLocation(),
                "Rescheduling " + getName() + " job"); // $NON-NLS-1$ //$NON-NLS-2$
      if (doReschedule) schedule(REPO_SCAN_INTERVAL);
      return Status.OK_STATUS;
    }
  @After
  public void tearDown() throws Exception {
    testRepository.dispose();
    testRepositoryClone.dispose();
    testRepository2.dispose();
    Activator.getDefault().getRepositoryCache().clear();

    testProject.dispose();
    testProject2.dispose();
  }
 @Override
 public void reset(URIish uri) {
   try {
     Activator.getDefault().getSecureStore().clearCredentials(uri);
     user = null;
     password = null;
   } catch (IOException e) {
     Activator.logError(
         MessageFormat.format(UIText.EGitCredentialsProvider_FailedToClearCredentials, uri), e);
   }
 }
  @Before
  public void setUp() throws Exception {
    Activator.getDefault().getRepositoryCache().clear();

    this.testProject = new TestProject(true);
    this.testRepository = createTestRepository(testProject);

    this.testRepositoryClone = cloneRepository(testRepository);

    this.testProject2 = new TestProject(true);
    this.testRepository2 = createTestRepository(testProject2);
  }
  /**
   * Creates project structure inside the base project
   *
   * @throws CoreException
   * @throws IOException
   * @throws WrongRepositoryStateException
   * @throws JGitInternalException
   * @throws ConcurrentRefUpdateException
   * @throws NoMessageException
   * @throws NoHeadException
   * @throws NoFilepatternException
   */
  public void createProjectStructure()
      throws NoFilepatternException, NoHeadException, NoMessageException,
          ConcurrentRefUpdateException, JGitInternalException, WrongRepositoryStateException,
          IOException, CoreException {
    File directory = createLocalGitRepo();

    addContentToGitRepo(directory);

    // Set persistent property so that we know when to show the context
    // menu item.
    project.setPersistentProperty(
        LocalFedoraPackagerPlugin.PROJECT_PROP, "true" /* unused value */); // $NON-NLS-1$

    ConnectProviderOperation connect = new ConnectProviderOperation(project);
    connect.execute(null);

    // Add created repository to the list of Git repositories so that it
    // shows up in the Git repositories view.
    final RepositoryUtil config = org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil();
    config.addConfiguredRepository(repository.getDirectory());
  }
예제 #10
0
  @After
  public void tearDown() throws Exception {

    Thread.sleep(1000); // FIXME: We need a good way to wait for things to settle

    RepositoryProvider.unmap(project);
    RepositoryProvider.unmap(project2);

    GitProjectData.delete(project);
    GitProjectData.delete(project2);

    project.delete(true, true, null);
    project2.delete(true, true, null);

    repository.close();
    repository2.close();

    org.eclipse.egit.core.Activator.getDefault().getRepositoryCache().clear();

    FileUtils.delete(gitDir, FileUtils.RECURSIVE);
    // gitDir2 is inside project, already gone
  }
예제 #11
0
  /**
   * This method starts a Job that refreshes all open projects related to the repository and
   * afterwards triggers the (asynchronous) recalculation of the IndexDiff. This ensures that the
   * IndexDiff calculation is not working on out-dated resources.
   */
  public void refreshResourcesAndIndexDiff() {
    String repositoryName =
        Activator.getDefault().getRepositoryUtil().getRepositoryName(repository);
    String jobName =
        MessageFormat.format(CoreText.IndexDiffCacheEntry_refreshingProjects, repositoryName);
    Job job =
        new WorkspaceJob(jobName) {

          @Override
          public IStatus runInWorkspace(IProgressMonitor monitor) {
            try {
              IProject[] validOpenProjects = ProjectUtil.getValidOpenProjects(repository);
              ProjectUtil.refreshResources(validOpenProjects, monitor);
            } catch (CoreException e) {
              return Activator.error(e.getMessage(), e);
            }
            refresh();
            return Status.OK_STATUS;
          }
        };
    job.setRule(ResourcesPlugin.getWorkspace().getRoot());
    job.schedule();
  }
예제 #12
0
 private UserPasswordCredentials getSecureStoreCredentials(final URIish finalURI)
     throws StorageException {
   EGitSecureStore secureStore = org.eclipse.egit.core.Activator.getDefault().getSecureStore();
   UserPasswordCredentials credentials = secureStore.getCredentials(finalURI);
   return credentials;
 }
예제 #13
0
 private String getUpdateJobName() {
   String repoName = Activator.getDefault().getRepositoryUtil().getRepositoryName(repository);
   return MessageFormat.format(CoreText.IndexDiffCacheEntry_reindexingIncrementally, repoName);
 }
예제 #14
0
 private boolean checkRepository() {
   if (Activator.getDefault() == null) return false;
   if (!repository.getDirectory().exists()) return false;
   return true;
 }
예제 #15
0
 /**
  * Create a MergeOperation object. Initializes the MergeStrategy with the preferred merge
  * strategy, according to preferences.
  *
  * @param repository
  * @param refName name of a commit which should be merged
  */
 public MergeOperation(@NonNull Repository repository, @NonNull String refName) {
   this.repository = repository;
   this.refName = refName;
   this.mergeStrategy = Activator.getDefault().getPreferredMergeStrategy();
 }
예제 #16
0
파일: Activator.java 프로젝트: jlulwd/egit
 /** @return the {@link RepositoryUtil} instance */
 public RepositoryUtil getRepositoryUtil() {
   return org.eclipse.egit.core.Activator.getDefault().getRepositoryUtil();
 }