Search in sources :

Example 16 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class FileGitEventInfo method getAffectedFileStatuses.

/**
 * @return the files affected by the current event.
 */
public List<FileStatus> getAffectedFileStatuses() {
    List<FileStatus> fss = new LinkedList<>();
    for (Iterator<String> iterator = affectedFiles.iterator(); iterator.hasNext(); ) {
        String path = iterator.next();
        fss.add(new FileStatus(GitChangeType.UNKNOWN, path));
    }
    return fss;
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) LinkedList(java.util.LinkedList)

Example 17 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class TreeViewTest method testConflict_resolveUsingMine.

/**
 * Resolve a conflict using my copy.
 *
 * @throws Exception If it fails.
 */
public void testConflict_resolveUsingMine() throws Exception {
    /**
     * Local repository location.
     */
    String localTestRepository = "target/test-resources/testConflict_resolveUsingMine_local";
    /**
     * Remote repository location.
     */
    String remoteTestRepository = "target/test-resources/testConflict_resolveUsingMine_remote";
    String localTestRepository2 = localTestRepository + "2";
    File file2 = new File(localTestRepository2 + "/test.txt");
    // Create repositories
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo1 = createRepository(localTestRepository);
    Repository localRepo2 = createRepository(localTestRepository2);
    // Bind the local repository to the remote one.
    bindLocalToRemote(localRepo2, remoteRepo);
    // Bind the local repository to the remote one.
    bindLocalToRemote(localRepo1, remoteRepo);
    // Create a new file and push it.
    new File(localTestRepository).mkdirs();
    File file = new File(localTestRepository + "/test.txt");
    createNewFile(localTestRepository, "test.txt", "content");
    add(new FileStatus(GitChangeType.UNKNOWN, "test.txt"));
    GitAccess.getInstance().commit("First version.");
    PushResponse push = push("", "");
    assertEquals("status: OK message null", push.toString());
    GitAccess.getInstance().setRepositorySynchronously(localTestRepository2);
    // Commit a new version of the file.
    setFileContent(file2, "modified from 2nd local repo");
    add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
    GitAccess.getInstance().commit("modified from 2nd local repo");
    push("", "");
    // Change back the repo.
    GitAccess.getInstance().setRepositorySynchronously(localTestRepository);
    // Change the file. Create a conflict.
    setFileContent(file, "modified from 1st repo");
    add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
    GitAccess.getInstance().commit("modified from 2nd local repo");
    // Get the remote. The conflict appears.
    pull();
    flushAWT();
    sleep(300);
    assertTreeModels("CONFLICT, test.txt", "");
    stagingPanel.getGitController().asyncResolveUsingMine(Arrays.asList(new FileStatus(GitChangeType.CONFLICT, "test.txt")));
    waitForScheduler();
    waitForScheluerBetter();
    assertTreeModels("", "");
    // Check the commit.
    CommitAndStatusPanel commitPanel = stagingPanel.getCommitPanel();
    assertEquals("Commit_to_merge", commitPanel.getCommitMessageArea().getText());
    commitPanel.getCommitButton().doClick();
    waitForScheduler();
    // TODO What should it assert here?
    assertEquals("", "");
}
Also used : Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) File(java.io.File) PushResponse(com.oxygenxml.git.service.PushResponse)

Example 18 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class TreeViewTest method testConflict_resolveUsingTheirsAndRestartMerge.

/**
 * Resolve a conflict using "their" copy, restart merge, and resolve again.
 *
 * @throws Exception If it fails.
 */
public void testConflict_resolveUsingTheirsAndRestartMerge() throws Exception {
    /**
     * Local repository location.
     */
    String localTestRepository = "target/test-resources/testConflict_resolveUsingTheirs_local";
    /**
     * Remote repository location.
     */
    String remoteTestRepository = "target/test-resources/testConflict_resolveUsingTheirs_remote";
    String localTestRepository2 = localTestRepository + "2";
    File file2 = new File(localTestRepository2 + "/test.txt");
    // Create repositories
    Repository remoteRepo = createRepository(remoteTestRepository);
    Repository localRepo1 = createRepository(localTestRepository);
    Repository localRepo2 = createRepository(localTestRepository2);
    // Bind the local repository to the remote one.
    bindLocalToRemote(localRepo2, remoteRepo);
    // Bind the local repository to the remote one.
    bindLocalToRemote(localRepo1, remoteRepo);
    // Create a new file and push it.
    new File(localTestRepository).mkdirs();
    File file = createNewFile(localTestRepository, "test.txt", "content");
    add(new FileStatus(GitChangeType.UNKNOWN, "test.txt"));
    GitAccess.getInstance().commit("First version.");
    PushResponse push = push("", "");
    assertEquals("status: OK message null", push.toString());
    GitAccess.getInstance().setRepositorySynchronously(localTestRepository2);
    // Commit a new version of the file.
    setFileContent(file2, "modified from 2nd local repo");
    add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
    GitAccess.getInstance().commit("modified from 2nd local repo");
    push("", "");
    // Change back the repo.
    GitAccess.getInstance().setRepositorySynchronously(localTestRepository);
    // Change the file. Create a conflict.
    setFileContent(file, "modified from 1st repo");
    add(new FileStatus(GitChangeType.MODIFIED, "test.txt"));
    GitAccess.getInstance().commit("modified from 2nd local repo");
    // Get the remote. The conflict appears.
    pull();
    flushAWT();
    assertTreeModels("CONFLICT, test.txt", "");
    // Resolve using theirs
    stagingPanel.getGitController().asyncResolveUsingTheirs(Arrays.asList(new FileStatus(GitChangeType.CONFLICT, "test.txt")));
    waitForScheduler();
    assertTreeModels("", "CHANGED, test.txt");
    // Restart merge
    ScheduledFuture<?> restartMerge = GitAccess.getInstance().restartMerge();
    restartMerge.get();
    flushAWT();
    assertTreeModels("CONFLICT, test.txt", "");
    // Resolve again using theirs
    stagingPanel.getGitController().asyncResolveUsingTheirs(Arrays.asList(new FileStatus(GitChangeType.CONFLICT, "test.txt")));
    waitForScheduler();
    assertTreeModels("", "CHANGED, test.txt");
    // Commit
    GitAccess.getInstance().commit("commit");
    flushAWT();
    assertTreeModels("", "");
}
Also used : Repository(org.eclipse.jgit.lib.Repository) FileStatus(com.oxygenxml.git.service.entities.FileStatus) File(java.io.File) PushResponse(com.oxygenxml.git.service.PushResponse)

Example 19 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method addAll.

/**
 * Adds multiple files to the staging area. Preparing the for commit
 *
 * @param files The files to be added.
 */
public void addAll(List<FileStatus> files) {
    Collection<String> filePaths = getFilePaths(files);
    try {
        fireOperationAboutToStart(new FileGitEventInfo(GitOperation.STAGE, filePaths));
        RmCommand removeCmd = null;
        AddCommand addCmd = null;
        for (FileStatus file : files) {
            if (file.getChangeType() == GitChangeType.MISSING) {
                if (removeCmd == null) {
                    removeCmd = git.rm().setCached(true);
                }
                removeCmd.addFilepattern(file.getFileLocation());
            } else {
                if (addCmd == null) {
                    addCmd = git.add();
                }
                addCmd.addFilepattern(file.getFileLocation());
            }
        }
        if (addCmd != null) {
            addCmd.call();
        }
        if (removeCmd != null) {
            removeCmd.call();
        }
        fireOperationSuccessfullyEnded(new FileGitEventInfo(GitOperation.STAGE, filePaths));
    } catch (GitAPIException e) {
        fireOperationFailed(new FileGitEventInfo(GitOperation.STAGE, filePaths), e);
        LOGGER.error(e.getMessage(), e);
    }
}
Also used : GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) FileStatus(com.oxygenxml.git.service.entities.FileStatus) RmCommand(org.eclipse.jgit.api.RmCommand) FileGitEventInfo(com.oxygenxml.git.view.event.FileGitEventInfo) AddCommand(org.eclipse.jgit.api.AddCommand)

Example 20 with FileStatus

use of com.oxygenxml.git.service.entities.FileStatus in project oxygen-git-client-addon by oxygenxml.

the class GitAccess method getFilePaths.

/**
 * Get file paths for the given file statuses.
 *
 * @param files The file statuses.
 *
 * @return the paths.
 */
private Collection<String> getFilePaths(List<FileStatus> files) {
    List<String> paths = new LinkedList<>();
    for (Iterator<FileStatus> iterator = files.iterator(); iterator.hasNext(); ) {
        FileStatus fileStatus = iterator.next();
        paths.add(fileStatus.getFileLocation());
    }
    return paths;
}
Also used : FileStatus(com.oxygenxml.git.service.entities.FileStatus) LinkedList(java.util.LinkedList)

Aggregations

FileStatus (com.oxygenxml.git.service.entities.FileStatus)210 File (java.io.File)136 Test (org.junit.Test)77 ArrayList (java.util.ArrayList)58 GitController (com.oxygenxml.git.view.event.GitController)53 List (java.util.List)50 Repository (org.eclipse.jgit.lib.Repository)49 GitControllerBase (com.oxygenxml.git.service.GitControllerBase)38 GitTreeNode (com.oxygenxml.git.view.GitTreeNode)33 JButton (javax.swing.JButton)33 SelectedResourcesProvider (com.oxygenxml.git.view.staging.ChangesPanel.SelectedResourcesProvider)26 IOException (java.io.IOException)25 AbstractAction (javax.swing.AbstractAction)24 JDialog (javax.swing.JDialog)24 GitResourceContextualMenu (com.oxygenxml.git.view.staging.GitResourceContextualMenu)20 RevCommit (org.eclipse.jgit.revwalk.RevCommit)19 URL (java.net.URL)18 Action (javax.swing.Action)18 CommitCharacteristics (com.oxygenxml.git.view.history.CommitCharacteristics)17 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)16