gitxelectron 1.3.3 → 1.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/out/main/index.js CHANGED
@@ -1038,6 +1038,14 @@ async function pullFromRemote(sessionId, remote, branch) {
1038
1038
  if (!targetBranch) {
1039
1039
  const status = await git.status();
1040
1040
  targetBranch = status.current || "main";
1041
+ if (targetBranch.includes("(no") || targetBranch === "HEAD") {
1042
+ try {
1043
+ const remoteHead = await git.raw(["rev-parse", "--abbrev-ref", `${targetRemote}/HEAD`]);
1044
+ targetBranch = remoteHead.trim().replace(`${targetRemote}/`, "");
1045
+ } catch {
1046
+ targetBranch = "main";
1047
+ }
1048
+ }
1041
1049
  }
1042
1050
  const authUrl = remoteObj.refs?.fetch ? injectAuthToken(sessionId, remoteObj.refs.fetch) : targetRemote;
1043
1051
  let didStash = false;
@@ -1244,7 +1252,25 @@ async function getBranches(sessionId) {
1244
1252
  }
1245
1253
  async function checkoutBranch(sessionId, branch) {
1246
1254
  const { git } = getGitSession(sessionId);
1247
- return await git.checkout(branch);
1255
+ let didStash = false;
1256
+ try {
1257
+ const status = await git.status();
1258
+ if (!status.isClean()) {
1259
+ await git.raw(["stash", "push", "-u", "-m", "gitquickpush-autostash-before-checkout"]);
1260
+ didStash = true;
1261
+ }
1262
+ } catch (err) {
1263
+ console.warn("Stash check before checkout warning:", err);
1264
+ }
1265
+ const res = await git.checkout(branch);
1266
+ if (didStash) {
1267
+ try {
1268
+ await git.raw(["stash", "pop"]);
1269
+ } catch (popErr) {
1270
+ console.warn("Auto-stash pop after checkout had merge notice:", popErr?.message);
1271
+ }
1272
+ }
1273
+ return res;
1248
1274
  }
1249
1275
  async function createBranch(sessionId, branch, baseBranch) {
1250
1276
  const { git } = getGitSession(sessionId);
@@ -1779,6 +1805,20 @@ async function removeGitLock(sessionId) {
1779
1805
  return false;
1780
1806
  }
1781
1807
  }
1808
+ async function masterPush(sessionId, remote, branch) {
1809
+ const { git } = getGitSession(sessionId);
1810
+ const remotes = await getRemotes(sessionId);
1811
+ const remoteObj = (remote ? remotes.find((r) => r.name === remote) : null) || remotes[0];
1812
+ if (!remoteObj) throw new Error("No remote repository configured.");
1813
+ const targetRemote = remoteObj.name;
1814
+ const authUrl = remoteObj.refs?.push ? injectAuthToken(sessionId, remoteObj.refs.push) : targetRemote;
1815
+ await git.add(".");
1816
+ try {
1817
+ await git.commit("Master Override Push", ["--no-verify"]);
1818
+ } catch (e) {
1819
+ }
1820
+ return await git.push(authUrl, branch, ["--force"]);
1821
+ }
1782
1822
  const SYSTEM_PROMPT = `You are an autonomous Git Healer Agent for the "GitElectron" app.
1783
1823
  The user has encountered a Git error during a push, pull, or merge operation and you are executing as a background process to silently fix it.
1784
1824
  You will receive the Git Status and the Raw Error Message.
@@ -1880,8 +1920,40 @@ ${errorMsg}
1880
1920
  lastError = e;
1881
1921
  }
1882
1922
  }
1923
+ console.warn("[AI Service] Falling back to local heuristic analysis...");
1924
+ const lowerError = errorMsg.toLowerCase();
1925
+ if (lowerError.includes("fetch first") || lowerError.includes("non-fast-forward") || lowerError.includes("updates were rejected") || lowerError.includes("remote contains work")) {
1926
+ return {
1927
+ explanation: "Diverged branch detected. Pulling remote changes to reconcile...",
1928
+ commandsToRun: ["git pull --no-edit"]
1929
+ };
1930
+ }
1931
+ if (lowerError.includes("merge conflict") || lowerError.includes("conflict") || lowerError.includes("automatic merge failed")) {
1932
+ return {
1933
+ explanation: "Merge conflict detected. Forcing resolution by keeping local changes...",
1934
+ commandsToRun: ["git merge --abort", "git pull -X ours --no-edit", "git add .", 'git commit -m "Auto-resolve merge conflict"']
1935
+ };
1936
+ }
1937
+ if (lowerError.includes("unmerged files") || lowerError.includes("you have unmerged paths")) {
1938
+ return {
1939
+ explanation: "Unmerged paths detected. Committing current state to proceed...",
1940
+ commandsToRun: ["git add .", 'git commit -m "Auto-resolve unmerged paths"']
1941
+ };
1942
+ }
1943
+ if (lowerError.includes("please tell me who you are")) {
1944
+ return {
1945
+ explanation: "Git identity not set. Setting temporary identity...",
1946
+ commandsToRun: ['git config user.email "gitelectron@example.com"', 'git config user.name "Git Electron"']
1947
+ };
1948
+ }
1949
+ if (lowerError.includes("would be overwritten by merge") || lowerError.includes("local changes to the following files would be overwritten")) {
1950
+ return {
1951
+ explanation: "Local changes would be overwritten. Stashing, pulling, and popping...",
1952
+ commandsToRun: ["git stash", "git pull --no-edit", "git stash pop", "git add .", 'git commit -m "Auto-resolved stashed changes"']
1953
+ };
1954
+ }
1883
1955
  throw new Error(
1884
- `AI Analysis failed after trying all provided keys. Last error: ${lastError?.message}`
1956
+ `AI Analysis failed after trying all provided keys and no local heuristics matched. Last error: ${lastError?.message || "Unknown"}`
1885
1957
  );
1886
1958
  }
1887
1959
  const AUTO_SYNC_SYSTEM_PROMPT = `You are an autonomous Git Healer Agent for the "GitQuickPush" app.
@@ -2482,6 +2554,9 @@ electron.app.whenReady().then(async () => {
2482
2554
  electron.ipcMain.handle("check-remote-updates", async (event) => {
2483
2555
  return await checkRemoteUpdates(event.sender.id);
2484
2556
  });
2557
+ electron.ipcMain.handle("master-push", async (event, remote, branch) => {
2558
+ return await masterPush(event.sender.id, remote, branch);
2559
+ });
2485
2560
  electron.ipcMain.handle("reset-to-remote", async (event, remote, branch) => {
2486
2561
  return await resetToRemote(event.sender.id, remote, branch);
2487
2562
  });
@@ -20,6 +20,7 @@ const api = {
20
20
  unstageFiles: (files) => electron.ipcRenderer.invoke("unstage-files", files),
21
21
  commitChanges: (message) => electron.ipcRenderer.invoke("commit-changes", message),
22
22
  pushToRemote: (remote, branch) => electron.ipcRenderer.invoke("push-to-remote", remote, branch),
23
+ masterPush: (remote, branch) => electron.ipcRenderer.invoke("master-push", remote, branch),
23
24
  pullFromRemote: (remote, branch) => electron.ipcRenderer.invoke("pull-from-remote", remote, branch),
24
25
  checkRemoteUpdates: () => electron.ipcRenderer.invoke("check-remote-updates"),
25
26
  resetToRemote: (remote, branch) => electron.ipcRenderer.invoke("reset-to-remote", remote, branch),