Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect dirty state of repository #14

Open
ad-m opened this issue Sep 27, 2020 · 4 comments
Open

Detect dirty state of repository #14

ad-m opened this issue Sep 27, 2020 · 4 comments
Labels
enhancement New feature or request

Comments

@ad-m
Copy link

ad-m commented Sep 27, 2020

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
Copy link
Owner

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
Copy link
Author

ad-m commented Sep 27, 2020

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 MarceloPrado added the enhancement New feature or request label Oct 8, 2020
@MarceloPrado
Copy link
Owner

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
Copy link
Author

ad-m commented Oct 8, 2020

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:

  • each test should have a separate clean environment, which in Git means you only need to create a temporary directory for each test
  • each test should define its state, and your proposal to use createFolder(name: string), createGitRepo(), createFile(name: string), stageFile(name: string), createCommit(msg: string) seems to be effective in this regard, because the test will be easy to read,
  • after completing the test (regardless of the result), it is worth cleaning up after yourself, which is well done by the wrapper using try { ...test... } finally {...cleanup...}.

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);
}));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants