Repository navigation
Expand file tree
/
Copy pathpublish_github.bat
More file actions
111 lines (92 loc) · 2.66 KB
/
Copy pathpublish_github.bat
File metadata and controls
111 lines (92 loc) · 2.66 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
@echo off
setlocal EnableExtensions
cd /d "%~dp0"
echo.
echo StemFlow - publish project to GitHub
echo.
where git >nul 2>nul
if errorlevel 1 (
echo [ERROR] Git was not found.
echo Install Git for Windows: https://git-scm.com/download/win
goto :failed
)
if not exist ".git" (
echo [1/5] Creating a local Git repository...
git init
if errorlevel 1 goto :failed
)
git branch -M main
if errorlevel 1 goto :failed
:check_user
set "GIT_USER="
for /f "delims=" %%N in ('git config user.name 2^>nul') do set "GIT_USER=%%N"
if defined GIT_USER goto :check_email
set /p "GIT_USER=Your name for Git commits: "
if not defined GIT_USER goto :cancelled
git config user.name "%GIT_USER%"
if errorlevel 1 goto :failed
:check_email
set "GIT_EMAIL="
for /f "delims=" %%E in ('git config user.email 2^>nul') do set "GIT_EMAIL=%%E"
if defined GIT_EMAIL goto :check_remote
set /p "GIT_EMAIL=Your email for Git commits: "
if not defined GIT_EMAIL goto :cancelled
git config user.email "%GIT_EMAIL%"
if errorlevel 1 goto :failed
:check_remote
git remote get-url origin >nul 2>nul
if not errorlevel 1 goto :check_files
echo.
echo Create an empty repository at https://github.com/new
echo Do not add a README, .gitignore, or license on the website.
echo.
set "REPO_URL=%~1"
if defined REPO_URL goto :add_remote
set /p "REPO_URL=Paste the HTTPS or SSH repository URL: "
if not defined REPO_URL goto :cancelled
:add_remote
git remote add origin "%REPO_URL%"
if errorlevel 1 goto :failed
:check_files
echo [2/5] Checking files...
git status --short
echo [3/5] Preparing commit...
git add -A
if errorlevel 1 goto :failed
git diff --cached --quiet
if not errorlevel 1 goto :no_changes
set "COMMIT_MESSAGE=%STEMFLOW_COMMIT_MESSAGE%"
if defined COMMIT_MESSAGE goto :create_commit
set /p "COMMIT_MESSAGE=Commit message [Update StemFlow]: "
if not defined COMMIT_MESSAGE set "COMMIT_MESSAGE=Update StemFlow"
:create_commit
git commit -m "%COMMIT_MESSAGE%"
if errorlevel 1 goto :failed
goto :push
:no_changes
echo There are no new changes to commit.
:push
echo [4/5] Pushing branch main...
git push -u origin main
if errorlevel 1 goto :auth_failed
echo [5/5] Done.
for /f "delims=" %%R in ('git remote get-url origin') do echo Repository: %%R
echo.
if not defined STEMFLOW_NO_PAUSE pause
exit /b 0
:auth_failed
echo.
echo [ERROR] GitHub rejected the push.
echo Sign in through the Git Credential Manager window and run this file again.
echo If the remote repository already contains commits, use an empty repository.
goto :failed
:cancelled
echo.
echo Publication cancelled.
if not defined STEMFLOW_NO_PAUSE pause
exit /b 2
:failed
echo.
echo Publication was not completed.
if not defined STEMFLOW_NO_PAUSE pause
exit /b 1