From e785da9157458c0ea94febcbefdfc8fc5aa8b6a1 Mon Sep 17 00:00:00 2001 From: Robert Cowham Date: Tue, 20 Jun 2023 18:07:25 +0100 Subject: [PATCH] Dir delete overrides modify --- main.go | 9 ++++--- main_test.go | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+), 4 deletions(-) diff --git a/main.go b/main.go index 55301d7..fc66aef 100644 --- a/main.go +++ b/main.go @@ -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 { @@ -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 { @@ -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 diff --git a/main_test.go b/main_test.go index b11e4b2..10414b0 100644 --- a/main_test.go +++ b/main_test.go @@ -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 1680784555 +0100 +committer Robert Cowham 1680784555 +0100 +data 8 +initial +M 100644 :1 src/file1.txt + +reset refs/heads/dev +commit refs/heads/dev +mark :4 +author Robert Cowham 1680784555 +0100 +committer Robert Cowham 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 1680784555 +0100 +committer Robert Cowham 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, "", 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()