gitextensions / gitextensions

Git Extensions is a standalone UI tool for managing git repositories. It also integrates with Windows Explorer and Microsoft Visual Studio (2015/2017/2019).
https://gitextensions.github.io/
Other
7.76k stars 2.08k forks source link

Git Flow plugin crashes on first use #10334

Closed mbikovitsky closed 1 year ago

mbikovitsky commented 1 year ago

Environment

Issue description

Exit code: 1 Command: C:\Program Files\Git\bin\git.exe Arguments: config --get gitflow.branch.master Working directory: [REDACTED]

GitExtUtils.ExternalOperationException
 ---> System.Exception
   --- End of inner exception stack trace ---
   at GitCommands.ExecutableExtensions.GetOutputAsync(IExecutable executable, ArgumentString arguments, Byte[] input, Encoding outputEncoding, CommandCache cache, Boolean stripAnsiEscapeCodes)
   at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
   at Microsoft.VisualStudio.Threading.JoinableTask`1.CompleteOnCurrentThread()
   at Microsoft.VisualStudio.Threading.JoinableTaskFactory.Run[T](Func`1 asyncMethod, JoinableTaskCreationOptions creationOptions)
   at Microsoft.VisualStudio.Threading.JoinableTaskFactory.Run[T](Func`1 asyncMethod)
   at GitCommands.ExecutableExtensions.GetOutput(IExecutable executable, ArgumentString arguments, Byte[] input, Encoding outputEncoding, CommandCache cache, Boolean stripAnsiEscapeCodes)
   at GitExtensions.Plugins.GitFlow.GitFlowForm.get_IsGitFlowInitialised()
   at GitExtensions.Plugins.GitFlow.GitFlowForm.Init()
   at GitExtensions.Plugins.GitFlow.GitFlowForm..ctor(GitUIEventArgs gitUiCommands)
   at GitExtensions.Plugins.GitFlow.GitFlowPlugin.Execute(GitUIEventArgs args)
   at GitUI.CommandsDialogs.FormBrowse.<>c__DisplayClass70_0.<RegisterPlugins>b__2(Object <p0>, EventArgs <p1>)
   at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e)
   at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e)
   at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ToolStrip.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam)

Steps to reproduce

Open the Git Flow plugin inside a repository that doesn't have Git Flow initialized.

Did this work in previous version of GitExtensions?

v3.5.4

Diagnostics

The issue is that git config --get gitflow.branch.master exits with status 1 because the setting isn't set. Running git flow init -d manually beforehand solves the issue.

vbjay commented 1 year ago

Related to 25060c3b0683c710cd5b47cdfc550b7f8a3b4940

See work done in relation to https://github.com/gitextensions/gitextensions/issues/10242. Need to tighten git config fetching to handle values not existing.

gerhardol commented 1 year ago

9056

Exit code is OK here.

        private bool IsGitFlowInitialised
        {
            get
            {
                GitArgumentBuilder args = new("config")
                {
                    "--get",
                    "gitflow.branch.master"
                };
                ExecutionResult exec = _gitUiCommands.GitModule.GitExecutable.Execute(args, throwOnErrorExit: false);
                return exec.ExitedSuccessfully && !string.IsNullOrWhiteSpace(exec.StandardOutput);
            }
        }

What is the usage of the GitFlow plugin if this has not been seen until now? This plugin should probably be removed from GE core and be maintained by users.

vbjay commented 1 year ago

Disagree. Just because you changed git executable handling of output and didn't verify plugin handling doesn't mean you should abandon a very useful plugin.

Git flow plugin supports git flow. https://danielkummer.github.io/git-flow-cheatsheet/

vbjay commented 1 year ago

Actually the better fix is to use the module's git config functionality to retrieve the setting. @mbikovitsky did you want to attempt that change?

gerhardol commented 1 year ago

Short term change is to apply the change I posted. Longer term there is no maintainer working with this plugin, so it cannot be well maintained within GE and may benefit from a separate release cycle.

vbjay commented 1 year ago

@mbikovitsky one thing that would help. Press f12 before launching gitflow dialog. Capture log output. Any error message?

mbikovitsky commented 1 year ago

@vbjay, here you go:

Log output ```plain File name: C:\Program Files\Git\bin\git.exe Arguments: config --get gitflow.branch.master Working dir: [REDACTED] Process ID: 19080 Started at: 2022-11-05T18:43:00.5811365+02:00 UI Thread?: True Duration: 30.581 ms Exit code: GitExtUtils.ExternalOperationException ---> System.Exception --- End of inner exception stack trace --- at GitCommands.ExecutableExtensions.GetOutputAsync(IExecutable executable, ArgumentString arguments, Byte[] input, Encoding outputEncoding, CommandCache cache, Boolean stripAnsiEscapeCodes) at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread() at Microsoft.VisualStudio.Threading.JoinableTask`1.CompleteOnCurrentThread() at Microsoft.VisualStudio.Threading.JoinableTaskFactory.Run[T](Func`1 asyncMethod, JoinableTaskCreationOptions creationOptions) at Microsoft.VisualStudio.Threading.JoinableTaskFactory.Run[T](Func`1 asyncMethod) at GitCommands.ExecutableExtensions.GetOutput(IExecutable executable, ArgumentString arguments, Byte[] input, Encoding outputEncoding, CommandCache cache, Boolean stripAnsiEscapeCodes) at GitExtensions.Plugins.GitFlow.GitFlowForm.get_IsGitFlowInitialised() at GitExtensions.Plugins.GitFlow.GitFlowForm.Init() at GitExtensions.Plugins.GitFlow.GitFlowForm..ctor(GitUIEventArgs gitUiCommands) at GitExtensions.Plugins.GitFlow.GitFlowPlugin.Execute(GitUIEventArgs args) at GitUI.CommandsDialogs.FormBrowse.<>c__DisplayClass70_0.b__2(Object , EventArgs ) at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam) Call stack: at GitCommands.Logging.CommandLog.LogProcessStart(String fileName, String arguments, String workDir) at GitCommands.Executable.ProcessWrapper..ctor(String fileName, String prefixArguments, String arguments, String workDir, Boolean createWindow, Boolean redirectInput, Boolean redirectOutput, Encoding outputEncoding, Boolean useShellExecute, Boolean throwOnErrorExit) at GitCommands.Executable.Start(ArgumentString arguments, Boolean createWindow, Boolean redirectInput, Boolean redirectOutput, Encoding outputEncoding, Boolean useShellExecute, Boolean throwOnErrorExit) at GitCommands.ExecutableExtensions.GetOutputAsync(IExecutable executable, ArgumentString arguments, Byte[] input, Encoding outputEncoding, CommandCache cache, Boolean stripAnsiEscapeCodes) at System.Runtime.CompilerServices.AsyncMethodBuilderCore.Start[TStateMachine](TStateMachine& stateMachine) at GitCommands.ExecutableExtensions.GetOutputAsync(IExecutable executable, ArgumentString arguments, Byte[] input, Encoding outputEncoding, CommandCache cache, Boolean stripAnsiEscapeCodes) at GitCommands.ExecutableExtensions.<>c__DisplayClass2_0.b__0() at Microsoft.VisualStudio.Threading.JoinableTaskFactory.ExecuteJob[T](Func`1 asyncMethod, JoinableTask job) at Microsoft.VisualStudio.Threading.JoinableTaskFactory.RunAsync[T](Func`1 asyncMethod, Boolean synchronouslyBlocking, JoinableTaskCreationOptions creationOptions) at Microsoft.VisualStudio.Threading.JoinableTaskFactory.Run[T](Func`1 asyncMethod, JoinableTaskCreationOptions creationOptions) at Microsoft.VisualStudio.Threading.JoinableTaskFactory.Run[T](Func`1 asyncMethod) at GitCommands.ExecutableExtensions.GetOutput(IExecutable executable, ArgumentString arguments, Byte[] input, Encoding outputEncoding, CommandCache cache, Boolean stripAnsiEscapeCodes) at GitExtensions.Plugins.GitFlow.GitFlowForm.get_IsGitFlowInitialised() at GitExtensions.Plugins.GitFlow.GitFlowForm.Init() at GitExtensions.Plugins.GitFlow.GitFlowForm..ctor(GitUIEventArgs gitUiCommands) at GitExtensions.Plugins.GitFlow.GitFlowPlugin.Execute(GitUIEventArgs args) at GitUI.CommandsDialogs.FormBrowse.<>c__DisplayClass70_0.b__2(Object , EventArgs ) at System.Windows.Forms.ToolStripMenuItem.OnClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleClick(EventArgs e) at System.Windows.Forms.ToolStripItem.HandleMouseUp(MouseEventArgs e) at System.Windows.Forms.ToolStrip.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.ToolStripDropDown.OnMouseUp(MouseEventArgs mea) at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.ToolStrip.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, WM msg, IntPtr wparam, IntPtr lparam) at Interop.User32.DispatchMessageW(MSG& msg) at Interop.User32.DispatchMessageW(MSG& msg) at System.Windows.Forms.Application.ComponentManager.Interop.Mso.IMsoComponentManager.FPushMessageLoop(UIntPtr dwComponentID, msoloop uReason, Void* pvLoopData) at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(msoloop reason, ApplicationContext context) at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(msoloop reason, ApplicationContext context) at System.Windows.Forms.Application.Run(Form mainForm) at GitUI.GitUICommands.StartBrowseDialog(IWin32Window owner, BrowseArguments args) at GitUI.GitUICommands.RunBrowseCommand(IReadOnlyList`1 args) at GitUI.GitUICommands.RunCommandBasedOnArgument(IReadOnlyList`1 args, IReadOnlyDictionary`2 arguments) at GitUI.GitUICommands.RunCommand(IReadOnlyList`1 args) at GitExtensions.Program.RunApplication() at GitExtensions.Program.Main() ```

But I'll leave the fix to someone else :) I don't have enough free time on my hands at this moment.

vbjay commented 1 year ago

Ok. @gerhardol I see what you changed. That would work too. Did you want to put it in?

gerhardol commented 1 year ago

Ok. @gerhardol I see what you changed. That would work too. Did you want to put it in?

Anyone is welcome to create a PR with that. (I try to look at issues between other things to do and plan to submit PRs after that.)

pmiossec commented 1 year ago

Until a fix is released, maybe initializing GitFlow manually is the solution by running the command git flow init -d (for default branch naming convention) or git flow init (but I'm not sure the plugin support another branch name than master...)

vbjay commented 1 year ago

No. When the config is in it reads the branch name from config. It's just yelling because of the exit code. It should accept that and not throw on that exit code.

pmiossec commented 1 year ago

When the config is in it reads the branch name from config.

For me masteris hardcoded: https://github.com/gitextensions/gitextensions/blob/master/Plugins/GitFlow/GitFlowForm.cs#L50 If I'm not wrong, there is no git config that store the name of the main branch of the repository. I will be really pleased if someone prove me wrong...

mbikovitsky commented 1 year ago

@pmiossec, gitflow.branch.master is the name of the config option that stores the name of the main branch. For example, in my .git\config file:

[gitflow "branch"]
    master = main
    develop = develop
vbjay commented 1 year ago

Yep. That is basically what is the name of the branch release and hotfix branches go to when completed. @pmiossec might want to read https://nvie.com/posts/a-successful-git-branching-model/

pmiossec commented 1 year ago

Yep. That is basically what is the name of the branch release and hotfix branches go to when completed. @pmiossec might want to read https://nvie.com/posts/a-successful-git-branching-model/

Yes, Yes, I know a little how it works. That's the link I put in the plugin UI as a documentation when I developed the plugin 😜

That's just I didn't remember the config key name and this name was especially misleading since Git introduced support for another name for default branch...

But still, the initialization of git flow with the default values as it is done today will not support another default branch than master...

vbjay commented 1 year ago

So git flow init won't read from what git understands is the main/master/trunk ..whatever we call the default branch?

pmiossec commented 1 year ago

So git flow init won't read from what git understands is the main/master/trunk ..whatever we call the default branch?

It's a good question. I don't know if git flow try to do something clever I don't know how but I don't think so. It's something that needs to be tested...

vbjay commented 1 year ago

Just did. I renamed my branch master which is not defaukt branch name in my config.
image

it still was smart enough and once I ran the init, plugin behaves well.

vbjay commented 1 year ago

image

So it actually looks at current branches to determine suggestions

image

has to exist too

pmiossec commented 1 year ago

I did some quick test also and when running git flow init -d (what is run by the plugin), there is a special handling for master(normal because it is the historic default) and main. I tried other names trunk or another random one but with only 1 branch in the repository and the command failed.

So as long as master or main are used, it should be ok...

vbjay commented 1 year ago

image Confirmed and init.defaultbranch does not play a part

image