]> git.nbdom.net Git - nb.git/commitdiff
gitf_pulish
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 4 May 2023 20:21:38 +0000 (22:21 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Thu, 4 May 2023 20:21:38 +0000 (22:21 +0200)
etc/profile.d/git.sh

index ece725d5b16b9fdca6e739f221825c9b36caa770..db6de9d6ebdc7a5639ce10e039693a238dfa5546 100644 (file)
@@ -7,6 +7,7 @@ which git > /dev/null || return 0
 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"
+alias git_root="git rev-parse --show-toplevel"
 
 gitf() {
        case "$@" in
@@ -32,13 +33,17 @@ EOF
 
        [ "$#" == "0" ] && echo "Args CMD missing" 2>&1 && return 1
 
-       declare cmd="cd "$(dirname "$file")" && $*"
-       cmd="whoami && pwd && $cmd"
+       declare pwd="$(pwd)"
+
+       declare cmd="cd \"$(dirname "$file")\" && cd \"\$(git_root)\" && $*"
+       cmd="$cmd && echo && echo user=\$(whoami) root=\$(pwd)"
        if [ "$owner" != "$(id -un)" ]; then
                su - "$owner" -c "$cmd"
        else
                eval "$cmd"
        fi
+
+       cd "$pwd"
 }
 
 gitf_publish() {
@@ -52,31 +57,32 @@ EOF
                ;;
        esac
 
-       declare file="${1:?Args 1: file is missing}"
        #exec echo $file
        if [ "$1" != "_gitf" ]
        then
-               gitf "$file" gitf_publish _gitf "$(realpath "$file")"
+               gitf "$1" gitf_publish _gitf "$(realpath "$1")"
                return
        fi
        shift
+       declare file="${1:?Args 1: file is missing}"
 
        #
        # Commit
        #
        declare comment
+       declare default="${file##$(git_root)/}"
        if [ -n "$(git status --porcelain "$file")" ]
        then
-               read -p "Your comment (default: $file): " comment
-               [ -z "$comment" ] && comment="$file"
-               echo git commit -m "$comment" "$file"
+               read -p "Your comment (default: $default): " comment
+               [ -z "$comment" ] && comment="$default"
+               git commit -m "$comment" "$file"
        fi
 
 
        #
        # Push
        #
-       echo git push
+       git push
 
        #
        # Merging
@@ -84,8 +90,8 @@ EOF
        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;;
+                       master) git branch | grep ' testing$' && git_merge_to testing;;
+                       testing) git_merge_to master;;
                esac
        else
                echo "Only one branch no merging"