Stijnus
commited on
Commit
·
d479550
1
Parent(s):
ee67bf1
Update api.update.ts
Browse files- app/routes/api.update.ts +14 -12
app/routes/api.update.ts
CHANGED
@@ -59,7 +59,7 @@ export const action: ActionFunction = async ({ request }) => {
|
|
59 |
let defaultBranch = branch || 'main'; // Make branch mutable
|
60 |
|
61 |
try {
|
62 |
-
await execAsync('git remote get-url
|
63 |
sendProgress({
|
64 |
stage: 'fetch',
|
65 |
message: 'Repository remote verified',
|
@@ -67,7 +67,7 @@ export const action: ActionFunction = async ({ request }) => {
|
|
67 |
});
|
68 |
} catch {
|
69 |
throw new Error(
|
70 |
-
'No
|
71 |
);
|
72 |
}
|
73 |
|
@@ -80,7 +80,7 @@ export const action: ActionFunction = async ({ request }) => {
|
|
80 |
});
|
81 |
|
82 |
try {
|
83 |
-
const { stdout } = await execAsync('git remote show
|
84 |
defaultBranch = stdout.trim() || 'main';
|
85 |
sendProgress({
|
86 |
stage: 'fetch',
|
@@ -114,14 +114,16 @@ export const action: ActionFunction = async ({ request }) => {
|
|
114 |
|
115 |
// Check if remote branch exists
|
116 |
try {
|
117 |
-
await execAsync(`git rev-parse --verify
|
118 |
sendProgress({
|
119 |
stage: 'fetch',
|
120 |
message: 'Remote branch verified',
|
121 |
progress: 60,
|
122 |
});
|
123 |
} catch {
|
124 |
-
throw new Error(
|
|
|
|
|
125 |
}
|
126 |
|
127 |
// Get current commit hash and remote commit hash
|
@@ -132,7 +134,7 @@ export const action: ActionFunction = async ({ request }) => {
|
|
132 |
});
|
133 |
|
134 |
const { stdout: currentCommit } = await execAsync('git rev-parse HEAD');
|
135 |
-
const { stdout: remoteCommit } = await execAsync(`git rev-parse
|
136 |
|
137 |
// If we're on the same commit, no update is available
|
138 |
if (currentCommit.trim() === remoteCommit.trim()) {
|
@@ -183,7 +185,7 @@ export const action: ActionFunction = async ({ request }) => {
|
|
183 |
if (files.length === 0) {
|
184 |
sendProgress({
|
185 |
stage: 'complete',
|
186 |
-
message: `No file changes detected between your version and
|
187 |
progress: 100,
|
188 |
details: {
|
189 |
currentCommit: currentCommit.trim().substring(0, 7),
|
@@ -221,7 +223,7 @@ export const action: ActionFunction = async ({ request }) => {
|
|
221 |
});
|
222 |
} catch (err) {
|
223 |
console.debug('Failed to get changed files:', err);
|
224 |
-
throw new Error(`Failed to compare changes with
|
225 |
}
|
226 |
|
227 |
// Get commit messages between current and remote
|
@@ -250,7 +252,7 @@ export const action: ActionFunction = async ({ request }) => {
|
|
250 |
if (!stats && changedFiles.length === 0) {
|
251 |
sendProgress({
|
252 |
stage: 'complete',
|
253 |
-
message: `No changes detected between your version and
|
254 |
progress: 100,
|
255 |
});
|
256 |
return;
|
@@ -259,7 +261,7 @@ export const action: ActionFunction = async ({ request }) => {
|
|
259 |
// We have changes, send the details
|
260 |
sendProgress({
|
261 |
stage: 'fetch',
|
262 |
-
message: `Changes detected on
|
263 |
progress: 100,
|
264 |
details: {
|
265 |
changedFiles,
|
@@ -275,11 +277,11 @@ export const action: ActionFunction = async ({ request }) => {
|
|
275 |
// Pull stage
|
276 |
sendProgress({
|
277 |
stage: 'pull',
|
278 |
-
message: `Pulling changes from
|
279 |
progress: 0,
|
280 |
});
|
281 |
|
282 |
-
await execAsync(`git pull
|
283 |
|
284 |
sendProgress({
|
285 |
stage: 'pull',
|
|
|
59 |
let defaultBranch = branch || 'main'; // Make branch mutable
|
60 |
|
61 |
try {
|
62 |
+
await execAsync('git remote get-url upstream');
|
63 |
sendProgress({
|
64 |
stage: 'fetch',
|
65 |
message: 'Repository remote verified',
|
|
|
67 |
});
|
68 |
} catch {
|
69 |
throw new Error(
|
70 |
+
'No upstream repository found. Please set up the upstream repository first by running:\ngit remote add upstream https://github.com/stackblitz-labs/bolt.diy.git',
|
71 |
);
|
72 |
}
|
73 |
|
|
|
80 |
});
|
81 |
|
82 |
try {
|
83 |
+
const { stdout } = await execAsync('git remote show upstream | grep "HEAD branch" | cut -d" " -f5');
|
84 |
defaultBranch = stdout.trim() || 'main';
|
85 |
sendProgress({
|
86 |
stage: 'fetch',
|
|
|
114 |
|
115 |
// Check if remote branch exists
|
116 |
try {
|
117 |
+
await execAsync(`git rev-parse --verify upstream/${defaultBranch}`);
|
118 |
sendProgress({
|
119 |
stage: 'fetch',
|
120 |
message: 'Remote branch verified',
|
121 |
progress: 60,
|
122 |
});
|
123 |
} catch {
|
124 |
+
throw new Error(
|
125 |
+
`Remote branch 'upstream/${defaultBranch}' not found. Please ensure the upstream repository is properly configured.`,
|
126 |
+
);
|
127 |
}
|
128 |
|
129 |
// Get current commit hash and remote commit hash
|
|
|
134 |
});
|
135 |
|
136 |
const { stdout: currentCommit } = await execAsync('git rev-parse HEAD');
|
137 |
+
const { stdout: remoteCommit } = await execAsync(`git rev-parse upstream/${defaultBranch}`);
|
138 |
|
139 |
// If we're on the same commit, no update is available
|
140 |
if (currentCommit.trim() === remoteCommit.trim()) {
|
|
|
185 |
if (files.length === 0) {
|
186 |
sendProgress({
|
187 |
stage: 'complete',
|
188 |
+
message: `No file changes detected between your version and upstream/${defaultBranch}. You might be on a different branch.`,
|
189 |
progress: 100,
|
190 |
details: {
|
191 |
currentCommit: currentCommit.trim().substring(0, 7),
|
|
|
223 |
});
|
224 |
} catch (err) {
|
225 |
console.debug('Failed to get changed files:', err);
|
226 |
+
throw new Error(`Failed to compare changes with upstream/${defaultBranch}. Are you on the correct branch?`);
|
227 |
}
|
228 |
|
229 |
// Get commit messages between current and remote
|
|
|
252 |
if (!stats && changedFiles.length === 0) {
|
253 |
sendProgress({
|
254 |
stage: 'complete',
|
255 |
+
message: `No changes detected between your version and upstream/${defaultBranch}. This might be unexpected - please check your git status.`,
|
256 |
progress: 100,
|
257 |
});
|
258 |
return;
|
|
|
261 |
// We have changes, send the details
|
262 |
sendProgress({
|
263 |
stage: 'fetch',
|
264 |
+
message: `Changes detected on upstream/${defaultBranch}`,
|
265 |
progress: 100,
|
266 |
details: {
|
267 |
changedFiles,
|
|
|
277 |
// Pull stage
|
278 |
sendProgress({
|
279 |
stage: 'pull',
|
280 |
+
message: `Pulling changes from upstream/${defaultBranch}...`,
|
281 |
progress: 0,
|
282 |
});
|
283 |
|
284 |
+
await execAsync(`git pull upstream ${defaultBranch}`);
|
285 |
|
286 |
sendProgress({
|
287 |
stage: 'pull',
|