diff --git a/bin/split b/bin/split index 81c061b9..7099f27a 100755 --- a/bin/split +++ b/bin/split @@ -10,6 +10,34 @@ NC='\033[0m' # No Color CHECK_MARK="✅" CROSS_MARK="❌" +# Initialize global flags +DEBUG=0 +DRY_RUN=0 + +# Process command-line arguments +for arg in "$@"; do + case $arg in + --debug) + DEBUG=1 + shift + ;; + --dry-run) + DRY_RUN=1 + shift + ;; + *) + # Unknown option + ;; + esac +done + +# Debug message function +debug_msg() { + if [ "$DEBUG" -eq 1 ]; then + echo -e "${INDIGO}Debug: $*${NC}" + fi +} + # Define remotes REMOTES=( 'src/Prime:flasher' @@ -33,27 +61,44 @@ REMOTES=( 'src/Noty/Symfony:flasher-noty-symfony' ) +# Function to get the current git branch name +function current_branch() { + git rev-parse --abbrev-ref HEAD +} + # Define a function to split and push code to a remote repository function split() { local prefix_and_remote="$1" local prefix="${prefix_and_remote%:*}" local remote="${prefix_and_remote#*:}" + local current_branch=$(current_branch) # Add remote if it does not exist (ignoring errors silently) if git remote add "$remote" "git@github.com:php-flasher/$remote.git" 2>/dev/null; then echo -e "${GREEN}Added remote ${INDIGO}$remote${NC} ${CHECK_MARK}" + else + debug_msg "Remote $remote already exists or could not be added." fi # Split the code using the splitsh-lite utility SHA1=$(./bin/splitsh-lite --prefix="$prefix") + debug_msg "SHA1 for $prefix is $SHA1." - # Push the code to the specified remote repository - git push "$remote" "$SHA1:refs/heads/main" -f + # Push the code to the remote repository on the same branch as the current branch + if [ "$DRY_RUN" -eq 0 ]; then + git push "$remote" "$SHA1:refs/heads/$current_branch" -f + else + echo -e "${INDIGO}Dry run: Would push $SHA1 to $remote on branch $current_branch${NC}" + fi } # Pull the latest code from the origin repository -echo -e "${INDIGO}Pulling the latest code from the origin repository...${NC}" -git fetch origin main +if [ "$DRY_RUN" -eq 0 ]; then + echo -e "${INDIGO}Pulling the latest code from the origin repository on branch ${current_branch}...${NC}" + git fetch origin "$current_branch" +else + echo -e "${INDIGO}Dry run: Would fetch latest code for branch $current_branch from the origin repository.${NC}" +fi # Iterate over the remotes and split and push the code for remote in "${REMOTES[@]}"; do diff --git a/src/Laravel/composer.json b/src/Laravel/composer.json index d033cb55..2124727f 100644 --- a/src/Laravel/composer.json +++ b/src/Laravel/composer.json @@ -34,7 +34,7 @@ "require": { "php": ">=8.2", "illuminate/support": "^11.0", - "php-flasher/flasher": "^2.0" + "php-flasher/flasher": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/Noty/Laravel/composer.json b/src/Noty/Laravel/composer.json index 31aa9436..81484379 100644 --- a/src/Noty/Laravel/composer.json +++ b/src/Noty/Laravel/composer.json @@ -33,8 +33,8 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher-laravel": "^2.0", - "php-flasher/flasher-noty": "^2.0" + "php-flasher/flasher-laravel": "2.x-dev", + "php-flasher/flasher-noty": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/Noty/Prime/composer.json b/src/Noty/Prime/composer.json index a6c9011f..b46da155 100644 --- a/src/Noty/Prime/composer.json +++ b/src/Noty/Prime/composer.json @@ -33,7 +33,7 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher": "^2.0" + "php-flasher/flasher": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/Noty/Symfony/composer.json b/src/Noty/Symfony/composer.json index ce3222a5..453dcdc7 100644 --- a/src/Noty/Symfony/composer.json +++ b/src/Noty/Symfony/composer.json @@ -33,8 +33,8 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher-noty": "^2.0", - "php-flasher/flasher-symfony": "^2.0" + "php-flasher/flasher-noty": "2.x-dev", + "php-flasher/flasher-symfony": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/Notyf/Laravel/composer.json b/src/Notyf/Laravel/composer.json index c5b8ba29..c6070c9e 100644 --- a/src/Notyf/Laravel/composer.json +++ b/src/Notyf/Laravel/composer.json @@ -33,8 +33,8 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher-laravel": "^2.0", - "php-flasher/flasher-notyf": "^2.0" + "php-flasher/flasher-laravel": "2.x-dev", + "php-flasher/flasher-notyf": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/Notyf/Prime/composer.json b/src/Notyf/Prime/composer.json index ab218560..57eddd06 100644 --- a/src/Notyf/Prime/composer.json +++ b/src/Notyf/Prime/composer.json @@ -33,7 +33,7 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher": "^2.0" + "php-flasher/flasher": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/Notyf/Symfony/composer.json b/src/Notyf/Symfony/composer.json index 5f688db2..5105883e 100644 --- a/src/Notyf/Symfony/composer.json +++ b/src/Notyf/Symfony/composer.json @@ -33,8 +33,8 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher-notyf": "^2.0", - "php-flasher/flasher-symfony": "^2.0" + "php-flasher/flasher-notyf": "2.x-dev", + "php-flasher/flasher-symfony": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/SweetAlert/Laravel/composer.json b/src/SweetAlert/Laravel/composer.json index 4e4c1f26..715b5b84 100644 --- a/src/SweetAlert/Laravel/composer.json +++ b/src/SweetAlert/Laravel/composer.json @@ -33,8 +33,8 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher-laravel": "^2.0", - "php-flasher/flasher-sweetalert": "^2.0" + "php-flasher/flasher-laravel": "2.x-dev", + "php-flasher/flasher-sweetalert": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/SweetAlert/Prime/composer.json b/src/SweetAlert/Prime/composer.json index eb110211..cde460c5 100644 --- a/src/SweetAlert/Prime/composer.json +++ b/src/SweetAlert/Prime/composer.json @@ -33,7 +33,7 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher": "^2.0" + "php-flasher/flasher": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/SweetAlert/Symfony/composer.json b/src/SweetAlert/Symfony/composer.json index 7917dfc6..c31d2a8c 100644 --- a/src/SweetAlert/Symfony/composer.json +++ b/src/SweetAlert/Symfony/composer.json @@ -33,8 +33,8 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher-sweetalert": "^2.0", - "php-flasher/flasher-symfony": "^2.0" + "php-flasher/flasher-sweetalert": "2.x-dev", + "php-flasher/flasher-symfony": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/Symfony/composer.json b/src/Symfony/composer.json index cd49f527..6e9d45b6 100644 --- a/src/Symfony/composer.json +++ b/src/Symfony/composer.json @@ -33,7 +33,7 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher": "^2.0", + "php-flasher/flasher": "2.x-dev", "symfony/config": "^7.0", "symfony/console": "^7.0", "symfony/dependency-injection": "^7.0", diff --git a/src/Toastr/Laravel/composer.json b/src/Toastr/Laravel/composer.json index ae829baa..81bac61f 100644 --- a/src/Toastr/Laravel/composer.json +++ b/src/Toastr/Laravel/composer.json @@ -29,8 +29,8 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher-laravel": "^2.0", - "php-flasher/flasher-toastr": "^2.0" + "php-flasher/flasher-laravel": "2.x-dev", + "php-flasher/flasher-toastr": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/Toastr/Prime/composer.json b/src/Toastr/Prime/composer.json index c4993bb8..3f6e9c36 100644 --- a/src/Toastr/Prime/composer.json +++ b/src/Toastr/Prime/composer.json @@ -33,7 +33,7 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher": "^2.0" + "php-flasher/flasher": "2.x-dev" }, "autoload": { "psr-4": { diff --git a/src/Toastr/Symfony/composer.json b/src/Toastr/Symfony/composer.json index cba69002..b2d8a66a 100644 --- a/src/Toastr/Symfony/composer.json +++ b/src/Toastr/Symfony/composer.json @@ -33,8 +33,8 @@ "prefer-stable": true, "require": { "php": ">=8.2", - "php-flasher/flasher-symfony": "^2.0", - "php-flasher/flasher-toastr": "^2.0" + "php-flasher/flasher-symfony": "2.x-dev", + "php-flasher/flasher-toastr": "2.x-dev" }, "autoload": { "psr-4": {