MCPcopy
hub / github.com/amplication/amplication / commit

Method commit

libs/util/git/src/providers/git-cli.ts:111–152  ·  view source on GitHub ↗
(
    branchName: string,
    message: string,
    files: UpdateFile[]
  )

Source from the content-addressed store, hash-verified

109 }
110
111 async commit(
112 branchName: string,
113 message: string,
114 files: UpdateFile[]
115 ): Promise<string> {
116 await this.checkout(branchName);
117
118 await Promise.all(
119 files.map(async (file) => {
120 const filePath = join(this.options.repositoryDir, file.path);
121 const fileParentDir = dirname(filePath);
122
123 if (file.deleted) {
124 //remove the file or silently ignore if it does not exist
125 await fs.remove(filePath);
126 return filePath;
127 }
128
129 if (!existsSync(filePath)) {
130 await mkdir(fileParentDir, { recursive: true });
131 await writeFile(filePath, file.content ?? "");
132 return filePath;
133 } else if (!file.skipIfExists) {
134 await mkdir(fileParentDir, { recursive: true });
135 await writeFile(filePath, file.content ?? "");
136 return filePath;
137 }
138 })
139 );
140
141 await this.add(["."]);
142
143 const status = await this.git.status();
144 if (status.staged.length + status.renamed.length > 0) {
145 const { commit: commitSha } = await this.git.commit(message);
146 await this.push();
147 return commitSha;
148 } else {
149 this.logger.warn(`Trying to commit empty changeset`, { status });
150 }
151 return "";
152 }
153
154 /**
155 * Clones the repository if not already cloned and sets the working directory to the repository directory.

Callers 4

createInitialCommitMethod · 0.45
applyPatchMethod · 0.45
git-cli.spec.tsFile · 0.45

Calls 6

checkoutMethod · 0.95
addMethod · 0.95
pushMethod · 0.95
mapMethod · 0.80
statusMethod · 0.80
warnMethod · 0.65

Tested by

no test coverage detected