Skip to content

Instantly share code, notes, and snippets.

@toonetown
Last active May 7, 2019 20:23
Show Gist options
  • Select an option

  • Save toonetown/5acae4666ecdf5535c1cff0dcd34a1c7 to your computer and use it in GitHub Desktop.

Select an option

Save toonetown/5acae4666ecdf5535c1cff0dcd34a1c7 to your computer and use it in GitHub Desktop.
Add perforce command line access using git configuration
###########
# Helper script that adds the ability to point to a perforce workspace using git command line
#
#!/bin/bash
PARENT_BRANCH="$(git branch -r -a --merged | sed -nE 's|^[ \*]+remotes/origin/(master\|branches/.*)$|\1|p')"
[ -n "${PARENT_BRANCH}" -a "$(echo "${PARENT_BRANCH}" | wc -l)" -eq 2 ] && {
PARENT_BRANCH="$(echo "${PARENT_BRANCH}" | grep -v '^master$')"
}
[ -n "${PARENT_BRANCH}" -a "$(echo "${PARENT_BRANCH}" | wc -l)" -eq 1 ] || {
echo "Must have a single parent branch under remotes/origin" >&2
exit 1
}
WORKSPACE="$(git config p4rec.${PARENT_BRANCH}.workspace)"
[ -n "${WORKSPACE}" ] || {
echo "Please set \`git config p4rec.${PARENT_BRANCH}.workspace <p4workspace>\`" >&2
exit 1
}
p4 -c ${WORKSPACE} "$@"
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment