Skip to content

Commit 6f859ca

Browse files
kofta999isomorphic-git-bot
authored andcommitted
fix: merging when file is deleted from both branches (#2111)
* test: add case for merging when file is deleted from both branches * fix: merging when file is deleted from both branches * chore: fix typos in merge command and test
1 parent cb31864 commit 6f859ca

File tree

5 files changed

+41
-11
lines changed

5 files changed

+41
-11
lines changed

js/isomorphic-git/index.cjs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9392,7 +9392,12 @@ async function mergeTree({
93929392
}
93939393

93949394
// deleted by both
9395-
if (base && !ours && !theirs && (await base.type()) === 'blob') {
9395+
if (
9396+
base &&
9397+
!ours &&
9398+
!theirs &&
9399+
((await base.type()) === 'blob' || (await base.type()) === 'tree')
9400+
) {
93969401
return undefined
93979402
}
93989403

@@ -9416,9 +9421,19 @@ async function mergeTree({
94169421
if (!parent) return
94179422

94189423
// automatically delete directories if they have been emptied
9419-
if (parent && parent.type === 'tree' && entries.length === 0) return
9424+
// except for the root directory
9425+
if (
9426+
parent &&
9427+
parent.type === 'tree' &&
9428+
entries.length === 0 &&
9429+
parent.path !== '.'
9430+
)
9431+
return
94209432

9421-
if (entries.length > 0) {
9433+
if (
9434+
entries.length > 0 ||
9435+
(parent.path === '.' && entries.length === 0)
9436+
) {
94229437
const tree = new GitTree(entries);
94239438
const object = tree.toObject();
94249439
const oid = await _writeObject({
@@ -9682,7 +9697,7 @@ async function _merge({
96829697
);
96839698

96849699
// Defer throwing error until the index lock is relinquished and index is
9685-
// written to filsesystem
9700+
// written to filesystem
96869701
if (tree instanceof MergeConflictError) throw tree
96879702

96889703
if (!message) {

js/isomorphic-git/index.js

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9386,7 +9386,12 @@ async function mergeTree({
93869386
}
93879387

93889388
// deleted by both
9389-
if (base && !ours && !theirs && (await base.type()) === 'blob') {
9389+
if (
9390+
base &&
9391+
!ours &&
9392+
!theirs &&
9393+
((await base.type()) === 'blob' || (await base.type()) === 'tree')
9394+
) {
93909395
return undefined
93919396
}
93929397

@@ -9410,9 +9415,19 @@ async function mergeTree({
94109415
if (!parent) return
94119416

94129417
// automatically delete directories if they have been emptied
9413-
if (parent && parent.type === 'tree' && entries.length === 0) return
9418+
// except for the root directory
9419+
if (
9420+
parent &&
9421+
parent.type === 'tree' &&
9422+
entries.length === 0 &&
9423+
parent.path !== '.'
9424+
)
9425+
return
94149426

9415-
if (entries.length > 0) {
9427+
if (
9428+
entries.length > 0 ||
9429+
(parent.path === '.' && entries.length === 0)
9430+
) {
94169431
const tree = new GitTree(entries);
94179432
const object = tree.toObject();
94189433
const oid = await _writeObject({
@@ -9676,7 +9691,7 @@ async function _merge({
96769691
);
96779692

96789693
// Defer throwing error until the index lock is relinquished and index is
9679-
// written to filsesystem
9694+
// written to filesystem
96809695
if (tree instanceof MergeConflictError) throw tree
96819696

96829697
if (!message) {

js/isomorphic-git/index.umd.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/isomorphic-git/index.umd.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/isomorphic-git/size_report.html

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)