Pavel
Pavel

Reputation: 2193

oh-my-zsh: git maximum nested function level reached

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

Upvotes: 14

Views: 23531

Answers (5)

4015.alt
4015.alt

Reputation: 75

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

Upvotes: 2

user9869932
user9869932

Reputation: 7337

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 $*
  ...
}

Upvotes: 1

Saman Mohamadi
Saman Mohamadi

Reputation: 4662

closing the terminal and reopening it, worked for me.

Upvotes: 1

bluenote10
bluenote10

Reputation: 26550

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

Upvotes: 7

Pavel
Pavel

Reputation: 2193

My mistake, I moved bash function to zsh:

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

Solution:

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

Upvotes: 16

Related Questions