example of git-p4 usage: checking out remote branches?
From: christopherlmarshall@yahoo.com <hidden>
Date: 2016-06-15 22:46:16
I am trying to learn how to use git-p4 to clone a perforce depot with
multiple branches to a git repo, push git changes back to p4, and pull
p4 changes into a git repo.
I have written a bash script that executes a scenario like this end-to-
end.
I am wondering if the commands I am using make sense or if they are
missing the point of git-p4; is my approach absurdly cumbersome?
In particular, should I really be checking out a remote branch, then
creating a local branch from it to work with?
I'm attached my bash script below.
Chris Marshall
#!/bin/bash
# file_summary: git-p4 clone, illustrates importing p4 repo, git -> p4
changes, and p4 -> git changes
rm -rf server workspace
mkdir -p server workspace git-proj
CWD=$(pwd)
# start server
cd server
p4d -f -p 1666 &
p4pid=$!
disown $p4pid
#
cd ../workspace
export P4PORT=1666
export P4CLIENT=testws
export P4EDITOR=true
# create client
while ! p4 client -o > tmp.txt ; do
sleep 1
done
p4 client -i < tmp.txt
# create some files in the mainline of a project
mkdir -p proj1/main
cd proj1/main
echo "1" > f1
echo "2" >> f1
echo "3" >> f1
echo "4" >> f1
echo "5" >> f1
p4 add f1
p4 submit -d "initial checkin"
sleep 2
# create a branch
(
echo "Branch: main2br1"
echo "View:"
echo " //depot/proj1/main/... //depot/proj1/br1/..."
) | p4 branch -i
p4 integrate -b main2br1
p4 submit -d "created br1 branch"
sleep 2
# change main line
p4 edit f1
echo "1" > f1
echo "2" >> f1
echo "3" >> f1
echo "4" >> f1
echo "4.1" >> f1
echo "5" >> f1
p4 submit -d "4.1 -> f1 on main line" f1
sleep 2
# change branch
cd ../br1
p4 edit f1
echo "1" > f1
echo "2" >> f1
echo "2.1" >> f1
echo "3" >> f1
echo "4" >> f1
echo "5" >> f1
p4 submit -d "2.1 -> f1 on br1" f1
sleep 2
cd $CWD
cd git-proj
git-p4 clone //depot/proj1@all proj1 --detect-branches
cd proj1
# checkout the head of the remote branch
git checkout p4/proj1/br1
# create a local branch to work with
git branch br1
git checkout br1
# make changes
echo "1" > f1
echo "2" >> f1
echo "2.1" >> f1
echo "2.2" >> f1
echo "3" >> f1
echo "4" >> f1
echo "5" >> f1
# commit
git commit -a -m "2.2 -> f1 on br1"
# br1: submit back to perforce
(
echo "y"
) | git-p4 submit
# p4 2.3 -> f1 on br1
cd ${CWD}/workspace/proj1/br1
p4 edit f1
echo "1" > f1
echo "2" >> f1
echo "2.1" >> f1
echo "2.2" >> f1
echo "2.3" >> f1
echo "3" >> f1
echo "4" >> f1
echo "5" >> f1
p4 submit -d "2.3 -> f1 on br1"
# pull them into git repo
cd ${CWD}/git-proj/proj1
git-p4 sync //depot/proj1@all --detect-branches
git merge p4/proj1/br1
# kill server
kill $p4pid
cd $CWD
rm -rf workspace server git-proj