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

Fix FileHistory/Blame for files not existing in the working directory #6893

Conversation

pmiossec
Copy link
Member

@pmiossec pmiossec commented Jul 5, 2019

Fixes #6458 and #6892

Proposed changes

The bad behavior comes from the fact that TryGetExactPath()
overwrite the out variable fileName with null
when return is false.
We should use another temporary variable.

Test methodology

  • Manual

Test environment(s)

  • Git Extensions 3.2.0
  • Build 8fee24f (Dirty)
  • Git 2.21.0.windows.1
  • Microsoft Windows NT 10.0.17134.0
  • .NET Framework 4.7.3416.0
  • DPI 192dpi (200% scaling)

@ghost ghost assigned pmiossec Jul 5, 2019
Copy link
Member

@gerhardol gerhardol left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good find
I added the issues to 3.2, this regression should be included

@pmiossec
Copy link
Member Author

pmiossec commented Jul 5, 2019

Even if I don't really know if 'TryGetExactPath()' is doing it's office...

I discovered with #6815 (comment), that the method is not working all the time well.

In this special case, where the casing is good because we got it from the file tree, the method that have for purpose to fix the casing, is to the contrary, returning a bad cased path....

My conclusion is that it should be either removed or called only when the input path is provided from places where we are not sure of the case accuracy, for example, the command line.

@RussKie
Copy link
Member

RussKie commented Jul 6, 2019

Let's change the BuildFilter method from local to private and expose it via a TestAccessor (and FileName too).
Then add a simple test for the following codepath (we can add tests for other code paths later):

            var fileName = FileName;

            // we will need this later to look up proper casing for the file
            var fullFilePath = _fullPathResolver.Resolve(fileName);

            if (_controller.TryGetExactPath(fullFilePath, out fileName))
            {
                fileName = fileName.Substring(Module.WorkingDir.Length);
            }

            // Replace windows path separator to Linux path separator.
            // This is needed to keep the file history working when started from file tree in
            // browse dialog.
            FileName = fileName.ToPosixPath();

@codecov
Copy link

codecov bot commented Jul 6, 2019

Codecov Report

❗ No coverage uploaded for pull request base (master@0ecb626). Click here to learn what that means.
The diff coverage is 45.78%.

@@            Coverage Diff            @@
##             master    #6893   +/-   ##
=========================================
  Coverage          ?   47.72%           
=========================================
  Files             ?      736           
  Lines             ?    54077           
  Branches          ?     7087           
=========================================
  Hits              ?    25806           
  Misses            ?    26878           
  Partials          ?     1393
Flag Coverage Δ
#production 36.86% <22.41%> (?)
#tests 97.66% <100%> (?)

@RussKie
Copy link
Member

RussKie commented Jul 6, 2019

@pmiossec I pushed a refactoring idea, to make the code testable.
Could you please have a look and confirm whether it is functionally equal to the original code.

@gerhardol
Copy link
Member

I discovered with #6815 (comment), that the method is not working all the time well.

For 3.2, I propose this is merged.

For next release, I propose the call to TryGetExactPath() in FormFileHistory is removed and added to
GitUICommands.cs RunFileHistoryCommand(), the only "external" source for filenames.
Files in GitHub3 from the command line will still fail though...
This change could be done already for 3.2 if we are sure this is sufficient.

@pmiossec pmiossec force-pushed the fix_filehistory_notexisting_files branch from 927bcca to 19948f5 Compare July 8, 2019 13:46
@pmiossec
Copy link
Member Author

pmiossec commented Jul 8, 2019

@RussKie It seems ok. I have added tests (and also refactored the one on TryGetExactPathName()).

This change could be done already for 3.2 if we are sure this is sufficient.

@gerhardol I have the same point of view on how to solve the problem.
And I'm not confident enough about not introducing bad side effects so I let the fix for a next release...

@gerhardol
Copy link
Member

