···518 IS_EXISTING_DIR=false
519 IS_GIT_REPO=false
520 HAS_COMMITS=false
00000000000000000521 if ${pkgs.git}/bin/git rev-parse --is-inside-work-tree &>/dev/null; then
522 IS_GIT_REPO=true
523 IS_EXISTING_DIR=true
···542 else
543 ${pkgs.git}/bin/git init -b "$BRANCH"
544 IS_GIT_REPO=true
0545 fi
546 fi
547
···518 IS_EXISTING_DIR=false
519 IS_GIT_REPO=false
520 HAS_COMMITS=false
521+522+ # Check if we're already in a git repo with the same name
523+ CURRENT_REPO_NAME=""
524+ if ${pkgs.git}/bin/git rev-parse --is-inside-work-tree &>/dev/null; then
525+ CURRENT_REPO_NAME=$(basename "$(${pkgs.git}/bin/git rev-parse --show-toplevel)")
526+ fi
527+528+ # If NAME was provided and we're not in a matching git repo, create/enter the directory
529+ if [[ -n "$NAME" ]] && [[ "$CURRENT_REPO_NAME" != "$NAME" ]]; then
530+ if [[ -d "$NAME" ]]; then
531+ cd "$NAME"
532+ else
533+ mkdir -p "$NAME"
534+ cd "$NAME"
535+ fi
536+ fi
537+538 if ${pkgs.git}/bin/git rev-parse --is-inside-work-tree &>/dev/null; then
539 IS_GIT_REPO=true
540 IS_EXISTING_DIR=true
···559 else
560 ${pkgs.git}/bin/git init -b "$BRANCH"
561 IS_GIT_REPO=true
562+ ${pkgs.gum}/bin/gum style --foreground 35 "✓ Initialized git repository"
563 fi
564 fi
565