-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpush-content.cmd
More file actions
117 lines (99 loc) · 2.76 KB
/
push-content.cmd
File metadata and controls
117 lines (99 loc) · 2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
@echo off
setlocal EnableExtensions EnableDelayedExpansion
cd /d "%~dp0"
set "SCRIPT_NAME=%~nx0"
set "TARGET_CONTENT=data\content.json"
if not exist "%TARGET_CONTENT%" (
echo [ERROR] File not found: %TARGET_CONTENT%
echo Put your content file at data\content.json and run again.
pause
exit /b 1
)
if not exist ".git" (
echo [ERROR] This folder is not a Git repository yet.
echo.
echo Quick setup - run once:
echo git init
echo git remote add origin YOUR_REPO_URL
echo git branch -M main
echo.
echo After that, run this file again.
pause
exit /b 1
)
set "GIT_USER_NAME="
set "GIT_USER_EMAIL="
for /f "delims=" %%N in ('git config --get user.name 2^>nul') do set "GIT_USER_NAME=%%N"
for /f "delims=" %%E in ('git config --get user.email 2^>nul') do set "GIT_USER_EMAIL=%%E"
if not defined GIT_USER_NAME (
echo.
set /p GIT_USER_NAME=Enter Git user.name for this repo:
)
if not defined GIT_USER_EMAIL (
set /p GIT_USER_EMAIL=Enter Git user.email for this repo:
)
if not defined GIT_USER_NAME (
echo [ERROR] user.name is empty.
pause
exit /b 1
)
if not defined GIT_USER_EMAIL (
echo [ERROR] user.email is empty.
pause
exit /b 1
)
git config user.name "!GIT_USER_NAME!"
git config user.email "!GIT_USER_EMAIL!"
if exist ".git\info\exclude" (
findstr /x /c:"%SCRIPT_NAME%" ".git\info\exclude" >nul 2>nul
if errorlevel 1 (
>> ".git\info\exclude" echo %SCRIPT_NAME%
)
)
git add -- "%TARGET_CONTENT%"
if errorlevel 1 (
echo [ERROR] git add failed.
pause
exit /b 1
)
git diff --cached --quiet -- "%TARGET_CONTENT%"
if not errorlevel 1 (
echo [INFO] No changes in data\content.json to commit.
pause
exit /b 0
)
for /f %%B in ('git branch --show-current') do set "BRANCH=%%B"
if not defined BRANCH (
set "BRANCH=main"
)
for /f %%D in ('powershell -NoProfile -Command "Get-Date -Format ''yyyy-MM-dd HH:mm:ss''"') do set "STAMP=%%D"
set "MSG=content update !STAMP!"
git commit -m "!MSG!" -- "%TARGET_CONTENT%"
if errorlevel 1 (
echo [ERROR] git commit failed.
pause
exit /b 1
)
git push -u origin "!BRANCH!"
if errorlevel 1 (
echo [WARN] Initial push failed. Trying to sync with origin and retry...
git pull --rebase --autostash origin "!BRANCH!"
if errorlevel 1 (
echo [ERROR] Could not rebase with origin/!BRANCH!.
echo Resolve manually, then run this file again:
echo git pull --rebase --autostash origin !BRANCH!
echo git push -u origin !BRANCH!
pause
exit /b 1
)
git push -u origin "!BRANCH!"
if errorlevel 1 (
echo [ERROR] git push failed after rebase.
echo Check remote and auth: git remote -v
pause
exit /b 1
)
)
echo [DONE] data\content.json pushed successfully.
pause
exit /b 0