lib/pvl/commit/git.sh
changeset 629 7214fe5c6fac
parent 628 b10ad946d01d
equal deleted inserted replaced
628:b10ad946d01d 629:7214fe5c6fac
     1 # Git wrappers
     1 # Git wrappers
     2 
     2 
     3 GIT=/usr/bin/git
     3 GIT=/usr/bin/git
     4 GIT_ARGS=()
     4 GIT_ARGS=()
     5 
       
     6 
     5 
     7 function git_probe {
     6 function git_probe {
     8     local repo=$1
     7     local repo=$1
     9 
     8 
    10     [ -d "$repo/.git" ]
     9     [ -d "$repo/.git" ]
    11 }
    10 }
    12 
    11 
    13 ## Run `git ...` within $REPO.
    12 ## Run `git ...` within $REPO.
    14 function git {
    13 function git {
    15     local repo=$1
    14     local repo=$1
    16     cmd $GIT -C "$repo" "${GIT_ARGS[@]:-}" "${@:2}"
    15     cmd $GIT -C "$repo" ${GIT_ARGS[@]:-} "${@:2}"
       
    16 }
       
    17 
       
    18 function git_test {
       
    19     local repo=$1
       
    20     cmd_test $GIT -C "$repo" ${GIT_ARGS[@]:-} "${@:2}"
    17 }
    21 }
    18 
    22 
    19 ## Does the repo have local modifications?
    23 ## Does the repo have local modifications?
    20 function git_modified {
    24 function git_modified {
    21     local repo=$1
    25     local repo=$1
    22 
    26 
    23     git $repo diff --quiet
    27     if git_test $repo diff --quiet; then
       
    28         # unmodified
       
    29         return 1
       
    30     else
       
    31         return 0
       
    32     fi
    24 }
    33 }
    25 
    34 
    26 ## Get the date for the current commit as an unix timestamp
    35 ## Get the date for the current commit as an unix timestamp
    27 function hg_time {
    36 function git_time {
    28     local repo=$1
    37     local repo=$1
    29 
    38 
    30     git $repo log -1 --format=format:%ct
    39     git $repo log -1 --format=format:%ct
    31 }
    40 }
    32 
    41 
    52         opts+=("--author=$SUDO_USER")
    61         opts+=("--author=$SUDO_USER")
    53     fi
    62     fi
    54     
    63     
    55     if [ "$msg" ]; then
    64     if [ "$msg" ]; then
    56         opts+=('-m' "$msg")
    65         opts+=('-m' "$msg")
       
    66     else
       
    67         opts+=('--allow-empty-message')
    57     fi
    68     fi
    58    
    69     
    59     git $repo commit -a "${opts[@]:-}"
    70     if [ ${#opts[@]} = 0 ]; then
       
    71         git $repo commit -a
       
    72     else
       
    73         git $repo commit -a "${opts[@]}"
       
    74     fi
    60 }
    75 }