Skip to content

Commit

Permalink
git:tag 总是以远端 TAG 解决冲突 #642
Browse files Browse the repository at this point in the history
  • Loading branch information
Soltus committed Apr 21, 2024
1 parent b8f735c commit c377815
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sillot",
"version": "0.30.1400",
"version": "0.30.1500",
"syv": "3.0.11",
"sypv": "[]",
"description": "Build Your Eternal Digital Garden",
Expand Down
35 changes: 33 additions & 2 deletions app/pushTagsByDate.cjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,42 @@
const { execSync } = require('node:child_process');
const { promisify } = require('node:util');
const exec = promisify(require('node:child_process').exec);

async function fetchTagsWithConflictResolution(localTags) {
try {
// Fetch the tags from the remote repository
await exec('git fetch --tags');
} catch (error) {
if (error.message.includes('would clobber existing tag')) {
console.error('Tag conflict detected. Deleting local tags and retrying...');

// Delete local tags that conflict with remote tags
for (const tag of localTags) {
try {
await exec(`git tag -d ${tag}`);
} catch (deleteError) {
console.error(`Failed to delete local tag ${tag}:`, deleteError.message);
}
}

// Retry fetching tags after deleting local tags
try {
await exec('git fetch --tags');
console.log('Successfully fetched tags after resolving conflicts.');
} catch (retryError) {
console.error('Failed to fetch tags even after resolving conflicts:', retryError.message);
}
} else {
// Some other error occurred
console.error('Failed to fetch tags:', error.message);
}
}
}

// Get the list of tags sorted by commit date
const localTags = execSync('git tag').toString().trim().split('\n');

// Fetch the tags from the remote repository
execSync('git fetch --tags');
fetchTagsWithConflictResolution(localTags).catch(console.error);

// Get the list of tags from the remote repository
const remoteTags = execSync('git ls-remote --tags origin').toString().trim().split('\n')
Expand Down

0 comments on commit c377815

Please sign in to comment.