getting “fatal: not a git repository: '.'” when using post-update hook to execute 'git pull' on another repo

前端 未结 5 552
梦谈多话
梦谈多话 2020-11-30 20:17

I\'m new to git so I apologize (and please correct me) if I misuse terminology here, but I\'ll do my best.

I\'m trying to set up a bare git repo (hub) and a developm

相关标签:
5条回答
  • 2020-11-30 20:35

    You probably have a permissions issue. I'm not sure how you have setup your bare git repo, but if it's running under the git user, make sure that git user is allowed to perform the git pull in your project directory.

    Optionally try this to find out what user you are when the hook is run:

    echo `whoami`
    
    0 讨论(0)
  • 2020-11-30 20:41

    Try instead:

    #!/bin/sh
    cd /path/to/working-copy/
    env -i git pull
    
    0 讨论(0)
  • 2020-11-30 20:48

    Despite that unset GIT_DIR just works.

    the problem occurs when you set GIT_DIR wrongly somewhere else.

    you can just add that instead: GIT_DIR=.git/ It will work

    0 讨论(0)
  • 2020-11-30 20:53

    In my case I had specified a working tree, and this breaks on some commands, like pull (or more precisely fetch).

    To unset the working tree if it is in your git config is via:

    git config --unset core.worktree
    

    (There are other ways to set a work tree)

    Important to note,

    There is next to no change of this being your problem unless you yourself dug this hole around you by using a custom worktree in the first place.

    Banter:

    This implies to me that git internals use paths relative to the worktree + .git/ in some cases. In my experience worktrees are not well supported whatsoever, except by the most fundamental parts of git. I have not experimented thoroughly, Git would probably behave if I set whatever the git directory config variable is properly, which I have not played with.

    0 讨论(0)
  • 2020-11-30 20:57

    Here is the script that ultimately worked. I think the bit I was originally missing that prevented it from working remotely was the unset GIT_DIR

    #!/bin/sh
    cd /path/to/working-copy/ || exit
    unset GIT_DIR
    git pull repo branch
    
    exec git-update-server-info
    
    0 讨论(0)
提交回复
热议问题