oh-my-zsh: git maximum nested function level reached
Asked Answered
W

5

12

Get an error when I use standard git command:

[~/site]$ git branch
git:1: maximum nested function level reached

.zshrc:

plugins=(git osx colored-man gem brew go bundler rake rails)
source $ZSH/oh-my-zsh.sh
Washable answered 15/3, 2017 at 23:29 Comment(0)
W
16

My mistake, I moved bash function to zsh:

gr() {
  git rebase -i HEAD~$1
}

Solution:

function gr() {
  git rebase -i HEAD~$1
}
Washable answered 15/3, 2017 at 23:42 Comment(1)
per chance are you holding FunCoin? Its literally all I have.Imbalance
A
6

I had the same error with a different command (export), caused by an accidental recursive function definition. I could solve the problem by removing the unwanted function:

unset -f export
Agglutinin answered 19/9, 2017 at 8:6 Comment(0)
U
1

I had the same issue, with a different command: find

TL;DR

Don't invoke aliases to a function inside the function script.


The error

$ find ~ -name some_thing
find_no_err:1: maximum nested function level reached; increase FUNCNEST?

The issue

  • I have created a function f (find_no_err), that use a command c (find)
  • then, defined an alias that associate the command to the function, as follow
alias c=f
  • so I ended up with a recursion without a stop condition :
# the recursion issue
c=f(c)

the solution

Avoid invoking aliases to functions or commands that call a given function inside its script

or, in the case of c=f(c), don't call c form f

Instead, use one of this 3 options:

  • use a relative path to the command (eg cmd)
  ./cmd
  • use the full path to the command
  # to get it, in linux systems, use
  whereis cmd
  • quote the command invocation inside the function script
  'cmd'

in practice

I just quoted find invocation, inside the function body

find_no_err(){
  'find' $* 2>/dev/null
}

then sourced the file (cf. zsh doc for "source file", cf. POSIX spec for "dot description")

what this has to do with the original question ?

  1. the issues seem similars: a git call invokes a git alias/function that invokes its invoker ...

  2. omz's git plugging , add a long list of git alias, among which there is

alias gr='git remote' # line 246

which may had some conflict with the OP custom function, after git branch call (but I don't see how)

  1. In my case, the accepted solution doesn't work

adding the optional (cf. zsh doc) function identifier, doesn't prevent the alias invocation within the function body (by default). that leads to the recursion issue, which throws "maximum nested function level reached;" error

  1. it is possible* to share custom functions between bash and zsh, by putting them in a separate dotfile, then sourcing it from there respective rc files

Alternatively

You can unset or remove the changes, as mentioned in bluenote10 answer

Upbraiding answered 13/12, 2021 at 15:20 Comment(0)
T
1

closing the terminal and reopening it, worked for me.

Torrietorrin answered 21/11, 2022 at 9:1 Comment(0)
K
1

You can add command to stop the recursion.

In my case I had this in my .zshrc:

docker() {
  docker $*      # <-- recursive
  if [[ ..
  ...
}

worked just fine after changing the docker call to:

docker() {
  command docker $*
  ...
}
Kerry answered 24/3, 2023 at 17:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.