How to turn off automatic alignment for all project or for 1 file? - phpstorm

I use PhpStorm 2020.3.1 in my work and I encouneterd a problem when I work in a team and have
to fix merge conflicts(I made git pull at first and apply updates manually )
and next I check my updates with command
git diff
I see that some automatic alignment is considered by git as my changes.
I mean lines like :
$var1 = ‘value1’;
$varGte = ‘value2’;
$var= ‘value’;
are rendered into :
$var1 = ‘value1’;
$varGte = ‘value2’;
$var = ‘value’;
And it is very strange that I work with many files, but I have such a problem only with 1 file.
Are there some options ?
If there is a way remove such automatic alignment for all project or for 1 file?
Thanks!

Related

What do you do when you want to commit a hunk and git thinks you're changing another hunk of text?

I'm editing a json configuration file, and much of it is similar. I'd like to edit it in hunks, since I was overly eager and made more than one change to my working directory.
I removed the configurations for two pages.
I'd prefer to add the changes to the index (the stage) separately in two separate commits, by adding hunks to them; however....
When I do go to do this; git ends up confusing the lines I remove with lines from the second page's configuration using git add -p config.js and it ends up in several hunks, looking something like this:
# Manual hunk edit mode -- see bottom for a quick guide
## -665,25 +665,30 ## var handlebarTemplateGen = function(loadedContent, filePathsArray) {
}
]
},
+ /*BEGIN: Controller*/
{
- "outputfile":"../../someplace.org/removeMe1.html",
+ "outputfile":"../../someplace.org/removeMe2.html",
"processingOrder": [
{
"view":"views/common/empty.view",
"template":"HeadStart.mustache"
},
+ /*
{
- "view":"views/removeMe1/meta.view",
+ "view":"views/removeMe2/meta.view",
"template":"meta.mustache"
},
+ */
{
- "view":"views/removeMe1/HeadEnd.view",
+ "view":"views/removeMe2/HeadEnd.view",
"template":"HeadEnd.mustache"
},
+ /*
{
"view":"views/common/empty.view",
"template":"SocialMediaShareScripts.mustache"
},
+ */
{
"view":"views/index/navbar.view",
"template":"navbar.mustache"
# ---
# To remove '-' lines, make them ' ' lines (context).
# To remove '+' lines, delete them.
# Lines starting with # will be removed.
...and I've tried about everything, but I can't seem to get just the changes to removeMe1 on the stage without also having the removeMe2 changes come along for the ride.
I tried following the instructions about counting lines when editing manually hunks in joaquin's post here, but when I get to the last one that states that I can't remove the references lines I start to have an issue, since I want to remove a block of code and set the reference lines to - (which I understand you have to replace, not just type in)
There was also a video that was helpful on learning this here, but it didn't really fix my issue; it simply told me about how lines should be counted.
I frequently get the "patch does not apply" error when doing this as well, usually because I turned a reference line into a - line.
Is there a way to split this by spiting hunks into separate commits, or is it just a bad idea to store json config files in git?

TortoiseHg Folder Comparison Doesn't Work Properly

When I clicked Diff to Local or Visual Diff, it used to be showing CodeCompare's Folder Comparison window, which is really nice looking. If you want to see how it looks like, please click on this link. But whatever happened I don't know, it stoped working and now is showing me this disgusting window when I say "Diff to Local" and "Visual Diff":
I have checked all the possible solutions, and did everything I knew and found but nothing seems to be working. Here the mercurial.ini content, which also happens to be the global setting of TortoiseHG:
[ui]
ssh="C:\Program Files\TortoiseHg\TortoisePlink.exe" -ssh -i "C:\Users\[Hidden]\ssh\id_rsa.ppk"
username = [Hidden]
merge = codecompare_merge
[tortoisehg]
fontdiff = Consolas,10,-1,5,50,0,0,0,0,0
fontlist = Consolas,10,-1,5,50,0,0,0,0,0
refreshwdstatus = always
fontcomment = Consolas,10,-1,5,50,0,0,0,0,0
fontlog = Consolas,10,-1,5,50,0,0,0,0,0
fontoutputlog = Consolas,8,-1,5,50,0,0,0,0,0
editor = notepad++
vdiff = codecompare_diff
[auth]
default.prefix = https://bitbucket.org
default.username = [Hidden]
default.password = [Hidden]
[merge-tools]
codecompare_merge.regkey=SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CodeCompare_is1
codecompare_merge.regname=InstallLocation
codecompare_merge.regappend=CodeMerge.exe
codecompare_merge.args=/SC=TortoiseHg /TF=$other /MF=$local /RF=$output /BF=$base /TT="Other: $other" /MT="Local: $local" /RT="Output: $output" /BT="Base: $base"
codecompare_merge.binary=False
codecompare_merge.gui=True
codecompare_merge.checkconflicts=True
codecompare_merge.premerge=Keep
[extensions]
extdiff=
[extdiff]
cmd.codecompare=C:\Program Files\Devart\Code Compare\CodeCompare.exe
opts.codecompare=/SC=Hg /W /title1="$plabel1" /title2="$clabel" $parent $child
[merge-patterns]
*.*=codecompare_merge
When I first installed CodeCompare, I honestly didn't add any of these things. It worked nicely. However, when this problem started to occur recently, I found this link with the hope it may help me, and added everything in my Mercurial.ini file and no luck so far.
Can anyone please help me on this?
Note: [Hidden]s were containing sensitive data, like my computer name, username, and password.
In (fresh) MergeTools.rc you already have 2 CodeCompare tools, extdiff not needed additionally (and your overloading in [merge-tools])
You forgot one key in definition for diffing directory (can be uses in merge-tools section) ???.dirdiff=True
MergeTools.rc define CodeCompare's both differ and merger in merge-tools, diff-definition
; 2-way diff only version of Code Compare
codecompare_diff.regkey=SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\CodeCompare_is1
codecompare_diff.regname=InstallLocation
codecompare_diff.regappend=CodeCompare.exe
codecompare_diff.diffargs=/SC=TortoiseHg /title1="$plabel1" /title2="$clabel" $parent $child
codecompare_diff.diff3args=/SC=TortoiseHg /title1="$plabel1" /title2="$clabel" /title3="$plabel2" $parent1 $child $parent2
codecompare_diff.binary=False
codecompare_diff.gui=True
codecompare_diff.dirdiff=True
and your diff-tool in interface will be codecompare_diff

Mercurial: TortoiseHg configuration to always prompt for manual resolve for all files when merging

We use Mercurial via TortoiseHg with the 'workbench'.
When merging branches, we often find the default (auto?) choice of updates is not what we want. We'd like to configure the tool to always prompt for any merge operation.
Each branch has some core files that we need to keep up to date between the two, but also some branch-specific files which need to be preserved.
If we update the core files in one branch we'd like to do a merge to get the latest core files in the other branch. However the default TortoiseHg makes automatic updates that we don't want.
Examples:
1) Branch '1' contains a file '1.xls' and branch '2' has an equivalent '2.xls' which are stored as binary. Merging '1' into a working directory based off '2' causes a delete of '2.xls' and an add of '1.xls'.
2) Branch '1' contains an updated file 'not_core.c' which has an equivalent 'not_core.c' in branch '2'. Merging '1' into a working directory based off '2' causes an unwanted automatic update of 'not-core.c' in '2'.
3) Branch '1' contains updated files 'core1.c' & 'core2.c'. Merging '1' into a working directory based off '2' causes an automatic update of both files, when we'd prefer a prompt to allow us to chose if these core files are updated. Maybe we want just 'core1.c' for now.
I have seen reference to setting 'mergetool.premerge = false' in mercurial.ini, and have tried some variants of this without success.
The ideal setup would be that the graphical manual resolve is triggered for every file that is different.
Can anyone help with a configuration that supports the functionality described?
Thanks, Ian
Three described cases have different nature in you case, you have to use different tricks for different cases
Cases 2 and 3 (non-conflicting changes in files of ranches) can be covered (TBT!) by disabling auto-merges in TortoseHG (Main menu - File - Settings - Global setting - TortoiseHG - "Auto-resolving merges": False /default - True/)
For case 1 (and other non-content changes - renames, changing attributes) situation is worse and automerge doesn't play: merge mirror history of changes from one branch to another, i.e if in common parent you have only 2.xls, which was deleted|renamed to 1.xls in source branch this change will be reflected in target.
You can try to use different "internal" merge-tool in such merges (when your prefer changes only from one branch - "dummy merge") - internal:local and internal:other. But - they work only for changed content (again!)
Maybe Keep "My" or "Their" files when doing a merge from TipsandTricks section will help (you can join mentioned merge-revert-resolve into new command in [aliases] and use it instead of ordinary merge, when needed)
You can configure this using the merge-patterns and merge-tools sections of hgrc. This set up allowed me to force kdiff3 to be used in my test:
[merge-patterns]
** = noautomerge
[merge-tools]
noautomerge.executable = kdiff3
noautomerge.args = $base $local $other -o $output --qall
noautomerge.priority = 1
noautomerge.premerge = False
This will turn off the automatic pre-merge that Mercurial does and start up kdiff3 instead.
It will do it for all files but it you might be better to amend the merge-patterns section to be a little more specific if that is possible.
Also, be aware of the possibility that your merge tool might automatically resolve the merge itself and if that happens look for command line options to turn that feature off.

