lazygit icon indicating copy to clipboard operation
lazygit copied to clipboard

Lazygit hangs on any custom command

Open wojciech-kulik opened this issue 1 year ago • 7 comments

Describe the bug When I call any custom command using : it is stuck on "Press enter to return to lazygit" when I call it from Neovim. However, when I call it directly from the Terminal (kitty) like:

/some/repo
> lazygit

+ /bin/zsh -i -c git fetch origin develop

From github.com:some/repo
 * branch                develop    -> FETCH_HEAD
[1]  + 50708 suspended (tty output)  lazygit

> …/some/repo ✖ TTOU 7s
> fg                                                                                                                                                                                                                                                                                
[1]  + 50708 continued  lazygit

it's stuck, lazygit doesn't appear. I can't do anything, I have to kill the terminal.

Environment

> lazygit --version                                                                                                                                                                                                                                                                 
commit=, build date=, build source=nix, version=0.44.1, os=darwin, arch=arm64, git version=2.46.0
> git --version                                                                                                                                                                                                                                                                    
git version 2.46.0

Additional context

I'm using Nix and I noticed that lazygit calls wrong zsh instance. It should use the first one:

> where zsh                                        
/etc/profiles/per-user/me/zsh
/run/current-system/sw/bin/zsh
/bin/zsh

but it uses the last one. I'm not sure if it matters.

wojciech-kulik avatar Sep 24 '24 09:09 wojciech-kulik

This is a duplicate of #3903 (and #3923).

I'm using Nix and I noticed that lazygit calls wrong zsh instance. It should use the first one: but it uses the last one. I'm not sure if it matters.

It probably doesn't matter for this issue, but just to explain this one: lazygit uses whatever your $SHELL environment variable is set to (and it seems to be /bin/zsh). It doesn't look for zsh in your PATH.

stefanhaller avatar Sep 24 '24 10:09 stefanhaller

Thank you for details! I'm waiting for the fix then 🤞

wojciech-kulik avatar Sep 24 '24 10:09 wojciech-kulik

Apologies if this is the same issue, but I'm running into almost exactly the same issue except my terminal (wezterm) is not freezing. Lazygit is simply being killed after running a custom command, and I have to reopen it.

+ /bin/zsh -i -c git pull

Already up to date.

Press enter to return to lazygit[3]  + 13839 suspended (tty input)  lazygit
~/Documents/myRepo $

mayorbyrne avatar Sep 24 '24 15:09 mayorbyrne

Apologies if this is the same issue, but I'm running into almost exactly the same issue except my terminal (wezterm) is not freezing. Lazygit is simply being killed after running a custom command, and I have to reopen it.

It gets suspended, not killed, you can bring it up with fg.

But yes, same issue.

mark2185 avatar Sep 24 '24 15:09 mark2185

Based on your logs it’s suspended. What happens if you run fg after that? In my case it’s not going back to lazygit but it’s freezed

wojciech-kulik avatar Sep 24 '24 15:09 wojciech-kulik

ah, yes. Confirmed that running fg afterwards results in [1] + 4381 continued lazygit with a hanging blinking cursor.

that said, if I run exit then, it does go back to lazygit

piggybacking on what @softkot said

downdrade to v0.43.1 solve the problem

I've also downgraded to 0.43.1 to solve the issue.

mayorbyrne avatar Sep 25 '24 15:09 mayorbyrne

Has the same issue starting from v0.44.0 downdrade to v0.43.1 solve the problem

softkot avatar Oct 17 '24 13:10 softkot

I had something similar using Conventional Commits guide bound to Ctrl-C it worked but then ended up in a freezing loop where eventually the mouse wouldn't even move.

I realized it was because there was a conflict between my "smooth" keybind and other apps or systems. Ctrl-C in linux is used to completely halt an operation. Kinda dumb - didn't think it would matter.

I saw the OP saying they use : which is a VERY VERY common and frequently used keybind in vim, and neovim by extension, so probably not the one you want to use.

I changed my binding and the problem went away. Figures that when lazygit is fighting to do something while some other system is trying to do something there ought to be conflicts.

hglbrg-sli avatar Oct 21 '24 09:10 hglbrg-sli

@hglbrg-sli the same issue occurs when lazygit is called directly from the terminal (not from Neovim)

wojciech-kulik avatar Oct 21 '24 09:10 wojciech-kulik

I'm having the same problem when running shell commands. Keeps hanging in Press enter to continue and doesn't leave, I have to kill lazygit to be able to leave the screen.

osdva avatar Nov 07 '24 14:11 osdva

After querying GTP, I got the exit solution. I've tried multiple commands and it works well. CleanShot 2024-11-13 at 16 09 09@2x

Can you guys try it out?

run <your command>; exit in lazygit instead.

yam-liu avatar Nov 13 '24 08:11 yam-liu

Hmm I just noticed this seems to work on the latest commit using the following custom command (log --graph --abbrev-commit --decorate --format=format:'%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)' --all)

https://github.com/mikavilpas/dotfiles/blob/8e457695f42dac7e7ba5772b58ee3cf4ec209483/.config/lazygit/config.yml?plain=1#L8-L12

Maybe it has been fixed? Can anyone reproduce the issue on e1e4e1be1fb6?

mikavilpas avatar Nov 13 '24 10:11 mikavilpas

@mikavilpas I believe these are different cases. The case we’re discussing is actually about ‘shell commands,’ not ‘custom commands.’

To be precise, custom commands are those configured in config.yml, while shell commands are entered directly in the input field that appears after typing :. The author has mixed up these concepts.

For custom commands, we don’t use the -i option, so they work as expected.

yam-liu avatar Nov 14 '24 13:11 yam-liu

I see. I just tried it out and it seems echo $USER and echo $USER && read work, but git fetch --prune does not.

mikavilpas avatar Nov 14 '24 14:11 mikavilpas

I have been using this method for days. And it works fine for me. I'm not sure if it's the correct way to fix it, but it works.

diff --git forkSrcPrefix/pkg/commands/oscommands/cmd_obj_builder.go forkDstPrefix/pkg/commands/oscommands/cmd_obj_builder.go
index 3e89ce1029354e8c813801a53c3765c9abefba46..97075768584f0d58644c610f0b1eb280303eef46 100644
--- forkSrcPrefix/pkg/commands/oscommands/cmd_obj_builder.go
+++ forkDstPrefix/pkg/commands/oscommands/cmd_obj_builder.go
@@ -52,6 +52,7 @@ func (self *CmdObjBuilder) NewShell(commandStr string) ICmdObj {
 }
 
 func (self *CmdObjBuilder) NewInteractiveShell(commandStr string) ICmdObj {
+	commandStr += "; exit"
 	quotedCommand := self.quotedCommandString(commandStr)
 	cmdArgs := str.ToArgv(fmt.Sprintf("%s %s %s %s", self.platform.InteractiveShell, self.platform.InteractiveShellArg, self.platform.ShellArg, quotedCommand))
 

CleanShot 2024-11-21 at 22 48 16@2x

yam-liu avatar Nov 21 '24 15:11 yam-liu

run <your command>; exit in lazygit instead.

@yam-liu is awesome! Your workaround mitigated this months-long issue!

@jesseduffield , please consider ship Yam's solution soon.

rayluo avatar Dec 23 '24 02:12 rayluo

@jesseduffield , please consider ship Yam's solution soon.

Here's a PR: #4126. Could those affected by the problem please test it? Thanks!

stefanhaller avatar Dec 24 '24 15:12 stefanhaller

Fixed in #4126.

stefanhaller avatar Dec 28 '24 13:12 stefanhaller