├── LICENSE ├── README.md ├── bin ├── git-delete-remote-branch ├── git-delete-remote-branch.bat ├── git-fflow-cbranches ├── git-fflow-cbranches.bat ├── git-fflow-cremotebranches ├── git-fflow-cremotebranches.bat ├── git-fflow-finish ├── git-fflow-finish.bat ├── git-fflow-push ├── git-fflow-push.bat ├── git-fflow-reset ├── git-fflow-reset.bat ├── git-fflow-start ├── git-fflow-start.bat ├── git-gitupdate ├── git-gitupdate.bat ├── git-push-current-branch-to-all-remotes ├── git-push-current-branch-to-all-remotes.bat ├── git-push-master-to-all-remotes ├── git-push-master-to-all-remotes.bat ├── git-sync-fork-with-upstream └── git-sync-fork-with-upstream.bat └── scripts-list.png /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Rogerio Prado de Jesus 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # SourceTree Custom Actions 2 | 3 | The commands I'm using to complement SourceTree via Custom Actions 4 | 5 | ![Command list in 2023-05-30](scripts-list.png) 6 | 7 | ## Installation 8 | 9 | Change your current directory to `$HOME/Library/Application Support/SourceTree/`: 10 | 11 | ```shell 12 | 13 | # macos 14 | cd "$HOME/Library/Application Support/SourceTree/" 15 | 16 | # or, in Windows 17 | # cd "%USERPROFILE%\AppData\Local\Atlassian\SourceTree\" 18 | ``` 19 | 20 | So, git clone (or download) this repository there: 21 | 22 | ```shell 23 | git clone \ 24 | https://github.com/rogeriopradoj/sourcetree-custom-actions-scripts.git \ 25 | scripts 26 | ``` 27 | 28 | Then, go to SourceTree, `Preferences -> Custom Actions -> Add`, filling the options like this: 29 | 30 | - **Menu Caption**: a custom name for that action; 31 | - **[x] Show Full Ouput**: mark it; 32 | - **Script to run**: navigate to `$HOME/Library/Application Support/SourceTree/scripts` folder (in macos or, in Windows, `%USERPROFILE%\AppData\Local\Atlassian\SourceTree\`) and pick the one you are setting up; 33 | 34 | And it's done! Remember that you need to do this process to each of the scripts you want to use as a Custom Action in your machine. 35 | 36 | ### Updating 37 | 38 | You can download latest zip, or run the following command: 39 | 40 | ```shell 41 | # macos 42 | CWD=`pwd` && \ 43 | cd "$HOME/Library/Application Support/SourceTree/scripts" && \ 44 | git pull && \ 45 | cd $CWD 46 | 47 | # or, in Windows 48 | # set "CWD=%CD%" & cd /d "%USERPROFILE%\AppData\Local\Atlassian\SourceTree\scripts" & git pull & cd /d "%CWD%" 49 | ``` 50 | 51 | So, you get the latest versions of the scripts. 52 | 53 | ## Usage 54 | 55 | While working in your repositories as normal in SourceTree, go to `Actions -> Custom Actions` and pick the one you want to use. 56 | 57 | ### Extra - Usage via CLI 58 | 59 | I suggest you adding the folder `$HOME/Library/Application Support/SourceTree/scripts/bin` in your `$PATH` environment variable (in macos or, in Windows, `%USERPROFILE%\AppData\Local\Atlassian\SourceTree\` to `%PATH%`). This way, you can use the same scripts via CLI just calling script name, instead of needing to type the full path to each script. 60 | 61 | In case you are using `bash` as your shell, you can do this: 62 | 63 | ```shell 64 | echo \ 65 | 'export PATH=$PATH:"$HOME/Library/Application Support/SourceTree/scripts/bin"' \ 66 | >> ~/.bashrc && \ 67 | source ~/.bashrc 68 | ``` 69 | 70 | Otherwise, here is the syntax if your shell is `zsh`: 71 | 72 | ```shell 73 | echo \ 74 | 'export PATH=$PATH:"$HOME/Library/Application Support/SourceTree/scripts/bin"' \ 75 | >> ~/.zshrc && \ 76 | source ~/.zshrc 77 | ``` 78 | 79 | Remember to make scripts executable: 80 | 81 | ```shell 82 | find "$HOME/Library/Application Support/SourceTree/scripts/bin/" -type f -print0 | xargs -0 chmod +x 83 | ``` 84 | 85 | After that, you can run any of the scripts via CLI no matter inside what directory you are, example of running `git-push-master-to-all-remotes` 86 | 87 | ```shell 88 | cd PATH_TO_ANY_GIT_PROJECT 89 | # 90 | git-push-master-to-all-remotes 91 | # or 92 | git push-master-to-all-remotes 93 | ``` 94 | -------------------------------------------------------------------------------- /bin/git-delete-remote-branch: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | branch="$1" 4 | remote="$2" 5 | if [ "$branch" == "" ]; then 6 | echo "" 7 | echo "...ERROR: You must inform the branch name. Ex.:" 8 | echo "" 9 | echo " ./$(basename $0) \"branch-to-be-deleted\" [remote-name]" 10 | exit 1 11 | fi 12 | 13 | if [ "$remote" != "" ]; then 14 | echo ">>>>>> git branch -d -r $remote/$branch" && \ 15 | git branch -d -r $remote/$branch; 16 | echo ">>>>>> git push $remote :$branch" && \ 17 | git push $remote :$branch; 18 | else 19 | for r in $(git remote); do 20 | echo ">>>>>> git branch -d -r $r/$branch" && \ 21 | git branch -d -r $r/$branch; 22 | echo ">>>>>> git push $r :$branch" && \ 23 | git push $r :$branch; 24 | done 25 | fi 26 | -------------------------------------------------------------------------------- /bin/git-delete-remote-branch.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | 4 | set "branch=%~1" 5 | set "remote=%~2" 6 | 7 | if "%branch%"=="" ( 8 | echo. 9 | echo ...ERROR: You must inform the branch name. Ex.: 10 | echo. 11 | echo %0 "branch-to-be-deleted" [remote-name] 12 | exit /b 1 13 | ) 14 | 15 | if not "%remote%"=="" ( 16 | echo ^>^>^>^>^> git branch -d -r %remote%/%branch% 17 | git branch -d -r %remote%/%branch% 18 | echo ^>^>^>^>^> git push %remote% :%branch% 19 | git push %remote% :%branch% 20 | ) else ( 21 | for /f "tokens=*" %%r in ('git remote') do ( 22 | echo ^>^>^>^>^> git branch -d -r %%r/%branch% 23 | git branch -d -r %%r/%branch% 24 | echo ^>^>^>^>^> git push %%r :%branch% 25 | git push %%r :%branch% 26 | ) 27 | ) 28 | 29 | endlocal 30 | -------------------------------------------------------------------------------- /bin/git-fflow-cbranches: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | CURRENT_BRANCH=`git symbolic-ref --short HEAD`; 4 | 5 | for b in $(git for-each-ref --format='%(refname:lstrip=-1)' refs/heads/); do 6 | if [ $b = 'master' ]; then 7 | continue 8 | elif [ $b = 'main' ]; then 9 | continue 10 | elif [ $b = $CURRENT_BRANCH ]; then 11 | continue 12 | else 13 | echo ">>>>>> git branch -d $b" && \ 14 | git branch -d $b; 15 | fi 16 | done 17 | -------------------------------------------------------------------------------- /bin/git-fflow-cbranches.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | for /f "tokens=*" %%a in ('git symbolic-ref --short HEAD') do set "CURRENT_BRANCH=%%a" 4 | 5 | for /f "delims=" %%b in ('git for-each-ref --format="%%(refname:lstrip=2)" refs/heads/') do ( 6 | set "BRANCH=%%b" 7 | if not "!BRANCH!"=="master" if not "!BRANCH!"=="main" if not "!BRANCH!"=="!CURRENT_BRANCH!" ( 8 | echo ^>^>^>^> git branch -D !BRANCH! 9 | git branch -D !BRANCH! 10 | ) 11 | ) 12 | 13 | endlocal 14 | -------------------------------------------------------------------------------- /bin/git-fflow-cremotebranches: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Buscar alterações de todos os remotos 4 | for remote in $(git remote); do 5 | echo "Fetching from remote: $remote" 6 | git fetch "$remote" 7 | done 8 | 9 | # Excluir todos os branches remotos, exceto master e main 10 | for remote in $(git remote); do 11 | for branch in $(git for-each-ref --format="%(refname:lstrip=3)" "refs/remotes/$remote/"); do 12 | if [[ "$branch" != "master" && "$branch" != "main" && "$branch" != "HEAD" ]]; then 13 | echo "Deleting remote branch: $branch from remote $remote" 14 | git push "$remote" --delete "$branch" 2>/dev/null 15 | fi 16 | done 17 | done 18 | -------------------------------------------------------------------------------- /bin/git-fflow-cremotebranches.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | 4 | :: Buscar alterações de todos os remotos 5 | for /f "tokens=*" %%a in ('git remote') do ( 6 | echo Fetching from remote: %%a 7 | git fetch %%a 8 | ) 9 | 10 | :: Excluir todos os branches remotos, exceto master e main 11 | for /f "tokens=*" %%a in ('git remote') do ( 12 | for /f "tokens=*" %%b in ('git for-each-ref --format="%%(refname:lstrip=3)" refs/remotes/%%a/') do ( 13 | set "branch=%%b" 14 | if not "!branch!"=="master" if not "!branch!"=="main" if not "!branch!"=="HEAD" ( 15 | echo Deleting remote branch: !branch! from remote %%a 16 | git push %%a --delete !branch! 2>nul 17 | ) 18 | ) 19 | ) 20 | 21 | endlocal 22 | -------------------------------------------------------------------------------- /bin/git-fflow-finish: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | main_branch="main" 4 | 5 | if ! git show-ref -q --heads $main_branch; then 6 | main_branch="master" 7 | fi 8 | 9 | BRANCH=`git symbolic-ref --short HEAD`; 10 | 11 | echo "Branch: $BRANCH" 12 | echo "main_branch: $main_branch" 13 | 14 | git checkout $main_branch && \ 15 | git merge $BRANCH --no-ff --no-edit && \ 16 | git branch -d $BRANCH 17 | -------------------------------------------------------------------------------- /bin/git-fflow-finish.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | 4 | set "main_branch=main" 5 | 6 | git show-ref --heads !main_branch! > nul 2>&1 7 | if not %errorlevel% == "0" ( 8 | set "main_branch=master" 9 | ) 10 | 11 | for /f "tokens=*" %%a in ('git symbolic-ref --short HEAD') do set "BRANCH=%%a" 12 | 13 | echo Branch: !BRANCH! 14 | echo main_branch: !main_branch! 15 | 16 | git checkout !main_branch! 17 | git merge !BRANCH! --no-ff --no-edit 18 | git branch -d !BRANCH! 19 | 20 | endlocal 21 | -------------------------------------------------------------------------------- /bin/git-fflow-push: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | BRANCH=`git symbolic-ref --short HEAD`; 4 | 5 | for r in $(git remote); do 6 | if [ $r = 'origin' ]; then 7 | echo ">>>>>> git push $r $BRANCH" && \ 8 | git push $r $BRANCH; 9 | fi 10 | done 11 | -------------------------------------------------------------------------------- /bin/git-fflow-push.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | 4 | for /f "tokens=*" %%a in ('git symbolic-ref --short HEAD') do set "BRANCH=%%a" 5 | 6 | for /f "tokens=*" %%r in ('git remote') do ( 7 | if "%%r"=="origin" ( 8 | echo ^>^>^>^>^> git push %%r !BRANCH! 9 | git push %%r !BRANCH! 10 | ) 11 | ) 12 | 13 | endlocal 14 | -------------------------------------------------------------------------------- /bin/git-fflow-reset: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if hash git &>/dev/null; then 4 | main_branch="main" 5 | 6 | if git show-ref -q --heads $main_branch; then 7 | continue 8 | else 9 | main_branch="master" 10 | fi 11 | 12 | printf '\033[0;32m%s\033[0m\n' 'checkout to main branch' 13 | printf '\033[0;32m%s\033[0m\n' '//' 14 | git checkout $main_branch 15 | echo '.' 16 | printf '\033[0;32m%s\033[0m\n' '\\' 17 | 18 | printf '\033[0;32m%s\033[0m\n' 'pull from origin' 19 | printf '\033[0;32m%s\033[0m\n' '//' 20 | git pull origin $main_branch 21 | echo '.' 22 | printf '\033[0;32m%s\033[0m\n' '\\' 23 | 24 | printf '\033[0;32m%s\033[0m\n' 'fetch pruning' 25 | printf '\033[0;32m%s\033[0m\n' '//' 26 | git fetch -p 27 | echo '.' 28 | printf '\033[0;32m%s\033[0m\n' '\\' 29 | 30 | fi -------------------------------------------------------------------------------- /bin/git-fflow-reset.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | 4 | where git > nul 2>&1 5 | if %errorlevel% == 0 ( 6 | set "main_branch=main" 7 | 8 | cmd /c "exit /b 0" 9 | git show-ref -q --heads %main_branch% > nul 2>&1 10 | if not %errorlevel% == "0" ( 11 | set "main_branch=master" 12 | ) 13 | 14 | echo. 15 | echo ----------------------------------------- 16 | echo checkout to main branch 17 | echo ----------------------------------------- 18 | echo. 19 | 20 | git checkout !main_branch! 21 | 22 | echo. 23 | echo ----------------------------------------- 24 | echo pull from origin 25 | echo ----------------------------------------- 26 | echo. 27 | 28 | git pull origin !main_branch! 29 | 30 | echo. 31 | echo ----------------------------------------- 32 | echo fetch pruning 33 | echo ----------------------------------------- 34 | echo. 35 | 36 | git fetch -p 37 | 38 | ) 39 | 40 | endlocal 41 | -------------------------------------------------------------------------------- /bin/git-fflow-start: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | feature="$1" 4 | if [ "$feature" == "" ]; then 5 | echo "" 6 | echo "...ERROR: You must inform the feature name. Ex.:" 7 | echo "" 8 | echo " ./$(basename $0) \"new-module-xyz\"" 9 | exit 1 10 | fi 11 | 12 | git checkout -b $feature; 13 | -------------------------------------------------------------------------------- /bin/git-fflow-start.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | set "feature=%~1" 4 | if "%feature%"=="" ( 5 | echo. 6 | echo ...ERROR: You must inform the feature name. Ex.: 7 | echo. 8 | echo %0 "new-module-xyz" 9 | exit /b 1 10 | ) 11 | 12 | git checkout -b %feature% 13 | -------------------------------------------------------------------------------- /bin/git-gitupdate: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if hash git &>/dev/null; then 4 | main_branch="main" 5 | 6 | if git show-ref -q --heads $main_branch; then 7 | continue 8 | else 9 | main_branch="master" 10 | fi 11 | 12 | printf '\033[0;32m%s\033[0m\n' 'checkout to main branch' 13 | printf '\033[0;32m%s\033[0m\n' '//' 14 | git checkout $main_branch 15 | echo '.' 16 | printf '\033[0;32m%s\033[0m\n' '\\' 17 | 18 | printf '\033[0;32m%s\033[0m\n' 'pull from origin' 19 | printf '\033[0;32m%s\033[0m\n' '//' 20 | git pull origin $main_branch 21 | echo '.' 22 | printf '\033[0;32m%s\033[0m\n' '\\' 23 | 24 | printf '\033[0;32m%s\033[0m\n' 'fetch pruning' 25 | printf '\033[0;32m%s\033[0m\n' '//' 26 | git fetch -p 27 | echo '.' 28 | printf '\033[0;32m%s\033[0m\n' '\\' 29 | 30 | fi -------------------------------------------------------------------------------- /bin/git-gitupdate.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | 4 | where git > nul 2>&1 5 | if %errorlevel% == 0 ( 6 | set "main_branch=main" 7 | 8 | cmd /c "exit /b 0" 9 | git show-ref -q --heads %main_branch% > nul 2>&1 10 | if not %errorlevel% == "0" ( 11 | set "main_branch=master" 12 | ) 13 | 14 | echo. 15 | echo ----------------------------------------- 16 | echo checkout to main branch 17 | echo ----------------------------------------- 18 | echo. 19 | 20 | git checkout !main_branch! 21 | 22 | echo. 23 | echo ----------------------------------------- 24 | echo pull from origin 25 | echo ----------------------------------------- 26 | echo. 27 | 28 | git pull origin !main_branch! 29 | 30 | echo. 31 | echo ----------------------------------------- 32 | echo fetch pruning 33 | echo ----------------------------------------- 34 | echo. 35 | 36 | git fetch -p 37 | 38 | ) 39 | 40 | endlocal 41 | -------------------------------------------------------------------------------- /bin/git-push-current-branch-to-all-remotes: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # BRANCH=`git symbolic-ref --short HEAD`; for r in $(git remote); do echo ">>>>>> git push $r $BRANCH" && git push $r $BRANCH; done 3 | BRANCH=`git symbolic-ref --short HEAD`; 4 | for r in $(git remote); do 5 | echo ">>>>>> git push $r $BRANCH" && \ 6 | git push $r $BRANCH; 7 | done 8 | -------------------------------------------------------------------------------- /bin/git-push-current-branch-to-all-remotes.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | 4 | for /f "tokens=*" %%a in ('git symbolic-ref --short HEAD') do set "BRANCH=%%a" 5 | 6 | for /f "tokens=*" %%r in ('git remote') do ( 7 | echo ^>^>^>^>^> git push %%r !BRANCH! 8 | git push %%r !BRANCH! 9 | ) 10 | 11 | endlocal 12 | -------------------------------------------------------------------------------- /bin/git-push-master-to-all-remotes: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # for r in $(git remote); do echo ">>>>>> git push $r master" && git push $r master; done 4 | for r in $(git remote); do 5 | echo ">>>>>> git push $r master" && \ 6 | git push $r master; 7 | done 8 | -------------------------------------------------------------------------------- /bin/git-push-master-to-all-remotes.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | for /f "tokens=*" %%r in ('git remote') do ( 4 | echo ^>^>^>^>^> git push %%r master 5 | git push %%r master 6 | ) 7 | -------------------------------------------------------------------------------- /bin/git-sync-fork-with-upstream: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | echo "➜ Origin repository (fork): $(git remote get-url origin)"; 4 | echo "➜ Upstream repository (official): $(git remote get-url upstream)"; 5 | 6 | git fetch upstream --prune; 7 | git branch --set-upstream-to upstream/master master; 8 | for brname in ` 9 | git branch -r | grep upstream | grep -v master | grep -v HEAD | sed -e 's/^[^\/]*\///' 10 | `; do 11 | git branch --track $brname upstream/$brname 2> /dev/null; 12 | git branch --set-upstream-to upstream/$brname $brname; 13 | done 14 | 15 | git pull --rebase upstream; 16 | git push --all origin; 17 | 18 | echo "➜ Origin repository (fork): $(git remote get-url origin)"; 19 | echo "➜ Upstream repository (official): $(git remote get-url upstream)"; 20 | -------------------------------------------------------------------------------- /bin/git-sync-fork-with-upstream.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | setlocal EnableDelayedExpansion 3 | 4 | for /f "tokens=*" %%a in ('git remote get-url origin') do set "REMOTE_URL_ORIGIN=%%a" 5 | for /f "tokens=*" %%a in ('git remote get-url upstream') do set "REMOTE_URL_UPSTREAM=%%a" 6 | 7 | echo ------------------------------------------ 8 | echo Git Branch Management 9 | echo ------------------------------------------ 10 | echo. 11 | echo ^>^>^>^>^> Origin repository (fork): !REMOTE_URL_ORIGIN! 12 | echo ^>^>^>^>^> Upstream repository (official): !REMOTE_URL_UPSTREAM! 13 | echo. 14 | 15 | git fetch upstream --prune 16 | git branch --set-upstream-to upstream/master master 17 | echo. 18 | 19 | for /f "tokens=*" %%a in ('git branch -r ^| findstr /i upstream ^| findstr /v /i master ^| findstr /v /i origin ^| findstr /v /i HEAD') do ( 20 | set "upstreamBranch=%%a" 21 | echo upstreamBranch: !upstreamBranch! 22 | set "branchName=!upstreamBranch:~10!" 23 | echo branchName: !branchName! 24 | git branch --track !branchName! !upstreamBranch! 2> nul 25 | git branch --set-upstream-to !upstreamBranch! !branchName! 26 | ) 27 | echo. 28 | 29 | git pull --rebase upstream 30 | git push --all origin 31 | echo. 32 | 33 | echo ^>^>^>^>^> Origin repository (fork): !REMOTE_URL_ORIGIN! 34 | echo ^>^>^>^>^> Upstream repository (official): !REMOTE_URL_UPSTREAM! 35 | echo. 36 | 37 | endlocal 38 | -------------------------------------------------------------------------------- /scripts-list.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rogeriopradoj/sourcetree-custom-actions-scripts/e7d6cd0291db5f55209714a452150c662bb7f20b/scripts-list.png --------------------------------------------------------------------------------