git p4: create p4/HEAD on initial clone

There is code to create a symbolic reference from p4/HEAD to p4/master. This allows saying "git show p4" as a shortcut to "git show p4/master", for example. But this reference was only created on the second "git p4 sync" (or first sync after a clone). Make it work on the initial clone or sync. Signed-off-by: Pete Wyckoff <pw@padd.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pete Wyckoff committed Jan 14, 2013 at 19:46 UTC 55d124376f1d5d91be4376016d92a6ca6474428a
2 files changed +31 -4
git-p4.py
+8 -4
@@ -2772,10 +2772,7 @@ class P4Sync(Command, P4UserMap):
2772 self.branch = self.refPrefix + "master"
2773 if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
2774 system("git update-ref %s refs/heads/p4" % self.branch)
2775 - system("git branch -D p4");
2776 - # create it /after/ importing, when master exists
2777 - if not gitBranchExists(self.refPrefix + "HEAD") and self.importIntoRemotes and gitBranchExists(self.branch):
2778 - system("git symbolic-ref %sHEAD %s" % (self.refPrefix, self.branch))
2775 + system("git branch -D p4")
2776
2777 # accept either the command-line option, or the configuration variable
2778 if self.useClientSpec:
@@ -3007,6 +3004,13 @@ class P4Sync(Command, P4UserMap):
3004 read_pipe("git update-ref -d %s" % branch)
3005 os.rmdir(os.path.join(os.environ.get("GIT_DIR", ".git"), self.tempBranchLocation))
3006
3007 + # Create a symbolic ref p4/HEAD pointing to p4/<branch> to allow
3008 + # a convenient shortcut refname "p4".
3009 + if self.importIntoRemotes:
3010 + head_ref = self.refPrefix + "HEAD"
3011 + if not gitBranchExists(head_ref) and gitBranchExists(self.branch):
3012 + system(["git", "symbolic-ref", head_ref, self.branch])
3013 +
3014 return True
3015
3016 class P4Rebase(Command):
t/t9806-git-p4-options.sh
+23
@@ -83,6 +83,29 @@ test_expect_failure 'sync --branch updates specified branch' '
83 )
84 '
85
86 +# allows using the refname "p4" as a short name for p4/master
87 +test_expect_success 'clone creates HEAD symbolic reference' '
88 + git p4 clone --dest="$git" //depot &&
89 + test_when_finished cleanup_git &&
90 + (
91 + cd "$git" &&
92 + git rev-parse --verify refs/remotes/p4/master >master &&
93 + git rev-parse --verify p4 >p4 &&
94 + test_cmp master p4
95 + )
96 +'
97 +
98 +test_expect_success 'clone --branch creates HEAD symbolic reference' '
99 + git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
100 + test_when_finished cleanup_git &&
101 + (
102 + cd "$git" &&
103 + git rev-parse --verify refs/remotes/p4/sb >sb &&
104 + git rev-parse --verify p4 >p4 &&
105 + test_cmp sb p4
106 + )
107 +'
108 +
109 test_expect_success 'clone --changesfile' '
110 test_when_finished "rm cf" &&
111 printf "1\n3\n" >cf &&