Skip to content

Instantly share code, notes, and snippets.

@vmassuchetto
Created September 25, 2017 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vmassuchetto/9dde12e45192c35aa96670bc0d8cee4a to your computer and use it in GitHub Desktop.
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)
#!/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@example.com>":
#
# Display Name <firstuser@example.com>
# Other Display Name <otheruser@example.com>
# Some Other <someother@example.com>
# (...)
#
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