Guest User

Untitled

a guest
Jan 17th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #!/bin/bash
  2. # Fetch the PID of git commit command just ran
  3. PID=$(ps aux | grep "git commit" | tail -1 | awk '{print $2}')
  4. # If unable to fetch the PID, give it another try
  5. if [[ -z "$PID" ]]; then
  6. echo "unable to get process id, please try again.."
  7. exit 1
  8. fi
  9. # Fetch the command used
  10. COMMAND=$(ps -p "$PID" -o args)
  11. # At times, unable to fetch the command used from PID
  12. # Checking Line counts and exits
  13. COMMAND_LINE_COUNT=$(ps -p "$PID" -o args | wc -l)
  14. if [[ $COMMAND_LINE_COUNT -eq 1 ]]; then
  15. echo "unable to fetch the command, please try again.."
  16. exit 1
  17. fi
  18. COMMAND=$(echo "$COMMAND" | tail -1)
  19.  
  20. # Print the Command observed
  21. # echo $COMMAND
  22.  
  23. # Variable to store if the command is ammend
  24. is_ammend=false
  25.  
  26. # Check if command is amend by regex match
  27. if [[ $COMMAND == *"amend"* ]]; then
  28. is_ammend=true
  29. fi
  30.  
  31. # If the issued command is ammend, validate the current author and previous commit author
  32. if [[ $is_ammend = "true" ]]; then
  33. echo "Looks like you are ammending the code.. "
  34. PREV_AUTHOR=$(git log --pretty=format:"%an" | head -1)
  35. CURRENT_AUTHOR=$(git config --global user.name)
  36. if [ "$PREV_AUTHOR" != "$CURRENT_AUTHOR" ]; then
  37. echo "Current Author $CURRENT_AUTHOR"
  38. echo "Previous Author $PREV_AUTHOR"
  39. echo "ammends to other's commit is not supported..."
  40. exit 1
  41. fi
  42. fi
  43.  
  44. exit 0
Add Comment
Please, Sign In to add comment