Skip to content

Commit c80dc60

Browse files
authored
diff: handle file rename without 100% similarity (#54)
1 parent a6a91d8 commit c80dc60

File tree

2 files changed

+90
-2
lines changed

2 files changed

+90
-2
lines changed

diff.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,15 @@ checkType:
306306
file.Index = shas[1]
307307
}
308308
break checkType
309-
case strings.HasPrefix(line, "similarity index 100%"):
309+
case strings.HasPrefix(line, "similarity index "):
310310
file.Type = DiffFileRename
311311
file.oldName = a
312312
file.Name = b
313-
break checkType
313+
314+
// No need to look for index if it's a pure rename
315+
if strings.HasSuffix(line, "100%") {
316+
break checkType
317+
}
314318
case strings.HasPrefix(line, "old mode"):
315319
break checkType
316320
}

diff_test.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,90 @@ index b6fc4c620b67d95f953a5c1c1230aaab5db5a1b0..ab80bda5dd90d8b42be25ac2c7a071b7
479479
isIncomplete: false,
480480
},
481481
},
482+
{
483+
input: `diff --git a/src/app/tabs/teacher/teacher.module.ts b/src/app/tabs/friends/friends.module.ts
484+
similarity index 69%
485+
rename from src/app/tabs/teacher/teacher.module.ts
486+
rename to src/app/tabs/friends/friends.module.ts
487+
index ce53c7e..56a156b 100644
488+
--- a/src/app/tabs/teacher/teacher.module.ts
489+
+++ b/src/app/tabs/friends/friends.module.ts
490+
@@ -2,9 +2,9 @@ import { IonicModule } from '@ionic/angular'
491+
import { RouterModule } from '@angular/router'
492+
import { NgModule } from '@angular/core'
493+
import { CommonModule } from '@angular/common'
494+
-import { FormsModule } from '@angular/forms'
495+
-import { TeacherPage } from './teacher.page'
496+
import { ComponentsModule } from '@components/components.module'
497+
+import { FormsModule } from '@angular/forms'
498+
+import { FriendsPage } from './friends.page'`,
499+
expDiff: &Diff{
500+
Files: []*DiffFile{
501+
{
502+
Name: "src/app/tabs/friends/friends.module.ts",
503+
Type: DiffFileRename,
504+
Index: "56a156b",
505+
Sections: []*DiffSection{
506+
{
507+
Lines: []*DiffLine{
508+
{
509+
Type: DiffLineSection,
510+
Content: "@@ -2,9 +2,9 @@ import { IonicModule } from '@ionic/angular'",
511+
}, {
512+
Type: DiffLinePlain,
513+
Content: ` import { RouterModule } from '@angular/router'`,
514+
LeftLine: 2,
515+
RightLine: 2,
516+
}, {
517+
Type: DiffLinePlain,
518+
Content: ` import { NgModule } from '@angular/core'`,
519+
LeftLine: 3,
520+
RightLine: 3,
521+
}, {
522+
Type: DiffLinePlain,
523+
Content: ` import { CommonModule } from '@angular/common'`,
524+
LeftLine: 4,
525+
RightLine: 4,
526+
}, {
527+
Type: DiffLineDelete,
528+
Content: `-import { FormsModule } from '@angular/forms'`,
529+
LeftLine: 5,
530+
RightLine: 0,
531+
}, {
532+
Type: DiffLineDelete,
533+
Content: `-import { TeacherPage } from './teacher.page'`,
534+
LeftLine: 6,
535+
RightLine: 0,
536+
}, {
537+
Type: DiffLinePlain,
538+
Content: ` import { ComponentsModule } from '@components/components.module'`,
539+
LeftLine: 7,
540+
RightLine: 5,
541+
}, {
542+
Type: DiffLineAdd,
543+
Content: `+import { FormsModule } from '@angular/forms'`,
544+
LeftLine: 0,
545+
RightLine: 6,
546+
}, {
547+
Type: DiffLineAdd,
548+
Content: `+import { FriendsPage } from './friends.page'`,
549+
LeftLine: 0,
550+
RightLine: 7,
551+
},
552+
},
553+
numAdditions: 2,
554+
numDeletions: 2,
555+
},
556+
},
557+
numAdditions: 2,
558+
numDeletions: 2,
559+
oldName: "src/app/tabs/teacher/teacher.module.ts",
560+
},
561+
},
562+
totalAdditions: 2,
563+
totalDeletions: 2,
564+
},
565+
},
482566
{
483567
input: `diff --git a/.travis.yml b/.travis.yml
484568
index 335db7ea..51d7543e 100644

0 commit comments

Comments
 (0)