Search in sources :

Example 1 with TagConflict

use of de.catma.project.conflict.TagConflict in project catma by forTEXT.

the class GitTagsetHandler method getTagsetConflict.

public TagsetConflict getTagsetConflict(String projectId, String tagsetId) throws Exception {
    try (ILocalGitRepositoryManager localGitRepoManager = this.localGitRepositoryManager) {
        String projectRootRepositoryName = GitProjectManager.getProjectRootRepositoryName(projectId);
        localGitRepoManager.open(projectId, projectRootRepositoryName);
        String tagsetSubmoduleRelDir = GitProjectHandler.TAGSET_SUBMODULES_DIRECTORY_NAME + "/" + tagsetId;
        File tagsetSubmoduleAbsPath = new File(localGitRepoManager.getRepositoryWorkTree().toString(), tagsetSubmoduleRelDir);
        localGitRepoManager.detach();
        String tagsetGitRepositoryName = projectRootRepositoryName + "/" + tagsetSubmoduleRelDir;
        localGitRepoManager.open(projectId, tagsetGitRepositoryName);
        Status status = localGitRepoManager.getStatus();
        File tagsetHeaderFile = new File(tagsetSubmoduleAbsPath, HEADER_FILE_NAME);
        String serializedTagsetHeaderFile = FileUtils.readFileToString(tagsetHeaderFile, StandardCharsets.UTF_8);
        TagsetConflict tagsetConflict = null;
        if (status.getConflictingStageState().containsKey(HEADER_FILE_NAME)) {
            GitTagsetHeader gitTagsetHeader = resolveTagsetHeaderConflict(serializedTagsetHeaderFile, status.getConflictingStageState().get(HEADER_FILE_NAME));
            serializedTagsetHeaderFile = new SerializationHelper<GitTagsetHeader>().serialize(gitTagsetHeader);
            localGitRepoManager.add(tagsetHeaderFile.getAbsoluteFile(), serializedTagsetHeaderFile.getBytes(StandardCharsets.UTF_8));
            tagsetConflict = new TagsetConflict(projectId, tagsetId, gitTagsetHeader.getName(), gitTagsetHeader.getDeletedDefinitions());
            tagsetConflict.setHeaderConflict(true);
            status = localGitRepoManager.getStatus();
        } else {
            GitTagsetHeader gitTagsetHeader = new SerializationHelper<GitTagsetHeader>().deserialize(serializedTagsetHeaderFile, GitTagsetHeader.class);
            tagsetConflict = new TagsetConflict(projectId, tagsetId, gitTagsetHeader.getName(), gitTagsetHeader.getDeletedDefinitions());
        }
        for (Entry<String, StageState> entry : status.getConflictingStageState().entrySet()) {
            String relativeTagPathname = entry.getKey();
            String absTagPathname = tagsetSubmoduleAbsPath + "/" + relativeTagPathname;
            StageState stageState = entry.getValue();
            switch(stageState) {
                case BOTH_MODIFIED:
                    {
                        String serializedConflictingTag = FileUtils.readFileToString(new File(absTagPathname), StandardCharsets.UTF_8);
                        TagConflict tagConflict = getBothModifiedTagConflict(projectId, tagsetId, serializedConflictingTag);
                        tagsetConflict.addTagConflict(tagConflict);
                        break;
                    }
                case DELETED_BY_THEM:
                    {
                        // them is the user on the dev branch here
                        // in this case the file comes from us (the team on the master branch)
                        String serializedConflictingTag = FileUtils.readFileToString(new File(absTagPathname), StandardCharsets.UTF_8);
                        TagConflict tagConflict = getDeleteByThemTagConflict(projectId, tagsetId, serializedConflictingTag);
                        tagsetConflict.addTagConflict(tagConflict);
                        break;
                    }
                case DELETED_BY_US:
                    {
                        // us is the team on the master branch here
                        // in this case the file comes from them (the user on the dev branch)
                        String serializedConflictingTag = FileUtils.readFileToString(new File(absTagPathname), StandardCharsets.UTF_8);
                        TagConflict tagConflict = getDeleteByUsTagConflict(projectId, tagsetId, serializedConflictingTag);
                        tagsetConflict.addTagConflict(tagConflict);
                        break;
                    }
                // TODO:
                default:
                    System.out.println("not handled");
            }
        }
        return tagsetConflict;
    }
}
Also used : Status(org.eclipse.jgit.api.Status) SerializationHelper(de.catma.repository.git.serialization.SerializationHelper) TagConflict(de.catma.project.conflict.TagConflict) StageState(org.eclipse.jgit.lib.IndexDiff.StageState) ILocalGitRepositoryManager(de.catma.repository.git.interfaces.ILocalGitRepositoryManager) GitTagsetHeader(de.catma.repository.git.serialization.models.GitTagsetHeader) File(java.io.File) TagsetConflict(de.catma.project.conflict.TagsetConflict)

