Пакетный скрипт, который автоматически остановит sh мою работу из текущей рабочей ветви и вытащит, pu sh в конкретную c ветку и создаст новую ветку - PullRequest
1 голос
/ 17 апреля 2020
@echo off

set working_dir="D:\Projects\NestJsApiProject"
set /P stash_name= Enter stash name: 
set /P branch_name= Enter new branch name: 
set /P commit_des= Enter commit description: 
set /P isFeature= Is it a feature?Y/N: 
set branch_type= features/
if %isFeature%==N (
    set branch_type= bugs/
)
echo %branch_type%
echo %stash_name%
echo %branch_name%
set /P areYouSure= You are going to create a branch named "%branch_type%%branch_name%", are u sure?Y/N:
if %areYouSure%==Y ( 
    cd /D %working_dir%
    git stash save %stash_name%
    git checkout pre-dev
    git pull origin pre-dev
    git stash pop stash@{0}
    git stash save %stash_name%
    git checkout root-branch
    git pull origin root-branch
    git branch %branch_type%%branch_name%
    git checkout %branch_type%%branch_name%
    git stash apply stash@{0}
    git add .
    git commit -m "%branch_name% %commit_des%"
    git push origin %branch_type%%branch_name%
    git checkout pre-dev
    git pull origin pre-dev
    git stash apply stash@{0}
    git add .
    git commit -m "%branch_name%# %commit_des%"
    git push origin pre-dev
)
pause

приведенный выше код решает мою проблему, но когда возникают конфликты с некоторыми файлами, он просто выталкивает конфликтующие файлы, которые мне не нужны. Есть ли способ приостановить командное окно в случае возникновения конфликта

1 Ответ

1 голос
/ 17 апреля 2020

Итак, вы можете использовать for l oop и операторов || и &&:

@echo off & setlocal enabledelayedexpansion

set working_dir="D:\Projects\NestJsApiProject"
set /P stash_name= Enter stash name: 
set /P branch_name= Enter new branch name: 
set /P commit_des= Enter commit description: 
set /P isFeature= Is it a feature?Y/N: 
set branch_type= features/

if /i "!isFeature!" == "N" set branch_type= bugs/
for %%i in (!branch_type!,!stash_name!,!branch_name!)do Echo/%%~i

:Ask_Again
set /P areYouSure= You are going to create a branch named "!branch_type!!branch_name!", are u sure? [Y/N]:

echo/!areYouSure!|"%__APPDIR__%Findstr.exe" /bei "Y  N" >nul || goto :Ask_Again

if /i "!areYouSure!" == "Y" ( 
      cd /D "!working_dir!"
      for %%i in (
      stash save %stash_name%,
      checkout pre-dev,
      pull origin pre-dev,
      stash pop stash@^{0^},
      stash save %stash_name%,
      checkout root-branch,
      pull origin root-branch,
      branch %branch_type%%branch_name%,
      checkout %branch_type%%branch_name%,
      stash apply stash@^{0^}
      add .,
      commit -m "%branch_name% %commit_des%",
      push origin %branch_type%%branch_name%,
      checkout pre-dev,
      pull origin pre-dev,
      stash apply stash@^{0^}
      add .,
      commit -m "%branch_name%# %commit_des%",
      push origin pre-dev 
    )do echo/ Git %%~i || "%__APPDIR__%Timeout.exe" -1 
) else echo/areYouSure = N 
endlocal

Проверьте и посмотрите результаты, если все в порядке, удалите:

<strike><b>echo/</b></strike> Git %%~i || "%__APPDIR__%Timeout.exe" -1

Подробнее о ...

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...