MarceloPrado / has-changed-path

GitHub Action that saves time and money in monorepo environments
MIT License
222 stars 33 forks source link

Detect dirty state of repository #14

Open ad-m opened 3 years ago

ad-m commented 3 years ago

What do you think about adding support detecting dirty state of repository also? You need run:

git diff-index --quiet HEAD -- ${path}

instead of:

git diff --quiet HEAD -- ${path}
MarceloPrado commented 3 years ago

Hey @ad-m, thanks for your suggestion. To be honest, I wasn't familiar with the diff-index command. Would you be willing to explain your use case?

At my side, I run has-changed-path after cloning the repository. This means the repo isn't in a dirty state scenario. Are you running something like a linter before the action?

ad-m commented 3 years ago

I would like detect non-committed changes in local repository. To have dirty repository clone repo and change file without commiting them. Your action is about committed changes and I suggest to test for uncommitted changes.

MarceloPrado commented 3 years ago

Hi @ad-m, sorry for the wait. I understood what you meant, great suggestion! Thanks 😀

I need to write a few unit tests for this function in order to guarantee the changes are being detected. After that, I would be willing to change to git diff-index.

My biggest fear right now is adding a breaking change, as some people are using this action in production.

Do you have any examples of testing git functionalities? My current idea is to create a bunch of test helper functions, such as: createFolder(name: string), createGitRepo(), createFile(name: string), stageFile(name: string), createCommit(msg: string). Then, I would use those functions to create a few common examples.

ad-m commented 3 years ago

My biggest fear right now is adding a breaking change, as some people are using this action in production.

At first, I thought that this should be an opt-in option - check commited / uncomitted changes.

Do you have any examples of testing git functionalities?

No, but I have experience with end-to-end API testing which requires a complex remote state to perform the operation.

In my experience, it is worth considering several elements:

Consider following snippet of code in JavaScript:

const withGit = (fn) => t => {
    try{
        const gitRepoPath = createGitRepo(fn);
        await fn(t, gitRepoPath)
    } finally {
        await cleanupGit(gitRepoPath);
    }
}
ava.test(withGit((t, gitRepoPath) => {
    t.true(true);
}));