Git clone writable: Difference between revisions

From SlackWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
(11 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[Category:Tips]]
[[Category:Tips]]
<pre>
<pre>
#Bash function to make git clones writable (annoyingly, if you clone repository, some files are non-user-writable... which after compiling dangerously tempts 'sudo rm -rf!')
# Annoyingly some 'git clone' files aren't user-writable: dangerously tempts 'sudo rm -rf'!. Bash function.
# Writable git clone
git()
git()
{
{
   if [ $1 = "clone" ]; then
  command git "$@"
     command git "$@" && find */.git -type f -perm ! -u=w -exec chmod u+w {} \;
   if [ $1 = 'clone' ]; then
  else
     d="$@"; d=${d##*/}; d=${d%.git}; d=${d##* }
     command git "$@";
    #read -p "dir: $d"
    if [ -d "$d" ]; then
      chmod -R u+w $d/.git*
      # Maybe faster than previous line.
      #find $d -iname .git* -perm u-w -exec chmod u+w {} \+
      cd $d
      VERSION=$(git log --pretty=format:'%cd_%h' --date=format:'%Y%m%d' | head -n 1)
      # Maybe faster than above chmod/find.
      #rm -fR .git*
      cd ..
      tar --exclude-vcs -cJvf $d-$VERSION.tar.xz $d
     else echo "save/download error"
    fi
   fi;
   fi;
}
}
</pre>
</pre>

Latest revision as of 11:29, 28 August 2022

# Annoyingly some 'git clone' files aren't user-writable: dangerously tempts 'sudo rm -rf'!. Bash function.
# Writable git clone
git()
{
  command git "$@"
  if [ $1 = 'clone' ]; then
    d="$@"; d=${d##*/}; d=${d%.git}; d=${d##* }
    #read -p "dir: $d"
    if [ -d "$d" ]; then
      chmod -R u+w $d/.git*
      # Maybe faster than previous line.
      #find $d -iname .git* -perm u-w -exec chmod u+w {} \+
      cd $d
      VERSION=$(git log --pretty=format:'%cd_%h' --date=format:'%Y%m%d' | head -n 1)
      # Maybe faster than above chmod/find.
      #rm -fR .git*
      cd ..
      tar --exclude-vcs -cJvf $d-$VERSION.tar.xz $d
    else echo "save/download error"
    fi
  fi;
}