Last active
May 7, 2019 20:23
-
-
Save toonetown/5acae4666ecdf5535c1cff0dcd34a1c7 to your computer and use it in GitHub Desktop.
Add perforce command line access using git configuration
This file contains hidden or 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
| ########### | |
| # 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