-
-
Notifications
You must be signed in to change notification settings - Fork 86
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
[FEATURE] Adds fallback for changed files for first push #234
[FEATURE] Adds fallback for changed files for first push #234
Conversation
Example solution for issue #233 |
return $ranges; | ||
} | ||
|
||
private function getHashOfBranchOrigin(): string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is the actual fix. All other files are just changes because the repository is needed.
With git reflog show
I get a list of all changes since the branch was created.
This looks like this:
4cd8bca1a853cde29a8a238ea24a36cf64898661 (HEAD -> feature/test) feature/test@{0}: commit: Improvement 2
05b5141ca91790d2becac4465232fa8ad695793e feature/test@{1}: commit: Improvement 1
3e6bc3932b396aa86b8e7d67188944956701bc13 (origin/master, master) feature/test@{2}: branch: Created from HEAD
The bottom entry of this list is the creation of the branch and it's hash can be used to get a list of changed files since the branch was created.
$processor = new Processor(); | ||
$reflog = $processor->run(sprintf('git reflog show --no-abbrev %s', $currentBranch)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be moved to SebastianFeldmann\Git\Repository
or one of the operator classes
This is even trickier than I thought. You tacked the problem at the And your fallback way of using the I tried to figure out some other ways to identify all the files that changed. Normally any That means And that's kind of true with one caveat. There are two ways of referencing the 1. Using the upstream HEAD (default branch)
This works if you have set a default branch.
You can set the default brach by executing If you don't have this setup properly the 2. Using the branch reference directly
This works if you haven't set a default branch. The problem being that it fails if you have done it.
If you have set a default branch it fails because, again ConclusionMy preferred course of action would be:
I'm still struggling with (2). The only way I could find so far to figure out if a default branch is set is running.
If the
So in order to detect the changed files I would:
If you know of anything I'm missing here please let me know ;) The even trickier part if figuring all this out for the first push of an so far empty repository. But I will tackle that problem, after we solved this one because that should really be an extreme edge case were someone has setup the Cap'n before even doing the first push ;) /cc @shochdoerfer @heiglandreas @bcremer @ramsey maybe you have some better ideas. |
I am not so deep into Git internals that I could provide a better option. The only thing that comes to my mind would be to set Also, I am wondering why I haven't been hitting the problem. Need to investigate, I guess. |
@shochdoerfer The issue comes up if a new branch gets pushed to a remote that does not exist on the remote so far. So we can ignore the whole The only right way to check is Since we don't know the root-branch for the current branch for sure we can't do something like
So far I could not find a way to reliably figure out the branch point without knowing the parent branch name. I will go with the |
I know the topic is very difficult. It took me a whole day to figure out a way to still get the files, which was quite weird for me as every GUI I know (being it specific git GUIs or an IDE like PhpStorm) shows me the changed files before I push. Even if the remote branch does not exists yet. Even if there are edge cases where it will not work or not work 100% I think implementing it is better than not having any files at all, because as it is right now the CHANGED_FILES variable is not usable at all for our workflow. Thank you for considering my solution and for the quick response |
Yes you are absolutely right @Eydamos I will switch some more things around to streamline the "changed files" thing even a bit more internally. I will also, just as you suggested, move some of the logic to the A huge thanks for taking the time to investigate this and providing the proof of concept implementation it is highly appreciated. I think I need at least a day or two to get everything working properly again. |
Take your time. I will just not use the pre-push for now as the check is not too important. If you need any help e.g. for testing or so let me know |
It's fixed. Just in You can give it a try by requiring CaptainHook version
but then you can test it locally if you want. I will make some final tests, and then tag a new version. |
I will close this since a lot of it made it's way to |
Thank you very much for your awesome work. Everything works like a charm now |
No description provided.