I approved the first commit. I am not sure after the rewrite, not sure if I see this as an improvement. Also most of the tests and changes should be removed with the proper fix: Remove TryGetExactPath from FormFileHistory*.cs

My first vote is to merge only the first commit here for 3.2.
Second alternative for 3.2 is to remove TryGetExactPath - this alternative feels better and better the more I look at it.
Third is to merge as is.
But I will not withdraw approval.

Post 3.2 is another discussion

@RussKie
Copy link
Member

RussKie commented Jul 9, 2019

Feel free to take the first into 3.2 and then merge the rest after the 3.2 cut

@pmiossec pmiossec force-pushed the fix_filehistory_notexisting_files branch from 19948f5 to e606dfd Compare July 9, 2019 07:40
@gerhardol
Copy link
Member

I have the same point of view on how to solve the problem.
And I'm not confident enough about not introducing bad side effects so I let the fix for a next release...

I can only see that the only call path where a path is not a GitItem is for GitUICommands.cs RunFileHistoryCommand()
I feel confident enough to suggest that this should be the solution in 3.2
The refactoring and added tests can be added to 3.3 (some refactoring needed).
It may be OK to skip updating RunFileHistoryCommand() in 3.2, the change still fixes the case where the path do not exist.

@pmiossec
Since you done the investigation here, do you want to submit a PR for 3.2?

gerhardol added a commit to gerhardol/gitextensions that referenced this pull request Jul 9, 2019
The bad behavior comes from the fact that `TryGetExactPath()`
changes the path to the file system path (if not existing, the path is cleared)

Alternative for gitextensions#6893
@pmiossec
Copy link
Member Author

pmiossec commented Jul 9, 2019

I would try to do it but most probably not before 2 or 3 days...

@gerhardol
Copy link
Member

I would try to do it but most probably not before 2 or 3 days...

You can copy the commit I did, or I submit the pr

pmiossec and others added 4 commits July 10, 2019 14:14
The bad behavior comes from the fact that `TryGetExactPath()`
overwrite the out variable `fileName` with null
when return is false.
We should use another temporary variable.

Fixes gitextensions#6458 and gitextensions#6892
to be able to improve unit tests
@gerhardol
Copy link
Member

This should be WIP and rebased on master with slightly updated testcases after the 3.2 release branch is created.
(This is probably an improvement even if I was negative to merge close to a release.)

@RussKie
Copy link
Member

RussKie commented Jul 31, 2019

Please resolve the merge conflict. We can probably squash it too 🤔

@RussKie
Copy link
Member

RussKie commented Aug 21, 2019

@pmiossec could you please resolve conflicts and squash, and we can take it in the 3.2 release.

@pmiossec
Copy link
Member Author

For me, this PR is no more needed since the merge of #6909

@gerhardol
Copy link
Member

@pmiossec
I believe you did some refactoring here. It is up to you if that is something that should be included in master

@pmiossec
Copy link
Member Author

No, I won't work on that. Maybe later.
I have some more priority changes to include first...

@RussKie
Copy link
Member

RussKie commented Aug 22, 2019

Closing. @pmiossec please re-open or open a new PR when you're ready.

@RussKie RussKie closed this Aug 22, 2019
Fabman08 added a commit to Fabman08/gitextensions that referenced this pull request Oct 7, 2019
* Path must be well formatted for Path.GetDirectoryName()

* Update namespace

* Fix i8n strings in GitUICommands

* GitHubHostedRemote: the underneath repository should be initialized with the GitProtocol already used

* Fix Clone Url when using https for parent repository

like what have been done in gitextensions#6515 (07acef9)

* Add menu entry to add the GitHub "upstream" remote

and fetch from it once added

* refactor: remove `IGitModule` from `IRepositoryHostPlugin`

to have a consistent api.
Following comment: gitextensions#6328 (review)

* Update translations

* Move UI-only strings to GitUI project

* Remove obsolete UI from TranslationApp

* Add script options c/sRemoteBranchName and RepoName

* Restore title of AppearanceSettingsPage

