Skip to content

Commit d73678a

Browse files
committed
Add configLoz method to Git class
Add configLoz method to Git class for configuring loz settings based on name and value parameters. This method allows setting and retrieving configuration values for loz. Generated by gpt-3.5-turbo
1 parent a23188e commit d73678a

File tree

3 files changed

+52
-6
lines changed

3 files changed

+52
-6
lines changed

src/git/index.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,30 @@ export class Git {
8888
);
8989
});
9090
}
91+
92+
public configLoz(name: string, value?: string): Promise<string> {
93+
return new Promise((resolve, reject) => {
94+
const gitCommand =
95+
value === undefined
96+
? `git config loz.${name}`
97+
: `git config loz.${name} ${value}`;
98+
99+
exec(
100+
gitCommand,
101+
(error: Error | null, stdout: string, stderr: string) => {
102+
if (error) {
103+
console.error(`Error: ${error.message}`);
104+
reject(error.message);
105+
return;
106+
}
107+
if (stderr) {
108+
console.error(`Stderr: ${stderr}`);
109+
reject(stderr);
110+
return;
111+
}
112+
resolve(stdout);
113+
},
114+
);
115+
});
116+
}
91117
}

src/index.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,11 @@ async function handleCodeDiffFromPipe(): Promise<void> {
8686
return;
8787
}
8888

89-
process.stdout.write(
90-
completion.content + "\n\nGenerated by " + completion.model + "\n",
91-
);
89+
if (loz.attribution) {
90+
process.stdout.write(
91+
completion.content + "\n\nGenerated by " + completion.model + "\n",
92+
);
93+
}
9294
});
9395
}
9496

src/loz.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export class Loz {
3737
configPath: string;
3838
config: Config = new Config();
3939
git: Git = new Git();
40+
attribution: boolean = false;
4041

4142
constructor() {
4243
this.defaultSettings = {
@@ -60,6 +61,18 @@ export class Loz {
6061
if (!fs.existsSync(LOG_DEV_PATH)) {
6162
fs.mkdirSync(LOG_DEV_PATH);
6263
}
64+
65+
const attributionValue = await this.git.configLoz("attribution");
66+
if (attributionValue === "") {
67+
this.git.configLoz("attribution", "false");
68+
this.attribution = false;
69+
} else {
70+
if (attributionValue.trimEnd() === "true") {
71+
this.attribution = true;
72+
} else {
73+
this.attribution = false;
74+
}
75+
}
6376
}
6477

6578
await this.initLLMfromConfig();
@@ -149,9 +162,14 @@ export class Loz {
149162
}
150163

151164
try {
152-
await this.git.commit(
153-
complete.content + "\n\nGenerated by " + complete.model,
154-
);
165+
if (this.attribution) {
166+
await this.git.commit(
167+
complete.content + "\n\nGenerated by " + complete.model,
168+
);
169+
} else {
170+
await this.git.commit(complete.content);
171+
}
172+
155173
const commitHEAD = await this.git.showHEAD();
156174
console.log("\n# Generated commit message: \n");
157175
console.log(commitHEAD);

0 commit comments

Comments
 (0)