Git clone writable: Difference between revisions

From SlackWiki
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 1: Line 1:
[[Category:Tips]]
[[Category:Tips]]
<pre>
<pre>
# bash function: set git clones user-writable (annoyingly if you clone some files are non-user-writable... 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 "$@"
     # Might work.
   if [ $1 = 'clone' ]; then
     #sudo find . -iname .git* -perm u-w -exec chmod u+w {} \+;
     d="$@"; d=${d##*/}; d=${d%.git}; d=${d##* }
     command git "$@" && chmod -R u+w */.git*;
     #read -p "dir: $d"
    # You may prefer.
     if [ -d "$d" ]; then
    #command git "$@" && rm -fR */.git*;
      chmod -R u+w $d/.git*
    # Uncomment section to SlackBuilds.org version naming convention compress.
      # Maybe faster than previous line.
    #d='$@'
      #find $d -iname .git* -perm u-w -exec chmod u+w {} \+
    #d=${d##*/}
      cd $d
    #d=${d%.git}
      VERSION=$(git log --pretty=format:'%cd_%h' --date=format:'%Y%m%d' | head -n 1)
    #cd $d
      # Maybe faster than above chmod/find.
    #VERSION=$(git log --pretty=format:'%cd_%h' --date=format:'%Y%m%d' | head -n 1)
      #rm -fR .git*
    #cd ..
      cd ..
    #tar --exclude-vcs -cJvf $d-$VERSION.tar.xz $d
      tar --exclude-vcs -cJvf $d-$VERSION.tar.xz $d
  else
    else echo "save/download error"
     command git "$@";
     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;
}