* Check for empty language selection

* Update/cleanup appveyor.yml

* Enforce update to translations as part of a PR

* stage *.xlf files - this way we ignore EOL issues,
* check if there are any xlf files are modified, and if so:
    - capture and publish the diff for the xlf files as git-diff-xlf.txt
    - break the build with a meaningful error

* Update translations

* Deprecate and remove InvokeAsyncDoNotUseInNewCode

Rewrite the callsite to use `InvokeAsync` instead, that switches
the execution context to the UI thread.

Closes gitextensions#6799

* RevisionLinks: Add templates for GitHub and AzureDevOps

+ Creation of GitHubRemoteParser & AzureDevOpsRemoteParser

* Check that directory (still) exists

before renabling the the FileWatcher for GitStatusMonitor

* Show changed images in all diff tabs

Previously, images were displayed as binary diffs, except some in
FormCommit:  .png and new worktree images

Other:
* FormCommit always show the worktree commit for index .png
* Show all images in FormCommit
(i.e. show index images and changed other than .png)
* Regression from a94a30a (ObjectId)
where blob guid were ignored and diff not shown
* Combined guid should never be used to get file blob guid
* openWithDiffTool action were not called from stash and RevisionDiff

* StatusMonitor: CancelToken to limit multiple commands

* Use CheckBox.Text instead of separate Label

in order to indicate focus and to make hotkey work directly

* Centralise the common logic

* fix: Ensure configured merge tool is present

KDiff3 was unbundled few versions ago, and some users no longer
have a diff/merge tool installed.

Until now the "resolve conflicts" dialog did not check whether a configured tool
physically existed in the system.

An error dialog is shown to the user if the tool is absent.

Closes gitextensions#6687

* Enhance error messages

* Rename to EnsureCommitMessageSecondLineEmpty

* Do not skip empty lines

fix regression introduced by commit template handling

* Factor out method and add tests

* Reposition buttons and add tooltips

* Update the layout for scaling

* Require repro steps before submission

Ask a user to provide more information before a report can be submitted.

Closes gitextensions#6607

* Update translations

* SettingsCache: Tempfile in temp dir

* Hide Watermark, too, if FilterComboBox invisible

make appearance the same as "There are no unstaged changes"

* refactor: Move email settings from General to Detailed

* Fix TryParseAsciiHex bytes bounds check

* Fix "Blame to previous revision"

to select the first commit before the revision selected (so the previous, no!?!)

Partly fix gitextensions#6605

* Blame: Add a context menu item to blame selected revision

to make explicit what could be done by double-clicking

* Refactoring & fixes following reviews...

* feature: Add setup telemetry dialog

Add a dialog to the setup that asks user's permission to capture telemetry information.

The setup will execute a script that will update user's configuration that is stored in
C:\Users\<user>\AppData\Roaming\GitExtensions\GitExtensions\GitExtensions.setting
with the user's selection.

* Disable blame menu items if revision is not in the revision grid

* feature: Add ApplicationInsights telemetry

Relates to gitextensions#6021

* Capture (selected) application telemetry information
* Prompt user to allow telemetry upon start up, if it isn't configured
* Allow telemetry information capture be toggled via a About menu
* Allow telemetry information capture be toggled via the settings dialog

The following information is captured:

Application-Level includes:
* Exception information
* Version number (e.g. 2.0.x.x)
* Is portable version
* Build type (whether the application is an official release build or not)
* Selected layout settings (such as visibility of the left panel, commit info position etc)
* Change of selected layout settings
* Git version (e.g. 2.19.0)
* SSH client (e.g. OpenSSH or PuTTY)

Operating System-Level includes:
* Version (e.g. Windows 10.0.17763.0)
* Machine Name (e.g. MyFastPC)
* .NET CLR version (e.g. 4.0.30319.42000)
* .NET SDK version (e.g. dotnet:2.10.0-24102)
* Current culture
* Current UI culture
* Number of monitors
* Resolution of all monitors
* Primary monitor DPI / scale factor

* feature: Add ApplicationInsights telemetry

Relates to gitextensions#6021

* Capture (selected) application telemetry information
* Prompt user to allow telemetry upon start up, if it isn't configured
* Allow telemetry information capture be toggled via a About menu
* Allow telemetry information capture be toggled via the settings dialog

The following information is captured:

Application-Level includes:
* Exception information
* Version number (e.g. 2.0.x.x)
* Is portable version
* Build type (whether the application is an official release build or not)
* Selected layout settings (such as visibility of the left panel, commit info position etc)
* Change of selected layout settings
* Git version (e.g. 2.19.0)
* SSH client (e.g. OpenSSH or PuTTY)

Operating System-Level includes:
* Version (e.g. Windows 10.0.17763.0)
* Machine Name (e.g. MyFastPC)
* .NET CLR version (e.g. 4.0.30319.42000)
* .NET SDK version (e.g. dotnet:2.10.0-24102)
* Current culture
* Current UI culture
* Number of monitors
* Resolution of all monitors
* Primary monitor DPI / scale factor

* Fix gitextensions#5944 by fixing --follow and revision reading

a306eb6 by mistake removed the "--follow" option when getting the git
log for history. This is reverted by this commit.
1f6b0ca by mistake removed parsing of the file name data into
GitRevision.Name. This is also reverted by this commit.
Together, these should fix rename tracking in the file history.

* Set recommended Git version to 2.22.0

* Fix FileHistory/Blame for files not existing in the working directory

The bad behavior comes from the fact that `TryGetExactPath()`
changes the path to the file system path (if not existing, the path is cleared)

Alternative for gitextensions#6893

* Redesign form "Commit template Settings"

* Commit designer changes due to /noscale
* Better menu item label in form commit
* Commit validation: better use of space for RegEx field
* Use a tab control to split "template" & "Validation"
* Left align controls

* Improve test readability on `TryGetExactPathName()`

* Stash: Add cherry pick of the currently selected file changes

Fixes gitextensions#6902

* fix: Commit message incorrect height at 150% scale factor

Closes gitextensions#6898

* Add support for "--rebase-merges" for newest version of git

