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

apply gawd directly on git commits #1

Open
tommens opened this issue Oct 25, 2023 · 5 comments
Open

apply gawd directly on git commits #1

tommens opened this issue Oct 25, 2023 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@tommens
Copy link
Collaborator

tommens commented Oct 25, 2023

It could be useful to use the tool by providing as input just a commit reference in some git repo and a reference to a yaml file in that commit. In that case, the tool would apply the diff to that specific file in that commit, w.r.t. to previous available version of that file, in order to return the diff with all of the changes that were made by that commit to the file.

In the same vein, it would be useful to have the tool do the same thing for all yaml workflow files corresponding to given commit. (This would correspond to applying the tool several times, once for each yaml workflow file found in the commit.

@AlexandreDecan
Copy link
Collaborator

I tend to disagree with this proposal. The same way that diff aims to be applied "locally", with no explicit relation to git or GitHub, gawd should be "platform-agnostic" (esp. since GitHub is not the only platform supporting YAML workflow files for GitHub Actions). Moreover, "diff-ing" with a parent commit is just one use case among many different ones (three-way diffing, diffing a pull request, etc.). We can perhaps implement this as part of another tool, built on top of gawd and distributed as a separate package (nothing prevents us from creating a "meta-package" having as dependencies all libraries/tools we implement to support workflow files, so that a single install is enough to get all of them). If we go that way, I suggest that the tool at least support diffing a given filepath (a workflow file relative to the root of the repository or relative to the .github/workflows folder) given two git references (the two "commits" to compare). By default, we can assume first reference is HEAD, while second is its parent.

@AlexandreDecan AlexandreDecan added the enhancement New feature or request label Oct 30, 2023
@tommens
Copy link
Collaborator Author

tommens commented Nov 8, 2023

I actually saw "gawd" as an alternative to "git diff", not "diff". And "git diff" provides the option to simply compute the diff for a given commit, showing the changes between that commit and the next one. Similarly, "gawd" could be applied to a given commit, and compute all the changes found in all of the workflow files in that commit (w.r.t. the next commit, similar to how git diff does it). I agree that it is useful to have a workflow diff tool that can be unaware of git and GitHub, but this does not exclude the tool of supporting diffs on commits as well.

@AlexandreDecan
Copy link
Collaborator

The underlying tool used by git when doing a diff can be configured in a .gitconfig file, so if one wants to use gawd to perform diff operations between commits or branches, it is enough to change the default tool in the .gitconfig file. AFAIK, one can even specify that a specific tool should be used for a given file format/path (need to be checked), so perhaps we can already mention this in the documentation (with a practical example).

@tommens
Copy link
Collaborator Author

tommens commented Nov 8, 2023

Yes indeed, if it is as easy as that, then this should be documented, together with an example of how to do it, and also be mentioned in the associated tool paper.

@AlexandreDecan
Copy link
Collaborator

I haven't tested it yet, but this should do the work (or at least provide some pointers):

git config --local diff.gawd.command 'gawd "$2" "$5"'
echo '.github/workflows/*.yml diff=gawd' >> .gitattributes
echo '.github/workflows/*.yaml diff=gawd' >> .gitattributes

First line defines an additional diff command (using gawd). The --local can be replaced with --global to apply on all git repositories. The two next lines indicates that specific paths in the current git repository should be diff-ed by using gawd.

It seems there's a way to apply the two last lines on "all repositories", by defining a global .gitattributes file:

git config --global core.attributesfile <path>

... where <path> should be replaced by the path to the .gitattributes file containing (at least) the two following lines (and assuming these two lines are correct, please check them locally before ^^):

.github/workflows/*.yml diff=gawd
.github/workflows/*.yaml diff=gawd

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

3 participants