Example 2 with TagConflict

use of de.catma.project.conflict.TagConflict in project catma by forTEXT.

the class GitTagsetHandler method getBothModifiedTagConflict.

private TagConflict getBothModifiedTagConflict(String projectId, String tagsetId, String serializedConflictingTag) throws Exception {
    String masterVersion = serializedConflictingTag.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q=======\\E(\\r\\n|\\r|\\n|.)*?\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
    String devVersion = serializedConflictingTag.replaceAll("\\Q<<<<<<< HEAD\\E(\\r\\n|\\r|\\n|.)*?\\Q=======\\E(\\r\\n|\\r|\\n)", "").replaceAll("\\Q>>>>>>> \\E.+?(\\r\\n|\\r|\\n)", "");
    GitTagDefinition gitMasterTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(masterVersion, GitTagDefinition.class);
    TagDefinition masterTagDefinition = gitMasterTagDefinition.getTagDefinition();
    GitTagDefinition gitDevTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(devVersion, GitTagDefinition.class);
    TagDefinition devTagDefinition = gitDevTagDefinition.getTagDefinition();
    TagConflict tagConflict = new TagConflict(masterTagDefinition, devTagDefinition);
    return tagConflict;
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) TagDefinition(de.catma.tag.TagDefinition) TagConflict(de.catma.project.conflict.TagConflict) GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition)

Example 3 with TagConflict

use of de.catma.project.conflict.TagConflict in project catma by forTEXT.

the class GitTagsetHandler method getDeleteByUsTagConflict.

private TagConflict getDeleteByUsTagConflict(String projectId, String tagsetId, String serializedConflictingTag) {
    GitTagDefinition gitDevTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(serializedConflictingTag, GitTagDefinition.class);
    TagDefinition devTagDefinition = gitDevTagDefinition.getTagDefinition();
    return new TagConflict(null, devTagDefinition);
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) TagDefinition(de.catma.tag.TagDefinition) TagConflict(de.catma.project.conflict.TagConflict) GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition)

Example 4 with TagConflict

use of de.catma.project.conflict.TagConflict in project catma by forTEXT.

the class GitTagsetHandler method getDeleteByThemTagConflict.

private TagConflict getDeleteByThemTagConflict(String projectId, String tagsetId, String serializedConflictingTag) {
    GitTagDefinition gitMasterTagDefinition = new SerializationHelper<GitTagDefinition>().deserialize(serializedConflictingTag, GitTagDefinition.class);
    TagDefinition masterTagDefinition = gitMasterTagDefinition.getTagDefinition();
    return new TagConflict(masterTagDefinition, null);
}
Also used : GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition) TagDefinition(de.catma.tag.TagDefinition) TagConflict(de.catma.project.conflict.TagConflict) GitTagDefinition(de.catma.repository.git.serialization.model_wrappers.GitTagDefinition)

Aggregations

TagConflict (de.catma.project.conflict.TagConflict)4 GitTagDefinition (de.catma.repository.git.serialization.model_wrappers.GitTagDefinition)3 TagDefinition (de.catma.tag.TagDefinition)3 TagsetConflict (de.catma.project.conflict.TagsetConflict)1 ILocalGitRepositoryManager (de.catma.repository.git.interfaces.ILocalGitRepositoryManager)1 SerializationHelper (de.catma.repository.git.serialization.SerializationHelper)1 GitTagsetHeader (de.catma.repository.git.serialization.models.GitTagsetHeader)1 File (java.io.File)1 Status (org.eclipse.jgit.api.Status)1 StageState (org.eclipse.jgit.lib.IndexDiff.StageState)1