from typing import Optional
from typing import Tuple


def expandCommand(command: str, currentBranch: str, prevBranch: Optional[str]) -> Tuple[str, bool]:
    """
    Replaces
    %P with prevBranch,
    %B with currentBranch.
    If couldn't replace e.g. due to prevBranch being None, then does
      no replacement.
    Returns:
        Tuple[expandedCommand, True if succeeded in expanding]
    """
    expandedCommand = command
    if command.find('%P') >= 0:
        if prevBranch is None:
            return command, False
        expandedCommand = command.replace('%P', prevBranch)

    expandedCommand = expandedCommand.replace('%B', currentBranch)
    return expandedCommand, True