stagit-scripts

Static git repository setup scripts
git clone https://www.brianlane.com/git/stagit-scripts
Log | Files | Refs | README

setup-stagit-remote (1136B)


      1 #!/usr/local/bin/bash
      2 reposdir="$HOME/stagit-repos"
      3 post_receive="$HOME/stagit-files/post-receive"
      4 
      5 if [ ! -e "${post_receive}" ]; then
      6     echo "${post_receive} script is missing"
      7     exit 1
      8 fi
      9 
     10 name="$(basename "$PWD")"
     11 if [ -e "${reposdir}/${name}" ]; then
     12     echo "Project ${name} already setup"
     13     exit 1
     14 fi
     15 if git remote|grep -q stagit; then
     16     echo "stagit remote already setup"
     17     exit 1
     18 fi
     19 
     20 read -p "Enter a description of the ${name} project: " description
     21 if [ -z "${description}" ]; then
     22     echo "Please enter a description"
     23     exit 1
     24 fi
     25 
     26 # Try to figure out the name of the main/master branch
     27 BRANCH="master"
     28 for b in $(git branch -r); do
     29     case $b in
     30         origin/main)
     31             BRANCH="main"
     32             break
     33             ;;
     34         *)
     35             ;;
     36     esac
     37 done
     38 echo "Using '${BRANCH}' as the name of main branch"
     39 
     40 # Create the bare repo
     41 pushd "${reposdir}" || exit 1
     42 git init "${name}" -b "${BRANCH}" --bare
     43 echo "${description}" > "${name}/description"
     44 popd || exit 1
     45 
     46 cp "${post_receive}" "${reposdir}/${name}/hooks"
     47 git remote add stagit "${reposdir}/${name}"
     48 
     49 echo "${name} setup for stagit updates"