Skip to content

Commit

Permalink
⚡ QD-9824 Fix names. Add test about moving files.
Browse files Browse the repository at this point in the history
  • Loading branch information
avafanasiev committed Aug 30, 2024
1 parent 0fd56a1 commit 1f0b2b6
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions platform/git_changes.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,10 @@ func getChangedFilesBetweenCommits(repo *git.Repository, cwd, hash1, hash2 strin

for _, change := range changes {
var path = ""
if change.From.Name != "" {
path = change.From.Name
} else {
if change.To.Name != "" {
path = change.To.Name
} else {
path = change.From.Name
}
if path == "" {
continue
Expand Down
39 changes: 39 additions & 0 deletions platform/git_changes_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,36 @@ func TestChangesCalculation(t *testing.T) {
"deleted": []
}
]
}`,
},
{
initialContent: "Hello, New File!\nThis file is newly created.\n",
modifiedContent: "Hello, New File!\nThis file is newly created.\n",
action: "move",
result: `
{
"files": [
{
"path": "file.txt",
"added": [],
"deleted": [
{
"firstLine": 1,
"count": 2
}
]
},
{
"path": "file2.txt",
"added": [
{
"firstLine": 1,
"count": 2
}
],
"deleted": []
}
]
}`,
},
}
Expand Down Expand Up @@ -150,6 +180,7 @@ func createRepo(t *testing.T, tc TestConfig) (string, string, string) {

// File name
fileName := "file.txt"
fileName2 := "file2.txt"

// Step 3: Create the first file and commit it if initial content is not empty
initialFileName := fileName
Expand All @@ -176,6 +207,14 @@ func createRepo(t *testing.T, tc TestConfig) (string, string, string) {
case "modify":
err = os.WriteFile(repoDir+"/"+fileName, []byte(tc.modifiedContent), 0644)
assert.NoError(t, err)
case "move":
cmd = exec.Command("git", "mv", repoDir+"/"+fileName, repoDir+"/"+fileName2)
cmd.Dir = repoDir
err = cmd.Run()
assert.NoError(t, err)
//err = os.Remove(repoDir + "/" + fileName)
//err = os.WriteFile(repoDir+"/"+fileName2, []byte(tc.modifiedContent), 0644)
//assert.NoError(t, err)
case "delete":
err = os.Remove(repoDir + "/" + fileName)
assert.NoError(t, err)
Expand Down

0 comments on commit 1f0b2b6

Please sign in to comment.