]> git.nbdom.net Git - nb.git/commitdiff
TODO git_commit_push_merge_file_user
authorNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 11 Apr 2023 00:45:44 +0000 (02:45 +0200)
committerNicolas Boisselier <nicolas.boisselier@gmail.com>
Tue, 11 Apr 2023 00:45:44 +0000 (02:45 +0200)
etc/profile.d/git.sh

index c26198f8c342da42d7b9d206b6cec1b1fa8eacfb..588f81b14ee642f0cb286b3b425252790ab97914 100644 (file)
@@ -8,6 +8,37 @@ 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() {
+       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
+               return 1
+       fi
+
+       declare owner=$(ls -dl "$file" | awk '{print $3}')
+       [ -n "$owner" ]  || return
+
+       declare cmd=""
+       if [ "$owner" != "$(id --user --name)" ]; then
+               true
+       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\
+ )
+EOF
+
+}
+
 git_new_branch() {
        git checkout -b "$1"
        git push -u origin "$1"