now that we recommend v2.22 (gitextensions#6769) that deprecate "--preserve-merges"

See:
* for option deprection: git/git@fa1b86e#diff-c7361e406139e8cd3a300b80b8f8cc8dR1220
* for some doc: https://stackoverflow.com/questions/15915430/what-exactly-does-gits-rebase-preserve-merges-do-and-why/50555740#50555740

* fixup! fix: Commit message incorrect height at 150% scale factor

* Fix: Build error due to duplicate NSubstitue entry in csproj

it's already in the proj as a package reference

* Sign contributors.txt

* signed contributors.txt

* ReleaseNotesGenerator plugin To field defaults to "HEAD" (gitextensions#4444)

* fix Delete tag not working

Fixes gitextensions#6281

* improved validation on create new repository dialog (fixes gitextensions#6955)

* Add an option to sort commits by author date in the revision graph.

* Adding myself to contributors.txt

* fix: Illegal characters in path

Do not crash the app if a repository contains illegal characters.

Closes gitextensions#6982

* fix tests

* fix: Remote Repositories List Empty

Restore saving a successfully cloned repository to the list of recent remotes.

Fixes gitextensions#6983

* Add option for default pull action in setting page

This change adds a dropdown for choosing default pull action
on the general tab in main setting dialog.

* Delete obsolete branches plugin - fix gitextensions#6813

* Add codescene.io analysis results (gitextensions#6272)

Codescene.io doesn't require any build programming, just a free account and an integration button click at codescene.io.
This may be a perfect fit for codecov analysis already in place.

* Replace git-diff patience with histogram

* Fix: Commit Dialog Spell Checker

* TortoiseGitMerge.exe old default name

* Adding myself to contributors.txt

* Fix: Proper spacing (gitextensions#7002)

Fix: Proper spacing

* Updated changed github id

* Fix: Keep push dialog open on failure (gitextensions#6367)

* The GroupBox items contained in the form need to… (gitextensions#7021)

* Fix for issue gitextensions#7020. The GroupBox items contained in the form need to have their AutoSize properties set to true, so they can resize when their contained controls do.

* Added my name to the contributors

* Settings: Display label to the top to make UI more readable on multiline controls

* should fix: [NBug] Sequence contains no elements gitextensions#7011

* fix: Crash when suggest merge/diff tool paths

If merge/diff tool paths enclosed in quotes, clicking on "Suggest" button
would crash the app.

Strip quotes from paths before attempting to suggest.

Fixes gitextensions#7000

* Display icons in commit templates menu items

* Fix potential bad end of line replacement

If the value contains a `\r\n`, the result will contain `\r\r\n`
which duplicate blank lines at the loading and each time a settings is changed and saved...

* JiraCommitHintPlugin: fix bad condition

* JiraCommitHintPlugin: Open the settings when not enabled

* Add scripts for BeforeFetch and AfterFetch (gitextensions#7026)

Additional scripts that should be executed before/after fetch can be added.

Fixes gitextensions#4909

* Fix: Add "Force push with lease" to the push dialog (gitextensions#3934)

* Generate GitHub OAuth token with github api

* Settings: Ensure that `CustomControl` is set

if we let the Setting(s) classes create the controls.
Otherwise, it could will trow a NRE if we access it to get the current value

* Add me (KvanTTT) to contributors.txt

* fix: Overflow error in Commit Dialog

DiffViewerLineNumberControl did not handle when MaxLineNumber was 0. Either an empty file can cause this (in this case _diffLines is empty so no problem) or a file where diff hunks were lost due to encoding errors.

Fixes gitextensions#7023

* Add a `PseudoSetting` to display controls that are not settings

i.e. that don't save a value in the settings files.
It is used to easily display a control that is not a setting (linklabel, text,...)

PS: Solve problem linklabels truncated horizontally of vertically if the good size is not set
(because the size no more have to be set)

* JiraCommitHintPlugin: Simplify settings definition by using`PseudoSetting`

Solve LinkLabel slightly truncated vertically

* Plugins: Being able to change CredentialsControl labels

to specify other things than the currently "User name" / "Password".

For example: "email" / "Token"

* Add me (palver123) to contributors.txt

* Update the GitExtensionsDoc submodule to 3.2

* Allow multi-select of files in FormStash

* Clarify Settings-Stash label

* File suffix incorrectly detected

If the file has no extension but the directory path has a period

* Ignore difftool for CombinedDiff

* fix installer for Win7

* Fix scrolling for committers label in statistics plugin (gitextensions#7092)

* Fix scrolling for committers label in statistics plugin

* Fix opencover not submiting reports

Looks like a regression on Appveyor side after they updated the VS2017
image.
The opencover now needs to be run as admin (?)

* Reintegration of PluginManager.

* Fix duplicate ignored tests

* Remove test assuming local file paths

* correctly call hMSBuild batch file

* Update version

* Add dummy item for the menu entry to appear expandable (7046)

Add dummy item for the menu entry to appear expandable (7046)

* JiraPlugin: Fix way to define TranslationString that prevent translation

+ remove TranslationString redundant with settings caption
(which is translated when defined in a private field!)

* Remove KDiff3 hardcoding

* Update README.md

* Update ChangeLog.md

* Update README.md

* Set repo workingdir from env only if cmd line arguments

This will allow starting with the dashboard in the debugger

* Set recommended Git version to 2.23.0

* PathUtil.GetDirectoryName did not accept root dirs

* Avoid exception when starting from commandline with rooted dir

* fix incorrect user-agent

Fixes gitextensions#7157

* Add hotkeys for middle of rebase etc.

* exename not set for tortoisemerge

* Consider the end-of-body marker everywhere

in the detection of single-line commit messages
(completes 53ebf95)

* Add more test cases for empty lines in commit msgs

addendum to PR gitextensions#6877

* Allow 'Amend Commit' for any CommitKind

reverts 82f125d partially

* Improve some mnemonics of commit dialog

* ConEmu 19.7.14

* Refactor: argument always null; positive logic

* correctly detect script options starting with "s"

resolves regression from commit 1b8bb93

* FormBrowse: provide RevisionGrid to ScriptRunner

* Add NUnit tests for ScriptRunner; handle nulls

* Settings: Prevent the multiple creation of controls

because `GetSettings()` (where controls are created) is call 3 times
that ends with that the controls displayed are not the one
that are the ones set in `CustomControl` property.

And that can cause problems if we manipulate `CustomControl`in the setting page
to get (until the setting is saved) or set a value.

We **must** keep the strategy that `GetSettings()` return every time new controls
because the previous instances of the controls are disposed when the settings form is closed.

These changes ensure that the `GetSettings()` method is called only **1** time.

The 2 other times (use of `.Any()`) has been replaced by a `HasSettings` property.

* Add modifyCommitMessageButton

* GitStatusMonitor: Timer wraps after 25 days

 * Always compare timer diff (to handle timer wraparound after 25 days)
 to avoid missing updates while command is running
 * Increase min update time 3s -> 5s at changes in the file system
 * Use locks consistently
 * Start interactive update only once to avoid race where two commands started

* Gerrit Plugin fixes/improvements

Fix syntax for gerrit push command
Fix Gerrit Publish dialog layout
Add CC and Hashtag to Gerrit Push
See: https://gerrit-review.googlesource.com/Documentation/user-upload.html#_git_push

* Try fix gitextensions#7205, gitextensions#7193

* Branch list could contain '+'

Seen in CommitInfo
Added test

* Popup when error staring mergetool

* Catch ConEmu exception for Done()

* Support older Gerrit API

Close gitextensions#7200

* Update contributors.txt (gitextensions#7220)

* Update contributors.txt

* Blame: Fix missing commit metadata on some commits

due to "orphan" filename lines that has for effect to overwrite good commit data
by incomplete ones when "Detect move and copy in all files" is enabled.

For example, command:

`git blame --porcelain -M -C -w -l "18fcca6d89c2d38ac1830697b5da3f78630b226e" -- "GitUI/Translation/English.Plugins.xlf"`

returns (part of the file):

`8f8393c283e7ad60c02805182d6778e5fc0c8b28 180 13
	      <trans-unit id="MsBuildEnabled.Caption">
b1d567e 7506 14 3
filename GitUI/Translation/English.xlf       <= orphan line that breaks the blame
	        <source>Enabled</source>
b1d567e 7507 15
	        <target />
b1d567e 7508 16
	      </trans-unit>
8f8393c 184 17 12
	      <trans-unit id="MsBuildPath.Caption">`

* Update contributors.txt

Fix emails

* Update readme

* Exclude "fixup!" and "squash!" prefixes from commit message RegEx validation

That prevent a boring question to be asked to the user
because the commit message doesn't follow the regex when
"fixup!" or "squash!" prefixes are used.

* Dont confirm switch worktree option (gitextensions#6864)

Dont confirm switch worktree option (gitextensions#6864)

Dont confirm switch worktree option (gitextensions#6864)

* GitIndexWatcher: check that directory exists before enabling

* Settings: Regenerate the Controls when previous instance was disposed

because we don't control the controls lifecycle
and the settings controls are disposed when settings are closed.

It depends on how the settings control is defined but could prevent exceptions
(and make plugins easier to write)

* Ordering of options

Ordering of options

* Add support for command line commit message when committing

close gitextensions#7219

* sort fields

* Add tests for `ArgumentBuilder`
@pmiossec pmiossec deleted the fix_filehistory_notexisting_files branch May 24, 2020 10:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

History not shown for a new file in a different branch
3 participants