Comments (17)
BTW the issue you had with the tags is exactly why I have the condition NotOnBranch
. Tags are only pushed from the master branch so I skip the check for this branch as the branch itself is protected any way so nobody could push actual changes to it
from captainhook.
Ok, then I will rollback the {$CHANGED_FILES}
behavior and introduce the new {$BRANCH_CHANGES}
placeholder and Condition
.
from captainhook.
Works like a charm now. As usual thank you very much for the quick response and fix
from captainhook.
That's strange. Force pushing works fine for me.
- Change file X
- Commit
- Push the change (CHANGED_FILES => X)
- Amend commit
- Force push (CHANGED_FILES => X)
Git puts the following into the stdIn
refs/heads/main a74336878c058b6902df202db2f2253868cf2421 refs/heads/main 6e1fcae8e07c60775a9d777cbcfe54b3c63566d8
a74336
is the new commit hash 6e1fcae
is the amended old hash.
The detected revision range 6e1fcae..a74336
works just fine to detect the files changed made with the amend.
Could you list a more detailed list of commands you execute to reproduce the problem?
from captainhook.
Example:
I change the following files:
- CHANGELOG.md
- some_script.php
I commit and push
Then I realise I have a typo in my some_script.php
so I fix it and the amend the commit and force push
The CHANGED_FILES
now only contains some_script.php
because that is the difference between the local hash and the remote hash
from captainhook.
And I would think that's correct :)
Because CHANGELOG.md
is already on the remote in exactly that state.
So if you have checks on .md
files it should have been checked before.
If you use changes to .md
files to trigger some other local workflow I would suggest writing a custom Condition
or Action
to implement the behavior you need.
from captainhook.
Of course this is correct. Which is why I requested a ALL_CHANGED_FILES
placeholder which shows all changed files since the creation of the branch. I at least see a use case for this and unfortunately there is also no way how I could add custom placeholders.
If you think this is not useful this is totally fine. Then I will just write a whole custom action which get's the changes from the reflog. As I have both the repository and IO it should be possible.
I just want to make sure that in your current branch you have modified the CHANGELOG.md file as sometimes people forget this and sometimes you also do not realised this in the PR and merge it without the CHANGELOG being changed
{
"pre-push": {
"enabled": true,
"actions": [
{
"action": "echo {$ALL_CHANGED_FILES|of-type:md} | grep 'CHANGELOG.md'",
"config": {
"label": "Check for 'CHANGELOG.md'"
},
"conditions": [
{
"exec": "\\Company\\Project\\Condition\\NotOnBranch",
"args": [
"master"
]
}
]
}
]
}
}
from captainhook.
Uhhh I like this
"conditions": [
{
"exec": "\\Company\\Project\\Condition\\NotOnBranch",
"args": [
"master"
]
}
I will steal that one for sure ;)
Regarding the {$ALL_CHANGED_FILES}
placeholder. I'm not sure how useful it would be to include.
What would you say to a placeholder {$BRANCH_START|compared-to:...}`?
Then you could use something like this
{
"action": "git diff --name-only {$BRANCH_START|compared-to:master}..HEAD | grep 'CHANGELOG.md",
"config": {
"label": "Check for 'CHANGELOG.md'"
},
"conditions": [
{
"exec": "\\Company\\Project\\Condition\\NotOnBranch",
"args": [
"master"
]
}
]
}
from captainhook.
I think this is what you need
git log --name-only --format='' master..HEAD | grep CHANGELOG.md
If you are sure that the master
branch is the source of your branch you can use this.
It will output all files changed by any commit that is in your current branch but not in the master
branch.
If you create feature branches (2) from feature branches (1). Running this will within branch (2) will list all files from (1) and (2) so if anyone in (1) already changed the CHANGELOG.md
you could get a false positive.
But this boils down to the same problem we faced with the PRE_PUSH
stuff. If you don't provide a reference manually, in your case master
determining it properly is only working with the reflog
and that only works if you haven't fetched that branch from a remote.
from captainhook.
I can not just compare to master. We have dozens of repositories so I made one repository that has a captainhook config with all the hooks. Some of those repositories have master
some have main
and some 2.x
so I can not hardcode this.
BTW beside the NotOnBranch
condition I also have a NotOnBranchByRegEx
so I can compare it against /\d+\.x/
;)
from captainhook.
Me playing around with 5.20.*
I run into more an more problems with the reflog
solution.
If I push and then tag the repo and then just push the repo I get a zero hash for the tag because it does not exist on the remote.
This leads the Cap'n to use the reflog
solution to figure out the changes.
While working on the main branch this now returns basically all files of the repository :)
Not sure that makes sense
I would have to check if the rev I'm receiving via stdIn
is a tag or a commit.
Maybe it would be best to introduce a new placeholder for the reflog
stuff because now it causes more problems than it solves.
from captainhook.
So here are my thoughts:
- So far the
reflog
solution seems pretty unstable especially when working onmain
directly. - I will most likely deactivate the
reflog
fallback and return to theCHANGED_FILES
behavior <5.20.0
. - I will introduce a new placeholder and condition to check the changed files for the current branch.
- I'm struggling to find a good name for the placeholder, and I'm still not sure that
reflog
is the best course of action.
Ideas so far
{$BRANCH_CHANGES}
, {$BRANCH_CHANGES|compared-to:master|of-type:md}
"conditions": [
{
"exec": "\\Company\\Project\\Condition\\BranchChanges",
"args": [
{"compared-to": "master", "of-type": "md"}
]
}
]
If the source branch is not specified I could try to find it using the reflog
.
This would give you two options
- Push a branch immediately after creation to have a reference and use
{$CHANGED_FILES}
from there (my preferred solution) - Use
{$BRANCH_CHANGES}
to be sure to test everything but accept, that during multiple pushes you check the same files multiple times
It would potentially slow down the hooks because it would run checks on all files changed in a branch on every push. But I think this is the best solution.
What do you think?
from captainhook.
I would go with option 2 {$BRANCH_CHANGES}
as it is basically what I initially proposed and fits our needs and work style the most.
I don't mind checking all the files on every push it is actually what I really want
from captainhook.
So i just released version 5.21.0
The new placeholder is called {$BRANCH_FILES}
, "changes" was a bit vague and could also be a full diff.
So you should be able to do something like {$BRANCH_FILES|of-type:md}
. If possible you should use the compared-to
option but as you already stated that does not work for your use case. So if you don't provide that option the previous reflog
solution is used to find the branching point of the current branch.
If that can't be found the placeholder is empty.
You can make sure to only execute the action if files can be detected by using the Branch\Files
condition.
from captainhook.
I get an exception:
Command failed:
exit-code: 128
message: fatal: ambiguous argument '73cf48c..HEAD..': unknown revision or path not in the working tree.
The issue comes from calling Operator\Log::getChangedFilesSince()
as $revision
you give it $start . '..HEAD'
but Log\Log::byRange()
expects a $from
and a $to
param instead of a single string
from captainhook.
ARGHHH, will fix in a sec stay tuned :)
from captainhook.
Should be fixed in 5.21.2
released 30 sec ago :)
from captainhook.
Related Issues (20)
- Path to the composer autoload bootstrap file is not using a "realpath" HOT 6
- STAGED_FILES greedy when there is conditions HOT 1
- Using $ENV in run-exec config HOT 3
- Support for Relative Path to CaptainHook Executable in Generated Hooks HOT 5
- Allow Staged and Changed files condition to define diff-filter HOT 1
- PHP Fatal error: Argument #2 ($filter) must be of type array HOT 7
- InjectIssueKeyFromBranch does not work as expected HOT 10
- http://captainhook.info is not available anymore? HOT 1
- Support Symfony 7 HOT 2
- $CHANGED_FILES placeholder is empty for first push HOT 1
- Docker mode not working? HOT 9
- Linting fails when it shouldn't? HOT 3
- Default config file does not work HOT 3
- Error 'The "--input" option does not exist' when rerunning the hooks HOT 1
- captainhook/captainhook-phar failing, prefer captainhook/captainhook in README HOT 3
- Running Hooks in Subrepositories fails HOT 10
- Execute PHAR hook installation without an autoloader HOT 9
- [Feature] Parallel execution of actions HOT 1
- [Bug?] Pre-push hook failing with ddev/docker HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from captainhook.