How to configure Mercurial to use Kompare when merging?

I've tried adding merge=kompare to my ~/.hgrc, but when I run hg merge, it runs kompare, but there's no UI to be seen. Hg says merging path/to/first-file and stays there, actionless.
The kompare.args posted earlier probably wont work. I've had difficulty using Kompare for merging, especially 3-way merges (which are preferred and safe).
BTW, most of the other options are enabled by default I believe, but you can verify with: hg showconfig merge-tools
You are better off using kdiff3. Incase you are on Ubuntu Intrepid, kdiff3 was erroneously removed from the repos - but you can easily compile from source.
You will also need to add a section that explains how to call Kompare. I don't know Kompare, so I don't know what the command line should look like (no guarantees for the kompare.args line), but it should be something like this:
[merge-tools]
kompare.executable = C:\<path...>\kompare.exe
kompare.args = $base $local $other -o $output
kompare.priority = 1
kompare.gui = True
kompare.binary = True
If merges aren't detected correctly, you might want to add
kompare.checkconflicts = True
kompare.checkchanged = True
Kompare does not support 3-way diffs, so it can be used for Visual Diff feature only. Here's the config to make it work:
[merge-tools]
kompare.executable = kompare
kompare.diffargs = -c $parent $child
kompare.gui = True
Note the diffargs field instead of args.

