@@ -19,7 +19,10 @@ export async function runGitCommand(repoPath: string, cmd: string): Promise<stri
1919}
2020
2121export async function getCommits ( repoPath : string , branch : string ) : Promise < Commit [ ] > {
22- const log = await runGitCommand ( repoPath , `log ${ branch } --reverse --pretty=format:"%H@|@%ct@|@%aN@|@%aE@|@%s@|@%ad"` ) ;
22+ const log = await runGitCommand (
23+ repoPath ,
24+ `log ${ branch } --reverse --pretty=format:"%H@|@%ct@|@%aN@|@%aE@|@%s@|@%ad"`
25+ ) ;
2326 const res = log
2427 . split ( '\n' )
2528 . filter ( Boolean )
@@ -64,12 +67,13 @@ export async function getDiffForCommit(repoPath: string, commitHash: string): Pr
6467 const diff = await runGitCommand ( repoPath , `show --name-status ${ commitHash } ` ) ;
6568 return diff
6669 . split ( '\n' )
67- . filter ( x => x . match ( / ^ [ A M D ] \t / ) )
70+ . filter ( x => x . match ( / ^ ( A | M | D | R \d \d \d ) \t / ) )
6871 . map ( x => {
69- const [ action , file ] = x . split ( '\t' ) ;
72+ const [ action , file , newFile ] = x . split ( '\t' ) ;
7073 return {
71- action : action as FileAction ,
74+ action : action . substring ( 0 , 1 ) as FileAction ,
7275 file,
76+ newFile,
7377 } ;
7478 } ) ;
7579}
@@ -82,6 +86,19 @@ export async function copyRepoFile(srcRepo: string, destRepo: string, file: stri
8286 console . log ( `Copied ${ file } from ${ srcRepo } to ${ destRepo } ` ) ;
8387}
8488
89+ export async function renameRepoFile ( srcRepo : string , destRepo : string , srcFile : string , dstFile : string ) {
90+ const oldTargetFile = path . join ( destRepo , srcFile ) ;
91+ if ( await fs . exists ( oldTargetFile ) ) {
92+ await fs . unlink ( oldTargetFile ) ;
93+ }
94+ const newSourceFile = path . join ( srcRepo , dstFile ) ;
95+ const newTargetFile = path . join ( destRepo , dstFile ) ;
96+
97+ await fs . ensureDir ( path . dirname ( newTargetFile ) ) ;
98+ await fs . copyFile ( newSourceFile , newTargetFile ) ;
99+ console . log ( `Renamed ${ srcFile } to ${ dstFile } from ${ srcRepo } to ${ destRepo } ` ) ;
100+ }
101+
85102export async function removeRepoFile ( repoPath : string , file : string ) {
86103 const filePath = path . join ( repoPath , file ) ;
87104 if ( await fs . exists ( filePath ) ) {
0 commit comments