]> git.nbdom.net Git - nb.git/commitdiff
gitf_publish
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 3 May 2023 21:51:01 +0000 (23:51 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Wed, 3 May 2023 21:51:01 +0000 (23:51 +0200)
etc/profile.d/git.sh

index f00b5cf3dd9c5589e0876bf41dc3b691437de8d6..d2d62e1e260a1c0719ddbb29db2c35093b0dbd51 100644 (file)
@@ -8,10 +8,19 @@ alias git_grep="git grep --color=auto"
 alias git_ls_tree="git ls-tree --full-tree -r HEAD"
 alias git_ls_files="git ls-files --full-name"
 
-git_commit_push_merge_file_user() {
+gitf() {
+       case "$@" in
+               --help|-h)
+                       cat <<EOF
+Usage: gitf FILE CMD
+Change dir and user to FILE path and run CMD.
+EOF
+                       return
+               ;;
+       esac
+
        declare file="${1:?Args 1: file is missing}"
        shift
-       declare comment="${@:?Args 2: comment is missing}"
 
        if [ ! -f "$file" -o ! -r "$file" ]; then
                echo "Can not find or read file '$file' !" 1>&2
@@ -19,24 +28,52 @@ git_commit_push_merge_file_user() {
        fi
 
        declare owner=$(ls -dl "$file" | awk '{print $3}')
-       [ -n "$owner" ]  || return
+       [ -z "$owner" ] && echo "Can't find owner for file '$file'" 1>&2 && return 1
 
-       declare cmd=""
-       if [ "$owner" != "$(id --user --name)" ]; then
-               true
+       [ "$#" == "0" ] && echo "Args CMD missing" 2>&1 && return 1
+
+       declare cmd="cd "$(dirname "$file")" && $*"
+       cmd="whoami && pwd && $cmd"
+       if [ "$owner" != "$(id -un)" ]; then
+               su - "$owner" -c "$cmd"
+       else
+               eval "$cmd"
        fi
+}
 
-       declare branch="$( cd "$(dirname "$file")" && git branch | awk '/^\*/{print $2}')"
-       cat<<EOF
-cd "$(dirname "$file")" || exit
-. ~/.profile
-git_branch
-echo git_commit_push "$comment" && (\
- [ "\$(git branch | awk '/^\\*/{print \$2}')" = "master" ]\
- || echo git_merge_to master\
- )
+gitf_publish() {
+       case "$@" in
+               --help|-h)
+                       cat <<EOF
+Usage: gitf_publish FILE
+Commit, push and merge if needed (master and testing branches only).
 EOF
+                       return
+               ;;
+       esac
 
+       if [ "$1" != "_gitf" ]
+       then
+               gitf "$1" gitf_publish _gitf
+               return
+       fi
+
+       #
+       # Commit
+       #
+
+       #
+       # Merging
+       #
+       if [ $(git branch | wc -l) -gt 1 ]
+       then
+               case "$(git_branch)" in
+                       master) git branch | grep ' testing$' && echo git_merge_to testing;;
+                       testing) echo git_merge_to master;;
+               esac
+       else
+               echo "Only one branch no merging"
+       fi
 }
 
 git_new_branch() {
@@ -67,48 +104,48 @@ git_cache_rm() {
        echo git filter-branch --index-filter "git rm --cached --ignore-unmatch $@" --force --prune-empty -- --all
 }
 
-gitcd() {
-
-       shell_help_noarg "Change directory to run git commands\nUsage: $FUNCNAME FILE|DIR GIT_ARGUMENTS" "$@" && return 1
-       local i d dir args
-       local pwd; pwd=$PWD
-       #for i in $@; do
-
-       while [ $# -gt 0 ]; do
-
-               i="$1"
-
-               # Replace file with realpath
-               if [ -e "$i" ]; then
-                       i=$(realpath "$i")
-
-                       # if dir stay there
-                       #[ -d "$i" ] && i="$i/.git"
-                       [ -d "$i" ] && i="$i/README.md"
-
-                       d=$(dirname "$i")
-
-                       dir="$d"
-               fi
-
-               shell_push_arg "$i" args
-               shift
-
-       done
-
-       [ -z "$dir" ] && echo "Can't find any file in $@" && return 1
-
-       cd "$dir" || return
-       #echo PWD=$(pwd)
-
-       eval git ${args}
-
-       cd "$pwd"
-
-} # < gitcd()
+# NB 03.05.23 gitcd() {
+# NB 03.05.23 
+       # NB 03.05.23 shell_help_noarg "Change directory to run git commands\nUsage: $FUNCNAME FILE|DIR GIT_ARGUMENTS" "$@" && return 1
+       # NB 03.05.23 local i d dir args
+       # NB 03.05.23 local pwd; pwd=$PWD
+       # NB 03.05.23 #for i in $@; do
+# NB 03.05.23 
+       # NB 03.05.23 while [ $# -gt 0 ]; do
+# NB 03.05.23 
+               # NB 03.05.23 i="$1"
+# NB 03.05.23 
+               # NB 03.05.23 # Replace file with realpath
+               # NB 03.05.23 if [ -e "$i" ]; then
+                       # NB 03.05.23 i=$(realpath "$i")
+# NB 03.05.23 
+                       # NB 03.05.23 # if dir stay there
+                       # NB 03.05.23 #[ -d "$i" ] && i="$i/.git"
+                       # NB 03.05.23 [ -d "$i" ] && i="$i/README.md"
+# NB 03.05.23 
+                       # NB 03.05.23 d=$(dirname "$i")
+# NB 03.05.23 
+                       # NB 03.05.23 dir="$d"
+               # NB 03.05.23 fi
+# NB 03.05.23 
+               # NB 03.05.23 shell_push_arg "$i" args
+               # NB 03.05.23 shift
+# NB 03.05.23 
+       # NB 03.05.23 done
+# NB 03.05.23 
+       # NB 03.05.23 [ -z "$dir" ] && echo "Can't find any file in $@" && return 1
+# NB 03.05.23 
+       # NB 03.05.23 cd "$dir" || return
+       # NB 03.05.23 #echo PWD=$(pwd)
+# NB 03.05.23 
+       # NB 03.05.23 eval git ${args}
+# NB 03.05.23 
+       # NB 03.05.23 cd "$pwd"
+# NB 03.05.23 
+# NB 03.05.23 } # < gitcd()
 
 git_commit_push() {
-       git commit -a -m "$*"; git push
+       git commit -a -m "$*" && git push
 }
 
 git_create() {