{"thread":{"id":"17972","subject":"example of git-p4 usage: checking out remote branches?","startedAt":"2009-02-23T16:30:52Z","lastAt":"2009-02-23T16:30:52Z","messageCount":1,"participants":["christopherlmarshall@yahoo.com"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"105914","messageId":"4431fe90-a540-4b19-954f-78465ef91eb2@e18g2000yqo.googlegroups.com","threadId":"17972","inReplyTo":null,"subject":"example of git-p4 usage: checking out remote branches?","fromName":"christopherlmarshall@yahoo.com","fromEmail":"christopherlmarshall@yahoo.com","sentAt":"2009-02-23T16:30:52Z","receivedAt":"2009-02-23T16:30:52Z","isPatch":false,"sender":{"key":"christopherlmarshall@yahoo.com","avatar":null},"body":"I am trying to learn how to use git-p4 to clone a perforce depot with\nmultiple branches to a git repo, push git changes back to p4, and pull\np4 changes into a git repo.\n\nI have written a bash script that executes a scenario like this end-to-\nend.\n\nI am wondering if the commands I am using make sense or if they are\nmissing the point of git-p4; is my approach absurdly cumbersome?\n\nIn particular, should I really be checking out a remote branch, then\ncreating a local branch from it to work with?\n\nI'm attached my bash script below.\n\nChris Marshall\n\n#!/bin/bash\n# file_summary: git-p4 clone, illustrates importing p4 repo, git -> p4\nchanges, and p4 -> git changes\n\nrm -rf server workspace\nmkdir -p server workspace git-proj\nCWD=$(pwd)\n\n# start server\ncd server\np4d -f -p 1666 &\np4pid=$!\ndisown $p4pid\n\n#\ncd ../workspace\nexport P4PORT=1666\nexport P4CLIENT=testws\nexport P4EDITOR=true\n\n# create client\nwhile ! p4 client -o > tmp.txt ; do\nsleep 1\ndone\np4 client -i < tmp.txt\n\n# create some files in the mainline of a project\nmkdir -p proj1/main\ncd proj1/main\necho \"1\" > f1\necho \"2\" >> f1\necho \"3\" >> f1\necho \"4\" >> f1\necho \"5\" >> f1\np4 add f1\np4 submit -d \"initial checkin\"\nsleep 2\n\n# create a branch\n(\n   echo \"Branch: main2br1\"\n   echo \"View:\"\n   echo \"   //depot/proj1/main/... //depot/proj1/br1/...\"\n) | p4 branch -i\n\np4 integrate -b main2br1\np4 submit -d \"created br1 branch\"\nsleep 2\n\n# change main line\np4 edit f1\necho \"1\" > f1\necho \"2\" >> f1\necho \"3\" >> f1\necho \"4\" >> f1\necho \"4.1\" >> f1\necho \"5\" >> f1\np4 submit -d \"4.1 -> f1 on main line\" f1\nsleep 2\n\n# change branch\ncd ../br1\np4 edit f1\necho \"1\" > f1\necho \"2\" >> f1\necho \"2.1\" >> f1\necho \"3\" >> f1\necho \"4\" >> f1\necho \"5\" >> f1\np4 submit -d \"2.1 -> f1 on br1\" f1\nsleep 2\n\ncd $CWD\ncd git-proj\ngit-p4 clone //depot/proj1@all proj1 --detect-branches\n\ncd proj1\n\n# checkout the head of the remote branch\ngit checkout p4/proj1/br1\n\n# create a local branch to work with\ngit branch br1\ngit checkout br1\n\n# make changes\necho \"1\" > f1\necho \"2\" >> f1\necho \"2.1\" >> f1\necho \"2.2\" >> f1\necho \"3\" >> f1\necho \"4\" >> f1\necho \"5\" >> f1\n# commit\ngit commit -a -m \"2.2 -> f1 on br1\"\n\n# br1: submit back to perforce\n(\n   echo \"y\"\n) | git-p4 submit\n\n# p4 2.3 -> f1 on br1\ncd ${CWD}/workspace/proj1/br1\np4 edit f1\necho \"1\" > f1\necho \"2\" >> f1\necho \"2.1\" >> f1\necho \"2.2\" >> f1\necho \"2.3\" >> f1\necho \"3\" >> f1\necho \"4\" >> f1\necho \"5\" >> f1\np4 submit -d \"2.3 -> f1 on br1\"\n\n# pull them into git repo\ncd ${CWD}/git-proj/proj1\ngit-p4 sync //depot/proj1@all --detect-branches\ngit merge p4/proj1/br1\n\n# kill server\nkill $p4pid\ncd  $CWD\nrm -rf workspace server git-proj\n"}]}