Case-insensitive diffs in Mercurial

I'm using Mercurial (specifically TortoiseHg on Windows) to do version control of VBA code. Anybody who's tried this knows that VBA changes the case of every variable throughout a project whenever any declaration of that variable is changed anywhere in the project (regardless of scope). It makes version control a nightmare.
I would like to ignore case changes in my source code when performing diffs. What is the easiest way to do this? (some option for diff that I'm missing, an external diff utility, something else?)
NOTE: I am not talking about dealing with 'case-insensitive filenames' (yes, I'm talking to you Google...)
You can do that when diffing for your on-screen consumption using the ExtDiff Extension.
[extensions]
hgext.extdiff =
[extdiff]
# add new command that runs GNU diff(1) in case-insensitive mode
cmd.mydiff = diff
opts.mydiff = -i
Then you'd run hg mydiff from the command line. That, of course, requires you have a diff binary installed be it gnu's or other.
However, that's not going to be as helpful as you might like because internally, of course, Mercurial can't ignore case -- it's taking the cryptographic hash of the file contents, and those don't allow for wiggle room. So if you get this set up you'll do hg mydiff, and see no changes, and then do hg commit and see changes all over the place.
So you can make this work on-screen, but not fundamentally.
One option would be to find a visual basic code-cleaner, similar to indent for C-like languages, that normalizes variable case and run that in a mercurial commit hook. Then at least all the code going into source control will be consistent and you can diff across revisions accurately.
If you are okay with having your code in all lower-case, say, then you could employ the encode/decode hooks for this. It would work like this:
[encode]
*.vba = tr A-Z a-z
This will encode the file content in lower-case whenever you do a commit. The diffs are also computed based on the encoded (repository) version of the files.
Consider a file that contains
hello
Changing it in your working copy to
Hello World
will give a diff of
% hg diff
diff --git a/a.txt b/a.txt
--- a/a.txt
+++ b/a.txt
## -1,1 +1,1 ##
-hello
+hello world
Notice how the capital "H" and "W" has been ignored.
I don't really know anything about VBA code, so I'm not 100% sure this solution works for you. But I hope it can be a starting point.
One drawback is that you'll need to set this encode rule for all your repositories. The reposettings extension can help you here.
Here's the solution I have settled on. It is far from ideal, but better than the other alternatives I've considered.
I created an Autohotkey script that does the following:
reverts MS Access files in a repository with detected changes (to .orig files)
reads in the .orig file (the one with the changes)
reads in the existing file (the one already in the repository)
converts the text of both files to lower case
compares the lower case contents of the files
if the files still differ, the .orig file is restored so it may be committed to the repository
if the files are the same (i.e., they differ only in case, the .orig file is deleted because we don't care about those changes)
For files that have actual changes that we care about, I still see the case changes that were made as well. If that results in a lot of noise, I open the file in a comparison tool that allows case-insensitive compares (e.g., kdiff).
It's not a perfect solution, but it removes about 90% of the frustration for me.
Here's my script. Note that the script includes another Autohotkey script, ConsoleApp.ahk, which provides a function named, ConsoleApp_RunWait(). This is a 3rd party script that no longer works very well with 64-bit AHK, so I'm not including it as part of my answer. Any AHK function that executes a command line and returns the output as a string will suffice.
; This script checks an MS Access source directory and reverts all files whose only modifications are to the
; case of the characters within the file.
#Include %A_ScriptDir%\ConsoleApp.ahk
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; Allow for custom path to hg (support for moving to TortoiseHg 2.0)
IniRead hg, %A_ScriptDir%\LocalSettings\Settings.cfg, TortoiseHg, hg_path, hg
if 0 < 1 ; The left side of a non-expression if-statement is always the name of a variable.
{
MsgBox Usage:`n`HgIgnoreCase DirectoryWithFilesToScrub
ExitApp
}
SrcDir = %1%
StringReplace SrcDir, SrcDir, ", , All
StringRight test, SrcDir, 1 ; add trailing slash if necessary
ifnotequal test, \
SrcDir = %SrcDir%\
RestoreOriginals(SrcDir)
RevertCaseChangeModifiedFiles(SrcDir)
RevertCaseChangeModifiedFiles(SrcDir) {
global hg
includes = -I "*.form" -I "*.bas" -I "*.report" -I "*.table"
cmdline = %hg% revert --all %includes%
;Don't revert items that have been removed completely
Loop 3
{
Result := ConsoleApp_RunWait(hg . " status -nrd " . includes, SrcDir)
If (Result)
Break
}
Loop parse, Result, `n, `r
{
if (A_LoopField)
cmdline = %cmdline% -X "%A_LoopField%"
}
Result =
;msgbox %cmdline%
;revert all modified forms, reports, and code modules
Loop 3
{
Result := ConsoleApp_RunWait(cmdline, SrcDir)
If (Result)
Break
}
;MsgBox %Result%
Loop parse, Result, `n, `r
{
StringLeft FileStatus, A_LoopField, 9
If (FileStatus = "reverting")
{
StringMid FName, A_LoopField, 11
FullPath = %SrcDir%%FName%
ToolTip Checking %FullPath%
RestoreIfNotEqual(FullPath, FullPath . ".orig")
}
}
ToolTip
}
RestoreIfNotEqual(FName, FNameOrig) {
FileRead File1, %FName%
FileRead File2, %FNameOrig%
StringLower File1, File1
StringLower File2, File2
;MsgBox %FName%`n%FNameOrig%
If (File1 = File2)
FileDelete %FNameOrig%
Else
FileMove %FNameOrig%, %FName%, 1
}
RestoreOriginals(SrcDir) {
Loop %SrcDir%*.orig
{
;MsgBox %A_LoopFileLongPath%`n%NewName%
NewName := SubStr(A_LoopFileLongPath, 1, -5)
FileMove %A_LoopFileLongPath%, %NewName%, 1
}
while FileExist(SrcDir . "*.orig")
Sleep 10
}