Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use current $SHELL for shell-plugin, fix #97 #100

Closed
wants to merge 1 commit into from

Conversation

bixel
Copy link
Contributor

@bixel bixel commented Oct 19, 2016

No description provided.

@nagromc
Copy link
Contributor

nagromc commented Oct 19, 2016

I think it closes #97, not #96

@bixel
Copy link
Contributor Author

bixel commented Oct 19, 2016

Uh, damn! Will I break anything with the PR if I rewrite the history within my fork?

@bixel bixel changed the title Use current $SHELL for shell-plugin, fix #96 Use current $SHELL for shell-plugin, fix #97 Oct 19, 2016
@nagromc
Copy link
Contributor

nagromc commented Oct 19, 2016

The PR hasn't been merged yet, so I guess it's okay if you push a new history. Maybe you'll have to close this PR and open a new one, or the UI will notify us the history changed. I'm sure GitHub engineers thought about this use case ;-) Maybe a FAQ describes this case.

If you aren't confident about that, just create a dummy repository and do some tests (I'm interested in the answer too actually). I can even create a PR for you ;-)

@nagromc
Copy link
Contributor

nagromc commented Oct 19, 2016

Well, it seems it's not recommend:

When pushing commits to a pull request, don't force push. Force pushing can corrupt your pull request.

It can corrupt you PR, but they don't explain in what. Since it would be only changing a comment, and since the original forked master branch doesn't move fast, I think it would be seamless. But that's only my point of view.

@anishathalye
Copy link
Owner

It's totally fine to force push to your own repo when updating a pull request.

@@ -41,8 +41,10 @@ def _process_commands(self, data):
self._log.lowinfo(cmd)
else:
self._log.lowinfo('%s [%s]' % (msg, cmd))
executable = os.environ.get('SHELL') if os.environ.get('SHELL') else None
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can do dict.get(key, default_value) (so os.environ.get('SHELL', None)).

Copy link
Contributor Author

@bixel bixel Oct 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I'll adjust it soon, thanks. I'll just omit the second argument since it defaults to None.

@anishathalye
Copy link
Owner

Sorry for the delay… this somehow fell off my radar.

Merged in 913d548. Thanks for the contribution!

anishathalye added a commit that referenced this pull request May 1, 2020
On POSIX-like systems, calling `subprocess.call()` with both
`shell=True` and `executable='...'` has the following behavior:

> If `shell=True`, on POSIX the _executable_ argument specifies a
> replacement shell for the default `/bin/sh`.

(via https://docs.python.org/3/library/subprocess.html?highlight=subprocess#popen-constructor)

This seems to have a similar behavior on Windows, but this is
problematic when a POSIX shell is substituted for cmd.exe. This is
because when `shell=True`, the shell is invoked with a '/c' argument,
which is the correct argument for cmd.exe but not for Bash, which
expects a '-c' argument instead. See here:
https://github.com/python/cpython/blob/1def7754b7a41fe57efafaf5eff24cfa15353444/Lib/subprocess.py#L1407

This is problematic when combined with Dotbot's behavior, where the
`executable` argument is set based on `$SHELL`. For example, when
running in Git Bash, the `$SHELL` environment variable is set to Bash,
so any commands run by Dotbot will fail (because it'll invoke Bash with
a '/c' argument).

This behavior of setting the `executable` argument based on `$SHELL` was
introduced in 7593d8c. This is the
desired behavior. See discussion in
#97 and
#100.

Unfortunately, this doesn't work quite right on Windows. This patch
works around the issue by avoiding setting the `executable` argument
when the platform is Windows, which is tested using
`platform.system() == 'Windows'`. This means that shell commands
executed by Dotbot on this platform will always be run using cmd.exe.
Invocations of single programs or simple commands will probably work
just fine in cmd.exe. If Bash-like behavior is desired, the user will
have to write their command as `bash -c '...'`.

This shouldn't have any implications for backwards-compatibility,
because setting the `executable` argument on Windows didn't do the right
thing anyways. Previous workarounds that users had should continue to
work with the new code.

When using Python from CYGWIN, `platform.system()` returns something
like 'CYGWIN_NT-...', so it won't be detected with the check, but this
is the correct behavior, because CYGWIN Python's `subprocess.call()` has
the POSIX-like behavior.

This patch also refactors the code to factor out the
`subprocess.call()`, which was being called in both `link.py` and
`shell.py`, so the workaround can be applied in a single place.

See the following issues/pull requests for a discussion of this bug:
- #170
- #177
- #219

An issue has also been raised in Python's issue tracker:
- https://bugs.python.org/issue40467

Thanks to @shivapoudel for originally reporting the issue, @SuJiKiNen
for debugging it and submitting a pull request, and @mohkale for
suggesting factoring out the code so that other plugins could use it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants