Skip to content

Commit 4615d54

Browse files
committed
fix: use git worktree with sparse-checkout to completely avoid long filename issues
1 parent caa182f commit 4615d54

File tree

3 files changed

+78
-84
lines changed

3 files changed

+78
-84
lines changed

.github/workflows/daily.yml

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,50 +67,48 @@ jobs:
6767
git config --global user.email chainreactorbot@gmail.com
6868
git config --global user.name chainreactorbot
6969
70-
# Stash any changes in master branch (like today.md)
71-
git stash push -m "Temporary stash for today.md" || true
72-
7370
# Get date variables
7471
year=$(date -d yesterday +'%Y')
7572
month=$(date -d yesterday +'%m')
7673
day=$(date -d yesterday +'%d')
7774
78-
# Move archive directory to temporary location
79-
temp_archive="/tmp/archive_temp_${year}_${month}_${day}"
80-
if [ -d "archive/${year}/${month}/${day}" ]; then
81-
mkdir -p "$temp_archive"
82-
mv "archive/${year}/${month}/${day}" "$temp_archive/"
83-
fi
84-
8575
# Fetch archive branch
86-
git fetch origin archive
87-
88-
# Use sparse-checkout to avoid long filename issues
89-
git config core.sparseCheckout true
90-
echo "archive/${year}/" > .git/info/sparse-checkout
76+
git fetch origin archive:archive 2>/dev/null || echo "Archive branch will be created"
9177
92-
# Checkout archive branch with sparse checkout
78+
# Create a worktree for archive branch
79+
worktree_path="/tmp/archive_worktree_$$"
9380
if git show-ref --verify --quiet refs/heads/archive; then
94-
git checkout -f archive
81+
# Archive branch exists, create worktree from it with sparse-checkout
82+
git worktree add --no-checkout "$worktree_path" archive
83+
cd "$worktree_path"
84+
git sparse-checkout set "archive/${year}/"
85+
git checkout
9586
else
96-
git checkout -b archive origin/archive 2>/dev/null || git checkout --orphan archive
87+
# Create orphan branch
88+
git worktree add --detach "$worktree_path"
89+
cd "$worktree_path"
90+
git checkout --orphan archive
91+
git rm -rf . 2>/dev/null || true
9792
fi
9893
99-
# Move files back
100-
if [ -d "$temp_archive/${day}" ]; then
94+
# Copy new files to worktree
95+
if [ -d "/home/runner/work/picker/picker/archive/${year}/${month}/${day}" ]; then
10196
mkdir -p "archive/${year}/${month}"
102-
mv "$temp_archive/${day}" "archive/${year}/${month}/"
97+
cp -r "/home/runner/work/picker/picker/archive/${year}/${month}/${day}" "archive/${year}/${month}/"
10398
fi
10499
105-
# Add and commit changes
100+
# Commit and push
106101
git add "archive/${year}/${month}/${day}/"
107-
git diff --staged --quiet || git commit -m "每日安全资讯(`date +'%Y-%m-%d'`)"
108-
109-
# Push to archive branch
110-
git push origin archive
102+
if git diff --staged --quiet; then
103+
echo "No changes to commit"
104+
else
105+
git commit -m "每日安全资讯(`date +'%Y-%m-%d'`)"
106+
git push origin archive
107+
fi
111108
112-
# Disable sparse-checkout for next steps
113-
git config core.sparseCheckout false
109+
# Cleanup
110+
cd /home/runner/work/picker/picker
111+
git worktree remove "$worktree_path" --force
114112
115113
- name: Update today.md in master
116114
run: |

.github/workflows/issue.yml

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -84,49 +84,47 @@ jobs:
8484
git config --global user.email chainreactorbot@gmail.com
8585
git config --global user.name chainreactorbot
8686
87-
# Stash any changes in master branch if they exist
88-
git stash push -m "Temporary stash before switching to archive" || true
89-
9087
# Get date variables
9188
year=$(date +'%Y')
9289
month=$(date +'%m')
9390
day=$(date +'%d')
9491
95-
# Move archive directory to temporary location
96-
temp_archive="/tmp/archive_temp_${year}_${month}_${day}"
97-
if [ -d "archive/${year}/${month}/${day}" ]; then
98-
mkdir -p "$temp_archive"
99-
mv "archive/${year}/${month}/${day}" "$temp_archive/"
100-
fi
101-
10292
# Fetch archive branch
103-
git fetch origin archive
104-
105-
# Use sparse-checkout to avoid long filename issues
106-
git config core.sparseCheckout true
107-
echo "archive/${year}/" > .git/info/sparse-checkout
93+
git fetch origin archive:archive 2>/dev/null || echo "Archive branch will be created"
10894
109-
# Checkout archive branch with sparse checkout
95+
# Create a worktree for archive branch
96+
worktree_path="/tmp/archive_worktree_$$"
11097
if git show-ref --verify --quiet refs/heads/archive; then
111-
git checkout -f archive
98+
# Archive branch exists, create worktree from it with sparse-checkout
99+
git worktree add --no-checkout "$worktree_path" archive
100+
cd "$worktree_path"
101+
git sparse-checkout set "archive/${year}/"
102+
git checkout
112103
else
113-
git checkout -b archive origin/archive 2>/dev/null || git checkout --orphan archive
104+
# Create orphan branch
105+
git worktree add --detach "$worktree_path"
106+
cd "$worktree_path"
107+
git checkout --orphan archive
108+
git rm -rf . 2>/dev/null || true
114109
fi
115110
116-
# Move files back
117-
if [ -d "$temp_archive/${day}" ]; then
111+
# Copy new files to worktree
112+
if [ -d "/home/runner/work/picker/picker/archive/${year}/${month}/${day}" ]; then
118113
mkdir -p "archive/${year}/${month}"
119-
mv "$temp_archive/${day}" "archive/${year}/${month}/"
114+
cp -r "/home/runner/work/picker/picker/archive/${year}/${month}/${day}" "archive/${year}/${month}/"
120115
fi
121116
122-
# Add and commit changes
117+
# Commit and push
123118
git add "archive/${year}/${month}/${day}/"
124-
git diff --staged --quiet || git commit -m "添加文章 markdown(Issue #${{ github.event.issue.number }})"
125-
126-
# Push to archive branch
127-
git push origin archive
119+
if git diff --staged --quiet; then
120+
echo "No changes to commit"
121+
else
122+
git commit -m "添加文章 markdown(Issue #${{ github.event.issue.number }})"
123+
git push origin archive
124+
fi
128125
129-
# Disable sparse-checkout for next steps
130-
git config core.sparseCheckout false
126+
# Cleanup
127+
cd /home/runner/work/picker/picker
128+
git worktree remove "$worktree_path" --force
131129
132130

.github/workflows/pick.yml

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -68,50 +68,48 @@ jobs:
6868
git config --global user.email chainreactorbot@gmail.com
6969
git config --global user.name chainreactorbot
7070
71-
# Stash any changes in master branch (like today_pick.md)
72-
git stash push -m "Temporary stash for today_pick.md" || true
73-
7471
# Get date variables
7572
year=$(date -d yesterday +'%Y')
7673
month=$(date -d yesterday +'%m')
7774
day=$(date -d yesterday +'%d')
7875
79-
# Move archive directory to temporary location
80-
temp_archive="/tmp/archive_temp_${year}_${month}_${day}"
81-
if [ -d "archive/${year}/${month}/${day}" ]; then
82-
mkdir -p "$temp_archive"
83-
mv "archive/${year}/${month}/${day}" "$temp_archive/"
84-
fi
85-
8676
# Fetch archive branch
87-
git fetch origin archive
88-
89-
# Use sparse-checkout to avoid long filename issues
90-
git config core.sparseCheckout true
91-
echo "archive/${year}/" > .git/info/sparse-checkout
77+
git fetch origin archive:archive 2>/dev/null || echo "Archive branch will be created"
9278
93-
# Checkout archive branch with sparse checkout
79+
# Create a worktree for archive branch
80+
worktree_path="/tmp/archive_worktree_$$"
9481
if git show-ref --verify --quiet refs/heads/archive; then
95-
git checkout -f archive
82+
# Archive branch exists, create worktree from it with sparse-checkout
83+
git worktree add --no-checkout "$worktree_path" archive
84+
cd "$worktree_path"
85+
git sparse-checkout set "archive/${year}/"
86+
git checkout
9687
else
97-
git checkout -b archive origin/archive 2>/dev/null || git checkout --orphan archive
88+
# Create orphan branch
89+
git worktree add --detach "$worktree_path"
90+
cd "$worktree_path"
91+
git checkout --orphan archive
92+
git rm -rf . 2>/dev/null || true
9893
fi
9994
100-
# Move files back
101-
if [ -d "$temp_archive/${day}" ]; then
95+
# Copy new files to worktree
96+
if [ -d "/home/runner/work/picker/picker/archive/${year}/${month}/${day}" ]; then
10297
mkdir -p "archive/${year}/${month}"
103-
mv "$temp_archive/${day}" "archive/${year}/${month}/"
98+
cp -r "/home/runner/work/picker/picker/archive/${year}/${month}/${day}" "archive/${year}/${month}/"
10499
fi
105100
106-
# Add and commit changes
101+
# Commit and push
107102
git add "archive/${year}/${month}/${day}/"
108-
git diff --staged --quiet || git commit -m "每日精选汇总(`date +'%Y-%m-%d'`)"
109-
110-
# Push to archive branch
111-
git push origin archive
103+
if git diff --staged --quiet; then
104+
echo "No changes to commit"
105+
else
106+
git commit -m "每日精选汇总(`date +'%Y-%m-%d'`)"
107+
git push origin archive
108+
fi
112109
113-
# Disable sparse-checkout for next steps
114-
git config core.sparseCheckout false
110+
# Cleanup
111+
cd /home/runner/work/picker/picker
112+
git worktree remove "$worktree_path" --force
115113
116114
- name: Update today_pick.md in master
117115
run: |

0 commit comments

Comments
 (0)