platformsh / legacy-cli

This is the legacy version of Platform.sh's command-line interface. The new version is at: https://github.com/platformsh/cli
https://docs.platform.sh/administration/cli.html
MIT License
221 stars 121 forks source link

Feature Request: Pull when checking out branch #315

Open joshmiller83 opened 9 years ago

joshmiller83 commented 9 years ago

I'd like the command:

platform checkout [branch]

to pull the latest repo from platform as an option or by default.

platform checkout [branch] --pull

and/or

platform checkout [branch] --pull-rebase

Right now I currently checkout, cd into repository and do a git pull --rebase. Often I find I miss the git pull and am working on an outdated branch.

joshmiller83 commented 9 years ago

Would be extra nice if I don't use the --pull command to be notified that the branch I just pulled down is

Warning: the [branch] branch is X number of commits behind platform
pjcdawkins commented 9 years ago

If you have the 'shell aliases' installed (see the README) this could be as easy as:

platform checkout [branch] && plgit pull

... which is only 7 characters longer than your suggestion of:

platform checkout [branch] --pull
joshmiller83 commented 9 years ago

The problem would remain that the "platform checkout [branch]" doesn't automatically pull in the latest code into the repository. Would be nice to have a more prominent warning telling users to pull in the latest branch that is X number of commits ahead.


To be clear (if this feature never makes it in and you've found this thread because you want something similar), this is what Patrick is recommending (from README):

Enable auto-completion and shell aliases (optional, but recommended).

In Linux or OS X, add this line to your shell configuration file:

    . "$HOME/.composer/vendor/platformsh/cli/platform.rc" 2>/dev/null

In Windows, it would be:

    . "$APPDATA/Composer/vendor/platformsh/cli/platform.rc" 2> nul
joshmiller83 commented 9 years ago

image

Also note, this is what the current (2.3.x) CLI does when you are behind... nice warning, but needs a warning color and maybe more whitespace. We really want people to catch on that we are 14 commits behind.

pjcdawkins commented 9 years ago

This kind of seems like it should be a feature request for Git. The CLI is just reprinting Git's output there.

pjcdawkins commented 9 years ago

Also note that Git is not actually showing you how far you are behind the remote. It's showing you how far you are behind your own local copy of the remote.

drjayvee commented 2 years ago

I'd like to breathe new life into this issue.

I'm trying to fully containerize our deploy process and rely on an API token (env PLATFORM_CLI_TOKEN) exclusively. Therefore, the build script cannot run any native git commands that need to use SSH (such as fetch, pull, push). (The CLI uses a custom GIT_SSH_COMMAND to use the SSH key it creates on the fly. I don't want our script to emulate this.)

It's a bit strange that platform checkout fetches from the remote only if the local branch doesn't exist. (see https://github.com/platformsh/platformsh-cli/blob/3.x/src/Command/Environment/EnvironmentCheckoutCommand.php#L64)

So one workaround is to remove the local branch before platform checkout, but that's ugly. (Another would be to remove the repo entirely, but come on.)

Therefore, I vote in favor of adding --pull (or --reset to git reset --hard $remote/$branch) to platform checkout.

I'd be happy to create a PR for this.