Skip to content

Commit

Permalink
Dir delete overrides modify
Browse files Browse the repository at this point in the history
  • Loading branch information
rcowham committed Jun 20, 2023
1 parent 3a66b91 commit e785da9
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
9 changes: 5 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1534,7 +1534,7 @@ func (g *GitP4Transfer) singleFileDelete(newfiles []*GitFile, gf *GitFile, cmt *
if len(dups) > 0 {
for _, dupGf := range dups {
if dupGf.action == modify {
g.logger.Debugf("DeleteOverridesModify: GitFile: %s ID %d, %s", cmt.ref(), dupGf.ID, gf.name)
g.logger.Debugf("DeleteOverridesModify1: GitFile: %s ID %d, %s", cmt.ref(), dupGf.ID, gf.name)
dupGf.actionInvalid = true
g.blobFileMatcher.removeGitFile(dupGf)
if !singleFile {
Expand Down Expand Up @@ -1689,8 +1689,8 @@ func (g *GitP4Transfer) ValidateCommit(cmt *GitCommit) {
// * invalid delete (attempted delete of non-existant file or path - log and ignore)
// Note that dir deletes can also override other (prior) actions in same commit
files := node.GetFiles(gf.name)
commitDeletes := findModifyDirNameMatches(newfiles, gf.name)
for _, df := range commitDeletes {
deleteOverrides := findModifyDirNameMatches(newfiles, gf.name)
for _, df := range deleteOverrides {
found := false
for _, f := range files {
if f == df.name {
Expand All @@ -1699,8 +1699,9 @@ func (g *GitP4Transfer) ValidateCommit(cmt *GitCommit) {
}
}
if !found {
g.logger.Debugf("DeleteOverrideModify: %s Dir:%s File:%s", cmt.ref(), gf.name, df.name)
g.logger.Debugf("DirDeleteOverridesModify2: %s Dir:%s File:%s", cmt.ref(), gf.name, df.name)
df.actionInvalid = true
g.blobFileMatcher.removeGitFile(df)
}
}
filesDeleted := 0
Expand Down
76 changes: 76 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4105,6 +4105,82 @@ M 100644 :2 src/file2.txt
assert.Equal(t, "contents02\n", result)
}

func TestDirDeleteOverridesModifySameCommit(t *testing.T) {
// Delete of modify in same commit
logger := createLogger()
logger.Debugf("======== Test: %s", t.Name())

gitExport := `blob
mark :1
data 11
contents01
blob
mark :2
data 11
contents02
reset refs/heads/main
commit refs/heads/main
mark :3
author Robert Cowham <rcowham@perforce.com> 1680784555 +0100
committer Robert Cowham <rcowham@perforce.com> 1680784555 +0100
data 8
initial
M 100644 :1 src/file1.txt
reset refs/heads/dev
commit refs/heads/dev
mark :4
author Robert Cowham <rcowham@perforce.com> 1680784555 +0100
committer Robert Cowham <rcowham@perforce.com> 1680784555 +0100
data 6
dev01
from :3
M 100644 :2 src/file2.txt
D src
reset refs/heads/dev
commit refs/heads/dev
mark :5
author Robert Cowham <rcowham@perforce.com> 1680784555 +0100
committer Robert Cowham <rcowham@perforce.com> 1680784555 +0100
data 6
dev02
from :4
M 100644 :2 src/file2.txt
`

r := runTransferWithDump(t, logger, gitExport, nil)
logger.Debugf("Server root: %s", r)

result, err := runCmd("p4 verify -qu //...")
assert.Equal(t, "", result)
assert.Equal(t, "<nil>", fmt.Sprint(err))

result, err = runCmd("p4 files //...")
assert.Equal(t, nil, err)
assert.Equal(t, `//import/dev/src/file1.txt#1 - delete change 4 (text+C)
//import/dev/src/file2.txt#1 - add change 5 (text+C)
//import/main/src/file1.txt#1 - add change 3 (text+C)
`,
result)

result, err = runCmd("p4 filelog //...")
assert.Equal(t, nil, err)
reExpected := `//import/dev/src/file1.txt
... #1 change 4 delete on \S+ by \S+ \S+ 'dev01 '
//import/dev/src/file2.txt
... #1 change 5 add on \S+ by \S+ \S+ 'dev02 '
//import/main/src/file1.txt
... #1 change 3 add on \S+ by \S+ \S+ 'initial '
`
assert.Regexp(t, reExpected, result)
compareFilelog(t, reExpected, result)

}

func TestDeleteOfRenamedDir(t *testing.T) {
// Dir renamed and target deleted
logger := createLogger()
Expand Down

0 comments on commit e785da9

Please sign in to comment.