git p4: create p4/HEAD on initial clone
authorPete Wyckoff <pw@padd.com>
Tue, 15 Jan 2013 00:46:59 +0000 (19:46 -0500)
committerJunio C Hamano <gitster@pobox.com>
Tue, 15 Jan 2013 17:46:29 +0000 (09:46 -0800)
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>
git-p4.py
t/t9806-git-p4-options.sh
index 2443f79e07203475bd0cebe9dbfb0370b0ef2499..7a0c0409bebf0d8894293c2f76ab8d22b8332cb3 100755 (executable)
--- a/git-p4.py
+++ b/git-p4.py
@@ -2772,10 +2772,7 @@ def run(self, args):
             self.branch = self.refPrefix + "master"
             if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
                 system("git update-ref %s refs/heads/p4" % self.branch)
             self.branch = self.refPrefix + "master"
             if gitBranchExists("refs/heads/p4") and self.importIntoRemotes:
                 system("git update-ref %s refs/heads/p4" % self.branch)
-                system("git branch -D p4");
-            # create it /after/ importing, when master exists
-            if not gitBranchExists(self.refPrefix + "HEAD") and self.importIntoRemotes and gitBranchExists(self.branch):
-                system("git symbolic-ref %sHEAD %s" % (self.refPrefix, self.branch))
+                system("git branch -D p4")
 
         # accept either the command-line option, or the configuration variable
         if self.useClientSpec:
 
         # accept either the command-line option, or the configuration variable
         if self.useClientSpec:
@@ -3007,6 +3004,13 @@ def run(self, args):
                 read_pipe("git update-ref -d %s" % branch)
             os.rmdir(os.path.join(os.environ.get("GIT_DIR", ".git"), self.tempBranchLocation))
 
                 read_pipe("git update-ref -d %s" % branch)
             os.rmdir(os.path.join(os.environ.get("GIT_DIR", ".git"), self.tempBranchLocation))
 
+        # Create a symbolic ref p4/HEAD pointing to p4/<branch> to allow
+        # a convenient shortcut refname "p4".
+        if self.importIntoRemotes:
+            head_ref = self.refPrefix + "HEAD"
+            if not gitBranchExists(head_ref) and gitBranchExists(self.branch):
+                system(["git", "symbolic-ref", head_ref, self.branch])
+
         return True
 
 class P4Rebase(Command):
         return True
 
 class P4Rebase(Command):
index 844aae048ec58be1c5dfa8b3561044332c82e3de..4900aef19e69a6f568d08e7b24fde20b1960ec32 100755 (executable)
@@ -83,6 +83,29 @@ test_expect_failure 'sync --branch updates specified branch' '
        )
 '
 
        )
 '
 
+# allows using the refname "p4" as a short name for p4/master
+test_expect_success 'clone creates HEAD symbolic reference' '
+       git p4 clone --dest="$git" //depot &&
+       test_when_finished cleanup_git &&
+       (
+               cd "$git" &&
+               git rev-parse --verify refs/remotes/p4/master >master &&
+               git rev-parse --verify p4 >p4 &&
+               test_cmp master p4
+       )
+'
+
+test_expect_success 'clone --branch creates HEAD symbolic reference' '
+       git p4 clone --branch=refs/remotes/p4/sb --dest="$git" //depot &&
+       test_when_finished cleanup_git &&
+       (
+               cd "$git" &&
+               git rev-parse --verify refs/remotes/p4/sb >sb &&
+               git rev-parse --verify p4 >p4 &&
+               test_cmp sb p4
+       )
+'
+
 test_expect_success 'clone --changesfile' '
        test_when_finished "rm cf" &&
        printf "1\n3\n" >cf &&
 test_expect_success 'clone --changesfile' '
        test_when_finished "rm cf" &&
        printf "1\n3\n" >cf &&