-
-
Notifications
You must be signed in to change notification settings - Fork 813
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
Fixing a bug where the Git Status is written multiple times #169
Conversation
I've created two separate pull requests as they solve different bugs despite being in the same area of code, so not sure if you would want to accept none/one/both or they have different feedback and changes needed |
I definitely hadn't considered My hestitation with removing the global variable is that it will kill any other integrations that have been initialized (specifically posh-hg). My preference on unload would be to remove the specific For removing the specific member, it seems like a closure over the added |
The issue happens because I encapsulate PowerShell customisations and tweaks into a custom module. When I make a change it's quicker to unload the module and reload it for testing rather than restart the PowerShell shell. Looking back at the change it does seem much more sensible to remove the specific entry in the array that was added rather than just removing the entire variable.. I hadn't thought about other modules that may depend upon it existing. Though uncommon it feels correct to remove the posh-git scriptblock when the module is unloaded similar to avoiding a memory leak. I'll submit an updated version shortly 😄 |
I've simplified the change just down to the specific problem.. let me know if you'd prefer the change to be done in a new pull request to make the history cleaner. I did consider initialising the global variable using |
Much simpler, nicely done.
Up to you - feel free to clean up history in-place and just |
de80692
to
66200ac
Compare
The bug occurs when you Remove-Module posh-git and Import-Module posh-git As the variable VcsPromptStatuses already exists in the global scope from a previous import additional Write-VcsStatus calls are added to the variable. The change stores the posh-git prompt scriptblock in a variable so it can be referenced during the module unload event
66200ac
to
9476e30
Compare
I've rewritten history to clean it up and to remove the noise.. I didn't know you could update the history once pushed to GitHub, a good learning experience 😄 |
Fixing a bug where the Git Status is written multiple times
You'll find differing opinions if you should, but you can guess where I stand. Thanks! |
Fixing a bug where the Git Status is written multiple times
The bug occurs when you Remove-Module posh-git and Import-Module posh-git
As the variable VcsPromptStatuses already exists in the global scope from a previous import additional Write-VcsStatus calls are added to the variable.
The change removes the variable when the module is unloaded (which is good practice anyway) while still allowing the variable to exist in the global scope to enable the same extensibility hook
I've also placed the variable name used into another variable as it is being reused a few times so if it needs to change it only needs to be changed in one place - it may also be a candidate to be refactored into a module exported variable rather than a global