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

GitProcess: allow GIT_TRACE to point to full path #326

Merged
merged 1 commit into from
Oct 8, 2018
Merged

Conversation

derrickstolee
Copy link
Contributor

The GIT_TRACE variable can be helpful for diagnosing problems during Git commands. However, there are many places in VFS for Git that require parsing the Git output. Using GIT_TRACE=1 sends the output to stdout, which messes up this parsing. In the past, we have blocked that variable for this reason.

It would still be helpful to allow logging the trace output. Git allows a fully-qualified path as the value of GIT_TRACE and will append to that file instead. This is how we would like users to use GIT_TRACE when investigating issues. Unblock that type of setting.

Resolves #276

@derrickstolee
Copy link
Contributor Author

If anyone is looking at the builds right now, I do have a passing functional tests build but it didn't get updated. I'm re-running.

// If GIT_TRACE is set to a fully-rooted path, then Git sends the trace
// output to that path instead of stdout (GIT_TRACE=1) or stderr (GIT_TRACE=2).
if (key.StartsWith("GIT_TRACE", StringComparison.OrdinalIgnoreCase) &&
!(key.Equals("GIT_TRACE") && Path.IsPathRooted(processInfo.EnvironmentVariables[key])))
Copy link
Member

@jeschu1 jeschu1 Oct 3, 2018

Choose a reason for hiding this comment

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

Any reason why we wouldn't want to leave it in fancy linq?
Aka

            foreach (string key in processInfo.EnvironmentVariables.Keys.Cast<string>()
                .Where(x => x.StartsWith("GIT_TRACE", StringComparison.OrdinalIgnoreCase) 
                    && !Path.IsPathRooted(processInfo.EnvironmentVariables[x]))
                .ToList())
            {
                processInfo.EnvironmentVariables.Remove(key);
            }

Also IsPathRooted can throw an exception if value contains invalid chars, We should guard against that I think https://docs.microsoft.com/en-us/dotnet/api/system.io.path.ispathrooted?redirectedfrom=MSDN&view=netframework-4.7.2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good find on that exception! I'll need to check for invalid chars first, I guess.

The extra complication we are doing here is something that is too large to fit nicely into a .Where() clause. It's also kind of pointless that we .ToList() something that is looped in a foreach.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for going after this bug, it was actually a change I requested :-)

Why do you need the !(key.Equals(GIT_TRACE) bit?

Agree we can drop the ToList. It reads nicely to me in the Linq, but I'm happy to follow your lead here!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There are other GIT_TRACE_ variables, like GIT_TRACE_PERF, but I suppose we could stop interfering with those, too.

@@ -3,8 +3,7 @@
using GVFS.FunctionalTests.Tools;
using GVFS.Tests.Should;
using NUnit.Framework;
using NUnit.Framework.Interfaces;
using System;
using System.Collections.Generic;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need for this change anymore.

GitHelpers.ValidateGitOutput(command, expectedResult, actualResult);

string.IsNullOrWhiteSpace(expectedResult.Errors).ShouldBeFalse();
string.IsNullOrWhiteSpace(actualResult.Errors).ShouldBeTrue();
Copy link
Member

Choose a reason for hiding this comment

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

Why did one write to Errors but the other didn't? Shouldn't the ValidateGitOutput be checking the Errors?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ValidateGitOutput does check the errors, which is why this test was failing.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah test failure was

Extra: 15:11:06.229742 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
Extra: 15:11:06.245368 run-command.c:638       trace: run_command: C:/Repos/GVFSFunctionalTests/enlistment/5fa79051845344039854/src/.git/hooks/pre-command.exe status --git-pid=792
Extra: 15:11:06.354746 git.c:477               trace: built-in: git status
Extra: 15:11:06.370374 run-command.c:638       trace: run_command: C:/Repos/GVFSFunctionalTests/enlistment/5fa79051845344039854/src/.git/hooks/post-command.exe status --git-pid=792 --exit_code=0
Missing: 15:11:06.151614 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
Missing: 15:11:06.151614 git.c:477               trace: built-in: git status

Extra means it was in the actual but not in expected
Missing means it was in expected but not in actual

So it looks like both expected and actual will have something in Errors right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These tests are testing the wrong thing :(. The environment stuff we are checking is only for Git commands invoked from GVFS, while these tests are calling Git directly (not going through the code paths I'm checking). That's why they are failing.

@derrickstolee derrickstolee force-pushed the git-trace branch 5 times, most recently from b84d90c to 350838e Compare October 5, 2018 13:16
Copy link
Member

@kewillford kewillford left a comment

Choose a reason for hiding this comment

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

The changes look good, just need to get the tests fixed and passing.

@derrickstolee derrickstolee force-pushed the git-trace branch 4 times, most recently from 5e12623 to 3a5009f Compare October 5, 2018 16:37
@derrickstolee
Copy link
Contributor Author

@kewillford Could you take a look at the new test structure? It took me a while to figure out the right thing to do, and it's very different than what you approved.

Copy link
Member

@kewillford kewillford left a comment

Choose a reason for hiding this comment

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

This makes a lot more sense, since we are really only testing how VFSForGit handles the GIT_TRACE and not how it compares with the control repo. Only had a couple other questions but it looks good.

[TestFixture]
public class StatusVerbTests : TestsWithEnlistmentPerFixture
{
private enum ExpectedReturnCode
Copy link
Member

Choose a reason for hiding this comment

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

I don't see where this is used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oops. It was needed for a helper function I had copied in an earlier version. Will delete.

Dictionary<string, string> environmentVariables = new Dictionary<string, string>();

this.Enlistment.Status(trace: "1");
this.Enlistment.Status(trace: "2");
Copy link
Member

Choose a reason for hiding this comment

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

Do we need to verify anything for these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So gvfs status could fail to parse the git status it calls if the GIT_TRACE values are not removed.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like we are sending a gvfs status command. Will that cause a git status to run as well? I wasn't able to find that in the quick search I did. Could you point me at that code?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right. I thought it did, but it doesn't. I must call something, since logPath is filled with contents.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I took a look at my logs, and we actually run git config to get the remote url:

07:52:55.681330 exec-cmd.c:236          trace: resolved executable dir: C:/Program Files/Git/mingw64/bin
07:52:55.684326 run-command.c:638       trace: run_command: C:/_git/ForTests2/src/.git/hooks/pre-command.exe config --local remote.origin.url --git-pid=16732
07:52:55.808825 git.c:477               trace: built-in: git config --local remote.origin.url
07:52:55.809326 run-command.c:638       trace: run_command: C:/_git/ForTests2/src/.git/hooks/post-command.exe config --local remote.origin.url --git-pid=16732 --exit_code=0

This is run by GitProcess.GetOriginUrl().

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The output is interpreted here in Enlistment.cs and would fail if we didn't redirect GIT_TRACE=1 (the output would not be a URL) or GIT_TRACE=2 (originResult.HasErrors would be true).

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.

5 participants