Skip to content

Commit 55d1243

Browse files
Pete Wyckoffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3b650fc commit 55d1243

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

git-p4.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2772,10 +2772,7 @@ def run(self, args):
27722772
self.branch = self.refPrefix + "master"
27732773
if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
27742774
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")
27792776

27802777
# accept either the command-line option, or the configuration variable
27812778
if self.useClientSpec:
@@ -3007,6 +3004,13 @@ def run(self, args):
30073004
read_pipe("git update-ref -d %s" % branch)
30083005
os.rmdir(os.path.join(os.environ.get("GIT_DIR", ".git"), self.tempBranchLocation))
30093006

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+
30103014
return True
30113015

30123016
class P4Rebase(Command):

t/t9806-git-p4-options.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,29 @@ test_expect_failure 'sync --branch updates specified branch' '
8383
)
8484
'
8585

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+
86109
test_expect_success 'clone --changesfile' '
87110
test_when_finished "rm cf" &&
88111
printf "1\n3\n" >cf &&

0 commit comments

Comments
 (0)