Merge branch 'tk/p4-with-explicity-sync'
"git p4" update. * tk/p4-with-explicity-sync: git-p4: support explicit sync of arbitrary existing git-p4 refs
This commit is contained in:
commit
af3a3205d1
51
git-p4.py
51
git-p4.py
@ -994,6 +994,35 @@ def gitConfigList(key):
|
|||||||
_gitConfig[key] = []
|
_gitConfig[key] = []
|
||||||
return _gitConfig[key]
|
return _gitConfig[key]
|
||||||
|
|
||||||
|
def fullP4Ref(incomingRef, importIntoRemotes=True):
|
||||||
|
"""Standardize a given provided p4 ref value to a full git ref:
|
||||||
|
refs/foo/bar/branch -> use it exactly
|
||||||
|
p4/branch -> prepend refs/remotes/ or refs/heads/
|
||||||
|
branch -> prepend refs/remotes/p4/ or refs/heads/p4/"""
|
||||||
|
if incomingRef.startswith("refs/"):
|
||||||
|
return incomingRef
|
||||||
|
if importIntoRemotes:
|
||||||
|
prepend = "refs/remotes/"
|
||||||
|
else:
|
||||||
|
prepend = "refs/heads/"
|
||||||
|
if not incomingRef.startswith("p4/"):
|
||||||
|
prepend += "p4/"
|
||||||
|
return prepend + incomingRef
|
||||||
|
|
||||||
|
def shortP4Ref(incomingRef, importIntoRemotes=True):
|
||||||
|
"""Standardize to a "short ref" if possible:
|
||||||
|
refs/foo/bar/branch -> ignore
|
||||||
|
refs/remotes/p4/branch or refs/heads/p4/branch -> shorten
|
||||||
|
p4/branch -> shorten"""
|
||||||
|
if importIntoRemotes:
|
||||||
|
longprefix = "refs/remotes/p4/"
|
||||||
|
else:
|
||||||
|
longprefix = "refs/heads/p4/"
|
||||||
|
if incomingRef.startswith(longprefix):
|
||||||
|
return incomingRef[len(longprefix):]
|
||||||
|
if incomingRef.startswith("p4/"):
|
||||||
|
return incomingRef[3:]
|
||||||
|
return incomingRef
|
||||||
|
|
||||||
def p4BranchesInGit(branchesAreInRemotes=True):
|
def p4BranchesInGit(branchesAreInRemotes=True):
|
||||||
"""Find all the branches whose names start with "p4/", looking
|
"""Find all the branches whose names start with "p4/", looking
|
||||||
@ -3920,9 +3949,13 @@ class P4Sync(Command, P4UserMap):
|
|||||||
|
|
||||||
# restrict to just this one, disabling detect-branches
|
# restrict to just this one, disabling detect-branches
|
||||||
if branch_arg_given:
|
if branch_arg_given:
|
||||||
short = self.branch.split("/")[-1]
|
short = shortP4Ref(self.branch, self.importIntoRemotes)
|
||||||
if short in branches:
|
if short in branches:
|
||||||
self.p4BranchesInGit = [short]
|
self.p4BranchesInGit = [short]
|
||||||
|
elif self.branch.startswith('refs/') and \
|
||||||
|
branchExists(self.branch) and \
|
||||||
|
'[git-p4:' in extractLogMessageFromGitCommit(self.branch):
|
||||||
|
self.p4BranchesInGit = [self.branch]
|
||||||
else:
|
else:
|
||||||
self.p4BranchesInGit = branches.keys()
|
self.p4BranchesInGit = branches.keys()
|
||||||
|
|
||||||
@ -3939,7 +3972,8 @@ class P4Sync(Command, P4UserMap):
|
|||||||
|
|
||||||
p4Change = 0
|
p4Change = 0
|
||||||
for branch in self.p4BranchesInGit:
|
for branch in self.p4BranchesInGit:
|
||||||
logMsg = extractLogMessageFromGitCommit(self.refPrefix + branch)
|
logMsg = extractLogMessageFromGitCommit(fullP4Ref(branch,
|
||||||
|
self.importIntoRemotes))
|
||||||
|
|
||||||
settings = extractSettingsGitLog(logMsg)
|
settings = extractSettingsGitLog(logMsg)
|
||||||
|
|
||||||
@ -3971,18 +4005,7 @@ class P4Sync(Command, P4UserMap):
|
|||||||
if not self.silent and not self.detectBranches:
|
if not self.silent and not self.detectBranches:
|
||||||
print("Performing incremental import into %s git branch" % self.branch)
|
print("Performing incremental import into %s git branch" % self.branch)
|
||||||
|
|
||||||
# accept multiple ref name abbreviations:
|
self.branch = fullP4Ref(self.branch, self.importIntoRemotes)
|
||||||
# refs/foo/bar/branch -> use it exactly
|
|
||||||
# p4/branch -> prepend refs/remotes/ or refs/heads/
|
|
||||||
# branch -> prepend refs/remotes/p4/ or refs/heads/p4/
|
|
||||||
if not self.branch.startswith("refs/"):
|
|
||||||
if self.importIntoRemotes:
|
|
||||||
prepend = "refs/remotes/"
|
|
||||||
else:
|
|
||||||
prepend = "refs/heads/"
|
|
||||||
if not self.branch.startswith("p4/"):
|
|
||||||
prepend += "p4/"
|
|
||||||
self.branch = prepend + self.branch
|
|
||||||
|
|
||||||
if len(args) == 0 and self.depotPaths:
|
if len(args) == 0 and self.depotPaths:
|
||||||
if not self.silent:
|
if not self.silent:
|
||||||
|
@ -74,6 +74,91 @@ test_expect_success 'git p4 sync new branch' '
|
|||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
#
|
||||||
|
# Setup as before, and then explicitly sync imported branch, using a
|
||||||
|
# different ref format.
|
||||||
|
#
|
||||||
|
test_expect_success 'git p4 sync existing branch without changes' '
|
||||||
|
test_create_repo "$git" &&
|
||||||
|
test_when_finished cleanup_git &&
|
||||||
|
(
|
||||||
|
cd "$git" &&
|
||||||
|
test_commit head &&
|
||||||
|
git p4 sync --branch=depot //depot@all &&
|
||||||
|
git p4 sync --branch=refs/remotes/p4/depot >out &&
|
||||||
|
test_i18ngrep "No changes to import!" out
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
#
|
||||||
|
# Same as before, relative branch name.
|
||||||
|
#
|
||||||
|
test_expect_success 'git p4 sync existing branch with relative name' '
|
||||||
|
test_create_repo "$git" &&
|
||||||
|
test_when_finished cleanup_git &&
|
||||||
|
(
|
||||||
|
cd "$git" &&
|
||||||
|
test_commit head &&
|
||||||
|
git p4 sync --branch=branch1 //depot@all &&
|
||||||
|
git p4 sync --branch=p4/branch1 >out &&
|
||||||
|
test_i18ngrep "No changes to import!" out
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
#
|
||||||
|
# Same as before, with a nested branch path, referenced different ways.
|
||||||
|
#
|
||||||
|
test_expect_success 'git p4 sync existing branch with nested path' '
|
||||||
|
test_create_repo "$git" &&
|
||||||
|
test_when_finished cleanup_git &&
|
||||||
|
(
|
||||||
|
cd "$git" &&
|
||||||
|
test_commit head &&
|
||||||
|
git p4 sync --branch=p4/some/path //depot@all &&
|
||||||
|
git p4 sync --branch=some/path >out &&
|
||||||
|
test_i18ngrep "No changes to import!" out
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
#
|
||||||
|
# Same as before, with a full ref path outside the p4/* namespace.
|
||||||
|
#
|
||||||
|
test_expect_success 'git p4 sync branch explicit ref without p4 in path' '
|
||||||
|
test_create_repo "$git" &&
|
||||||
|
test_when_finished cleanup_git &&
|
||||||
|
(
|
||||||
|
cd "$git" &&
|
||||||
|
test_commit head &&
|
||||||
|
git p4 sync --branch=refs/remotes/someremote/depot //depot@all &&
|
||||||
|
git p4 sync --branch=refs/remotes/someremote/depot >out &&
|
||||||
|
test_i18ngrep "No changes to import!" out
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git p4 sync nonexistent ref' '
|
||||||
|
test_create_repo "$git" &&
|
||||||
|
test_when_finished cleanup_git &&
|
||||||
|
(
|
||||||
|
cd "$git" &&
|
||||||
|
test_commit head &&
|
||||||
|
git p4 sync --branch=depot //depot@all &&
|
||||||
|
test_must_fail git p4 sync --branch=depot2 2>errs &&
|
||||||
|
test_i18ngrep "Perhaps you never did" errs
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
|
test_expect_success 'git p4 sync existing non-p4-imported ref' '
|
||||||
|
test_create_repo "$git" &&
|
||||||
|
test_when_finished cleanup_git &&
|
||||||
|
(
|
||||||
|
cd "$git" &&
|
||||||
|
test_commit head &&
|
||||||
|
git p4 sync --branch=depot //depot@all &&
|
||||||
|
test_must_fail git p4 sync --branch=refs/heads/master 2>errs &&
|
||||||
|
test_i18ngrep "Perhaps you never did" errs
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'clone two dirs' '
|
test_expect_success 'clone two dirs' '
|
||||||
(
|
(
|
||||||
cd "$cli" &&
|
cd "$cli" &&
|
||||||
|
@ -129,6 +129,16 @@ test_expect_success 'import depot, branch detection' '
|
|||||||
)
|
)
|
||||||
'
|
'
|
||||||
|
|
||||||
|
test_expect_success 'sync specific detected branch' '
|
||||||
|
test_when_finished cleanup_git &&
|
||||||
|
git p4 clone --dest="$git" --detect-branches //depot@all &&
|
||||||
|
(
|
||||||
|
cd "$git" &&
|
||||||
|
git p4 sync --branch=depot/branch2 >out &&
|
||||||
|
test_i18ngrep "No changes to import!" out
|
||||||
|
)
|
||||||
|
'
|
||||||
|
|
||||||
test_expect_success 'import depot, branch detection, branchList branch definition' '
|
test_expect_success 'import depot, branch detection, branchList branch definition' '
|
||||||
test_when_finished cleanup_git &&
|
test_when_finished cleanup_git &&
|
||||||
test_create_repo "$git" &&
|
test_create_repo "$git" &&
|
||||||
|
Loading…
Reference in New Issue
Block a user