11import { promises as fs } from "fs" ;
22import { relative , resolve } from "path" ;
33import git from "isomorphic-git" ;
4+ import { commitFilesFromBase64 } from "./core.ts" ;
45import type {
56 CommitChangesFromRepoArgs ,
6- CommitFilesFromBuffersArgs ,
7+ CommitFilesFromBase64Args ,
78 CommitFilesResult ,
89} from "./interface.ts" ;
9- import { commitFilesFromBuffers } from "./node.ts" ;
1010
1111/**
1212 * @see https://isomorphic-git.org/docs/en/walk#walkerentry-mode
@@ -23,7 +23,6 @@ export const commitChangesFromRepo = async ({
2323 cwd : workingDirectory ,
2424 recursivelyFindRoot = true ,
2525 filterFiles,
26- log,
2726 ...otherArgs
2827} : CommitChangesFromRepoArgs ) : Promise < CommitFilesResult > => {
2928 const ref = base ?. commit ?? "HEAD" ;
@@ -44,6 +43,27 @@ export const commitChangesFromRepo = async ({
4443 throw new Error ( `Could not determine oid for ${ ref } ` ) ;
4544 }
4645
46+ return await commitFilesFromBase64 ( {
47+ ...otherArgs ,
48+ fileChanges : await getFileChanges (
49+ workingDirectory ,
50+ repoRoot ,
51+ oid ,
52+ filterFiles ,
53+ ) ,
54+ base : {
55+ commit : oid ,
56+ } ,
57+ } ) ;
58+ } ;
59+
60+ // Exported for testing only
61+ export async function getFileChanges (
62+ cwd : string ,
63+ repoRoot : string ,
64+ ref : string ,
65+ filterFiles ?: CommitChangesFromRepoArgs [ "filterFiles" ] ,
66+ ) : Promise < CommitFilesFromBase64Args [ "fileChanges" ] > {
4767 /**
4868 * The directory to add files from. This is relative to the repository
4969 * root, and is used to filter files.
@@ -52,13 +72,10 @@ export const commitChangesFromRepo = async ({
5272 cwd === repoRoot ? null : relative ( repoRoot , cwd ) + "/" ;
5373
5474 // Determine changed files
55- const trees = [ git . TREE ( { ref : oid } ) , git . WORKDIR ( ) ] ;
56- const additions : CommitFilesFromBuffersArgs [ "fileChanges" ] [ "additions" ] = [ ] ;
57- const deletions : CommitFilesFromBuffersArgs [ "fileChanges" ] [ "deletions" ] = [ ] ;
58- const fileChanges = {
59- additions,
60- deletions,
61- } ;
75+ const trees = [ git . TREE ( { ref } ) , git . WORKDIR ( ) ] ;
76+ const additions : CommitFilesFromBase64Args [ "fileChanges" ] [ "additions" ] = [ ] ;
77+ const deletions : CommitFilesFromBase64Args [ "fileChanges" ] [ "deletions" ] = [ ] ;
78+
6279 await git . walk ( {
6380 fs,
6481 dir : repoRoot ,
@@ -115,7 +132,7 @@ export const commitChangesFromRepo = async ({
115132 }
116133 if ( ! workdir ) {
117134 // File was deleted
118- deletions . push ( filepath ) ;
135+ deletions . push ( { path : filepath } ) ;
119136 return null ;
120137 } else {
121138 // File was added / updated
@@ -125,19 +142,12 @@ export const commitChangesFromRepo = async ({
125142 }
126143 additions . push ( {
127144 path : filepath ,
128- contents : Buffer . from ( arr ) ,
145+ contents : Buffer . from ( arr ) . toString ( "base64" ) ,
129146 } ) ;
130147 }
131148 return true ;
132149 } ,
133150 } ) ;
134151
135- return commitFilesFromBuffers ( {
136- ...otherArgs ,
137- fileChanges,
138- log,
139- base : {
140- commit : oid ,
141- } ,
142- } ) ;
143- } ;
152+ return { additions, deletions } ;
153+ }
0 commit comments