0

Neither functions seem to affect anything for me? Is anyone able to get them working and show me what I'm doing wrong?

I'm trying to override git pull to include recursive submodules whilst keeping other git commands work

#https://superuser.com/a/479816
function git() {
  case $* in
    -pull* ) shift 1; command git pull --recurse-submodules "$@" ;;
    * ) command git "$@" ;;
  esac
}

function ls() { case $* in -la* ) shift 1; command ls -la "$@" | more ;; * ) command ls "$@" ;; esac }

Destroy666
  • 6,771
P1000
  • 1
  • 1
    Git already has options for that topic. Check fetch.recurseSubmodules, push.recurseSubmodules and submodule.recurse. – Daniel B Dec 02 '23 at 09:05
  • @DanielB git push -recurseSubmodules? – P1000 Dec 02 '23 at 16:40
  • I don’t understand your question, sorry. These options go in any of the Git config files, like repo/.git/config, $HOME/.gitconfig or /etc/gitconfig. – Daniel B Dec 02 '23 at 20:14

1 Answers1

0

Your script doesn't make much sense in the 1st place as it's trying to match git -pull, git -pulled123 and similar statements. I would recommend to read about functionalities you're trying to use, such as case matching with wildcard (*) or what $* means (argument string).

Regardless, not going into that too deep because it's not the way to go. The most proper way to define git aliases is and will be to use git config --global alias.xyz "definition", e.g. here:

git config --global alias.rpull "pull --recurse-submodules"

You can't overwrite the command this way, but you can use a very similar one. And overriding is generally a bad idea as you might want to use regular pull one day and you'll have to get rid of the script at least temporarily. There are definitely cases when you don't want to pull submodules recursively. It's also suboptimal for repos without submodules.

Destroy666
  • 6,771
  • That looks much more like what I was looking for for git config. Thanks! I'll see if I can get it working.

    For trying out more ordinary usages for learning about overwrites https://superuser.com/a/479816

    Any idea why I couldn't get the ls example to work?

    – P1000 Dec 02 '23 at 15:43
  • I explained above - the main reason is that you're matching -pull instead of pull. So nothing happens like you mentioned. The asterisk isn't handled too well either and could match some aliases starting with pull. – Destroy666 Dec 02 '23 at 16:30
  • Is that in the ls example or git? It matching -pull makes sense as a mistake
    function ls() {
      case $* in
        -la* ) shift 1; command ls -la "$@" | more ;;
        * ) command ls "$@" ;;
      esac
    }
    
    – P1000 Dec 02 '23 at 16:33
  • I don't know what's your question. – Destroy666 Dec 02 '23 at 17:07
  • Sorry, couldn't figure out the ls -la overwrite was doing in the example. Think I've figured it out as passing the command into 'more'. Thanks for the help – P1000 Dec 02 '23 at 23:35
  • No problem. If the answer helped, please make sure to mark it with the tick symbol. – Destroy666 Dec 03 '23 at 00:50