Skip to content

Commit f7666d8

Browse files
authored
Merge pull request #579 from intersystems/fix-481
Remove deleted files from index to avoid errors on commit
2 parents 168f172 + f942b73 commit f7666d8

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4141
- Report error more clearly if you try to create a branch with an invalid name (#534)
4242
- Don't default to WINDOWS style paths (#357)
4343
- Fix errors when deleting non-existent files on import (#524)
44+
- Fix errors on commit when a file was added, never committed, then deleted from the repository (#481)
4445
- Fixed issue with saving multiple new no-folder mapping settings at the same time (#533)
4546

4647
## [2.6.0] - 2024-10-07

cls/SourceControl/Git/Change.cls

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,20 @@ ClassMethod RefreshUncommitted(Display = 0, IncludeRevert = 0, Output gitFiles,
177177
if $$$ISERR(sc) continue
178178
}
179179
}
180+
181+
// If a file was added to the index and then deleted, git status will show it as a delete but committing will fail.
182+
// The solution is to git add each deleted file that has never been committed so it will be removed from the index.
183+
set key = $order(gitFiles(""))
184+
while (key '= "") {
185+
if $listget(gitFiles(key),1) = "D" {
186+
set filename = $listget(gitFiles(key),2)
187+
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("log",,.errStream,.outStream,"--first-parent", "--", filename)
188+
if (outStream.Size = 0) {
189+
do ##class(SourceControl.Git.Utils).RunGitCommandWithInput("add",,errStream,outStream,filename)
190+
}
191+
}
192+
set key = $order(gitFiles(key))
193+
}
180194
set ^IRIS.Temp.gitsourcecontrol("Refresh") = $zdatetime($ztimestamp,-2)
181195
merge ^IRIS.Temp.gitsourcecontrol("LastUncommitted") = gitFiles
182196
quit sc

0 commit comments

Comments
 (0)