atomist-attic / artifact-source

ArtifactSource abstraction for source code
GNU General Public License v3.0
2 stars 3 forks source link

Cannot delete then add a file #30

Closed ddgenome closed 7 years ago

ddgenome commented 7 years ago

A typical pattern for adding a file from a Rug archive is

        const settings = ".settings.xml";
        if (project.fileExists(settings)) {
            project.deleteFile(settings);
        }
        project.copyEditorBackingFileOrFail(settings);

This no longer works. It seems marking the file as deleted at any point results in it being deleted in the resulting change set. So the resulting commit/PR deletes the settings file rather than have it changed to the contents of the settings file from the editor's archive.

alankstewart commented 7 years ago

I can't reproduce this at the artifact-source level nor the rug level. Deleting a file will result in a new ArtifactSource being returned without the file and will contain a FileDeletionDelta. Perhaps rather than deleting the file, replace the contents instead, which I think your workaround is doing

ddgenome commented 7 years ago

I can't reproduce it either with the current released versions or latest master of artifact-source, rug, and rug-cli. Hopefully it was fixed.

Here is the Rug I created to test it, running it it in local mode on itself.

import { File, Project } from "@atomist/rug/model/Core";
import { Editor, Parameter, Tags } from "@atomist/rug/operations/Decorators";
import { EditProject } from "@atomist/rug/operations/ProjectEditor";
import { Pattern } from "@atomist/rug/operations/RugOperation";

/**
 * Sample TypeScript editor used by AddNoOp.
 */
@Editor("NoOp", "does nothing")
@Tags("documentation")
export class NoOp implements EditProject {

    public edit(project: Project) {
        const path = "README.md";
        project.deleteFile(path);
        project.copyEditorBackingFileOrFail(path);
    }
}

export const noOp = new NoOp();