Question

Folder inside www deleted on git push

Posted November 10, 2020 82 views
Git

I created a shell script that takes the folder name as input and creates a repo on my server while also creating a subfolder inside “www/codepixelz/” which is linked to my subfolder codepixelz.tech
So if someone provides folder name as “xyz”
It would create a repo called xyz.git and also a subfolder called “www/codepixelz/xyz” and can be accessed by codepixelz.tech/xyz

While this seemed to work first. I am having some issues now.
The folder in www/codepixelz is created. But when I clone the bare repo to local and then add my files and push. It is pushed to git. However, the folder under “www/codepixelz” is deleted. and I can no longer access codepixelz.tech/xyz
What could be the issue?

The code to create repo is as below:

if [ "$#" -eq 1 ]; then

  if [ -d "$1.git" ]; then
      # Control will enter here if $DIRECTORY exists.
    echo "Repository $1.git already exists"
    exit 0

  fi

    echo "*Setting up repo and web root folder for product $1"
    if [ -d "/var/www/codepixelz/$1" ]; then
            echo "Project already exists /product/$1"
            exit 0
    fi

    echo "Creating git repo $1.git ..."

    mkdir $1.git
    mkdir /var/www/codepixelz/$1
        chown dev:dev -R /var/www/codepixelz/$1
    chmod 775 -R /var/www/codepixelz/$1

    cd $1.git

    git init --bare
    git --bare update-server-info
    git config core.bare false
    git config receive.denycurrentbranch ignore
    git config core.worktree /var/www/codepixelz/$1

    echo "#!/bin/sh" |  tee hooks/post-receive
    echo "git checkout -f" |  tee -a hooks/post-receive
    echo "rm -rf /var/www/codepixelz/$1" | tee -a hooks/post-receive
    chmod +x hooks/post-receive


    echo "Created git repo  $1.git"
    echo "Clone: git clone ssh://dev@codepixelz.tech/home/dev/git/$1.git"
    echo "Add into existing git repo:  git remote add origin ssh://dev@codepixelz.tech/home/dev/git/$1.git"
    echo "/home/dev/git/$1.git created on " >> gitLog $(date)
elif [ $project_dir -eq 2 ] ; then
    if [ -d "/var/www/codepixelz/$1" ]; then
            echo "Project already exists./codepixelz/$1"
            exit 0
    fi

    echo "Creating git repo $1.git ..."

    mkdir $1.git
    mkdir /var/www/codepixelz/$1
    chmod 775 -R /var/www/codepixelz/$1

    cd $1.git

    git init --bare
    git --bare update-server-info
    git config core.bare false
    git config receive.denycurrentbranch ignore
    git config core.worktree /var/www/codepixelz/$1

    echo "#!/bin/sh" |  tee hooks/post-receive
    echo "git checkout -f" |  tee -a hooks/post-receive
    chmod +x hooks/post-receive


    echo "Created git repo  $1.git"
    echo "Clone: git clone ssh://dev@codepixelz.tech/home/dev/git/$1.git"
    echo "Add into existing git repo:  git remote add origin ssh://dev@codepixelz.tech/home/dev/git/$1.git"
    echo "/home/dev/git/$1.git created on " >> gitLog $(date)
else
  echo "Enter project name to create."
fi

The error that I get is:

fatal: sha1 file ’<stdout>’ write error: Broken pipe KiB/s
error: remote unpack failed: unable to create temporary object directory
error: failed to push some refs to ‘ssh://dev@codepixelz.tech/home/dev/git/xyz.git’

Any lead would be of great help.

Thanks.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

×
1 answer

Hi @utsavrathour,

Can you let me know with how much arguments are you running the script, I can see that this depends?

Additionally, I can’t see anything worrying at the moment. What I’ll recommend is opening the script and start executing the commands one by one. That way you’ll be able to see where exactly the behaviour expected is different.

  • There’s only one parameter. The name of the project.

    Apart from that. It runs well and creates subfolfer. But pushing to it later on the first push is what deletes the folder.

Submit an Answer