diff --git a/contrib/fast-import/git-p4 b/contrib/fast-import/git-p4 index 47ba7adafb..3881515034 100755 --- a/contrib/fast-import/git-p4 +++ b/contrib/fast-import/git-p4 @@ -1780,7 +1780,9 @@ class P4Sync(Command): changes.sort() else: - if not isinstance(self, P4Clone) and not self.p4BranchesInGit: + # catch "git-p4 sync" with no new branches, in a repo that + # does not have any existing git-p4 branches + if len(args) == 0 and not self.p4BranchesInGit: die("No remote p4 branches. Perhaps you never did \"git p4 clone\" in here."); if self.verbose: print "Getting p4 changes for %s...%s" % (', '.join(self.depotPaths), diff --git a/t/t9800-git-p4.sh b/t/t9800-git-p4.sh index abe7c64ba9..a523473954 100755 --- a/t/t9800-git-p4.sh +++ b/t/t9800-git-p4.sh @@ -61,6 +61,29 @@ test_expect_success 'git-p4 clone @all' ' rm -rf "$git" && mkdir "$git" ' +test_expect_success 'git-p4 sync uninitialized repo' ' + test_create_repo "$git" && + cd "$git" && + test_must_fail "$GITP4" sync && + rm -rf "$git" && mkdir "$git" +' + +# +# Create a git repo by hand. Add a commit so that HEAD is valid. +# Test imports a new p4 repository into a new git branch. +# +test_expect_success 'git-p4 sync new branch' ' + test_create_repo "$git" && + cd "$git" && + test_commit head && + "$GITP4" sync --branch=refs/remotes/p4/depot //depot@all && + git log --oneline p4/depot >lines && + cat lines && + test_line_count = 2 lines && + cd .. && + rm -rf "$git" && mkdir "$git" +' + test_expect_success 'exit when p4 fails to produce marshaled output' ' badp4dir="$TRASH_DIRECTORY/badp4dir" && mkdir -p "$badp4dir" &&