From 24be26ae05cad1c6f21ae97b3e38ce57f12fe289 Mon Sep 17 00:00:00 2001 From: John Doe Date: Wed, 4 Nov 2020 00:50:55 +0500 Subject: [PATCH] Autoconfig --- .gitconfig-for-nix | 37 ++++++++++++++++++++++ .gitconfig-for-win | 36 +++++++++++++++++++++ .gitignore | 7 +++++ apply-gitconfig-for-nix.sh | 18 +++++++++++ apply-gitconfig-for-win.cmd | 62 +++++++++++++++++++++++++++++++++++++ 5 files changed, 160 insertions(+) create mode 100644 .gitconfig-for-nix create mode 100644 .gitconfig-for-win create mode 100644 .gitignore create mode 100755 apply-gitconfig-for-nix.sh create mode 100644 apply-gitconfig-for-win.cmd diff --git a/.gitconfig-for-nix b/.gitconfig-for-nix new file mode 100644 index 00000000..ada35de9 --- /dev/null +++ b/.gitconfig-for-nix @@ -0,0 +1,37 @@ +[merge] + tool = vscode +[mergetool] + keepbackup = false +[diff] + tool = vscode + guitool = vscode +[core] + autocrlf = input +[pull] + ff = only + rebase = false +[fetch] + prune = false +[rebase] + autoStash = false +[difftool "vscode"] + path = code + cmd = code --wait --diff $LOCAL $REMOTE +[mergetool "vscode"] + path = code + cmd = code --wait $MERGED +[credential] + helper = manager +[alias] + it = !git init && git commit -m 'Initial commit' --allow-empty + st = status -sb + call = !git add . && git commit -m + commend = commit --amend --no-edit + graph = log --oneline --decorate --graph --all + to = checkout + pushup = push -u origin HEAD + please = push --force-with-lease + puff = pull --ff-only + pure = pull --rebase --autostash + undo = reset --soft HEAD^ + diff --git a/.gitconfig-for-win b/.gitconfig-for-win new file mode 100644 index 00000000..d483dd1e --- /dev/null +++ b/.gitconfig-for-win @@ -0,0 +1,36 @@ +[merge] + tool = vscode +[mergetool] + keepbackup = false +[diff] + tool = vscode + guitool = vscode +[core] + autocrlf = true +[pull] + ff = only + rebase = false +[fetch] + prune = false +[rebase] + autoStash = false +[difftool "vscode"] + path = code + cmd = code --wait --diff $LOCAL $REMOTE +[mergetool "vscode"] + path = code + cmd = code --wait $MERGED +[credential] + helper = manager +[alias] + it = !git init && git commit -m 'Initial commit' --allow-empty + st = status -sb + call = !git add . && git commit -m + commend = commit --amend --no-edit + graph = log --oneline --decorate --graph --all + to = checkout + pushup = push -u origin HEAD + please = push --force-with-lease + puff = pull --ff-only + pure = pull --rebase --autostash + undo = reset --soft HEAD^ diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..9d17fc14 --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +# Коллекция полезных .gitignore от GitHub: https://github.com/github/gitignore + +# Игнорирование всех markdown-файлов: +*.md + +# Исключение из игнорирования конкретного файла: +!init.md diff --git a/apply-gitconfig-for-nix.sh b/apply-gitconfig-for-nix.sh new file mode 100755 index 00000000..32896b5e --- /dev/null +++ b/apply-gitconfig-for-nix.sh @@ -0,0 +1,18 @@ +#!/bin/bash +git config --local include.path "../.gitconfig-for-nix" + +# setting editor for commits +git config --local core.editor nano + +# setting anonymous name and email if not configured by user +GitUserEmail=$(git config --get user.email) +if [[ "$GitUserEmail" == "" ]]; then + git config --local user.email "johndoe@example.com" +fi +GitUserName=$(git config --get user.name) +if [[ "$GitUserName" == "" ]]; then + git config --local user.name "John Doe" +fi + +echo "Configuration is done" +sleep 3 diff --git a/apply-gitconfig-for-win.cmd b/apply-gitconfig-for-win.cmd new file mode 100644 index 00000000..ddd91a57 --- /dev/null +++ b/apply-gitconfig-for-win.cmd @@ -0,0 +1,62 @@ +@echo off + +set GIT=git + +%GIT% --help > nul + +if %errorlevel% neq 0 ( + set GIT="%ProgramFiles%\Git\bin\gi.exe" +) + +%GIT% --help > nul + +if %errorlevel% neq 0 ( + color 0c + echo. + echo. + echo "Git is not configured properly... Ask for help!" + pause + exit +) + +REM setting editor for commits +%GIT% config --local core.editor notepad + +REM including predefined config +%GIT% config --local include.path "../.gitconfig-for-win" + +REM setting up absolute path to visual studio code +if exist "%ProgramFiles(x86)%\Microsoft VS Code\Code.exe" ( + %GIT% config --local difftool.vscode.path "%ProgramFiles(x86)%\Microsoft VS Code\Code.exe" + %GIT% config --local difftool.vscode.cmd "%ProgramFiles(x86)%\Microsoft VS Code\Code.exe --wait --diff $LOCAL $REMOTE" + %GIT% config --local mergetool.vscode.path "%ProgramFiles(x86)%\Microsoft VS Code\Code.exe" + %GIT% config --local mergetool.vscode.cmd "%ProgramFiles(x86)%\Programs\Microsoft VS Code\Code.exe --wait $MERGED" +) +if exist "%ProgramFiles%\Microsoft VS Code\Code.exe" ( + %GIT% config --local difftool.vscode.path "%ProgramFiles%\Microsoft VS Code\Code.exe" + %GIT% config --local difftool.vscode.cmd "%ProgramFiles%\Microsoft VS Code\Code.exe --wait --diff $LOCAL $REMOTE" + %GIT% config --local mergetool.vscode.path "%ProgramFiles%\Microsoft VS Code\Code.exe" + %GIT% config --local mergetool.vscode.cmd "%ProgramFiles%\Programs\Microsoft VS Code\Code.exe --wait $MERGED" +) +if exist "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe" ( + %GIT% config --local difftool.vscode.path "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe" + %GIT% config --local difftool.vscode.cmd "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe --wait --diff $LOCAL $REMOTE" + %GIT% config --local mergetool.vscode.path "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe" + %GIT% config --local mergetool.vscode.cmd "%LOCALAPPDATA%\Programs\Microsoft VS Code\Code.exe --wait $MERGED" +) + +REM setting anonymous name and email if not configured by user +for /f %%i in ('git config --get user.email') do set GitUserEmail=%%i + +if [%GitUserEmail%] == [] ( + %GIT% config --local user.email "johndoe@example.com" +) + +for /f %%i in ('git config --get user.name') do set GitUserName=%%i + +if [%GitUserName%] == [] ( + %GIT% config --local user.name "John Doe" +) + +echo Configuration is done +pause