Created
September 25, 2017 15:21
-
-
Save vmassuchetto/9dde12e45192c35aa96670bc0d8cee4a to your computer and use it in GitHub Desktop.
Commit and push changes on a shared codebase using a single user (used in Cobol mainframes for teams not familiar with Git)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Script to help users in version control in a shared codebase | |
# and a single user account. It will parse a USERS_FILE to | |
# fill the proper committer info and push changes. Pull and | |
# merges are not used. Pushes are forced because the main codebase | |
# is the work-tree and not the upstream code. | |
# | |
function help { | |
echo "" | |
echo "Usage:" | |
echo "" | |
echo "List modified files:" | |
echo "" | |
echo " commit.sh" | |
echo "" | |
echo "Commit modified files:" | |
echo "" | |
echo " commit.sh [ <username> <file1> <file2> <file3> ... ]" | |
echo "" | |
echo "Example:" | |
echo "" | |
echo " commit.sh carolina /dev/ain/SCF23510.CBL /dev/art/SCF23610.CBL" | |
echo "" | |
exit | |
} | |
# User file with user in each line like "Display Name <[email protected]>": | |
# | |
# Display Name <[email protected]> | |
# Other Display Name <[email protected]> | |
# Some Other <[email protected]> | |
# (...) | |
# | |
USERS_FILE="/cobol/desenv/bin/comita_usuarios.txt" | |
# Git paths | |
export GIT="/usr/bin/git --git-dir /codebase/.git --work-tree /codebase" | |
if [[ -z "$@" ]] ; then | |
$GIT status -s | |
exit | |
fi | |
if [[ -z "$1" ]] || ! grep -q "<$1@" $USERS_FILE ; then | |
echo "ERROR: Invalid user." | |
ajuda | |
fi | |
AUTHOR="`grep "<$1@" $USERS_FILE`" | |
shift 1 | |
if [[ -z "$@" ]] ; then | |
echo "ERROR: No files to commit." | |
help | |
fi | |
VERSION_BEFORE="`$GIT show-ref --heads -s master`" | |
$GIT add "$@" | |
$GIT commit --quiet --verbose --author "$AUTHOR" "$@" | |
VERSAO_AFTER="`$GIT show-ref --heads -s master`" | |
if [[ $VERSION_BEFORE != $VERSION_AFTER ]] ; then | |
$GIT push --force | |
fi | |
# Leave without staging anything | |
$GIT reset 2>&1 > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment