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

Support more path types in vcs_relative_path #304

Merged
merged 1 commit into from
Apr 27, 2020

Conversation

jamesottaway
Copy link
Contributor

Fixes #303

I see now that the old local p=$( printf "%s" "$( pwd -P )/${1}" | sed 's#//*#/#g' ) line was trying to generate an absolute path, but it didn't support ../ and also assumed it was being given a relative path and hence failed when passed an absolute one.

I got the implementation of abs from StackOverflow and ran ShellCheck over it to fix a few small things, which avoids both caveats of the old line.

By moving this out of vcs_relative_path any improvements/fixes needed can be scoped to the new abs function, and vcs_relative_path is now much easier to follow.

@jamesottaway
Copy link
Contributor Author

jamesottaway commented Apr 25, 2020

Proof it works on macOS:

❯ uname -a
Darwin JamesBookAir.local 19.4.0 Darwin Kernel Version 19.4.0: Wed Mar  4 22:28:40 PST 2020; root:xnu-6153.101.6~15/RELEASE_X86_64 x86_64

❯ echo $PWD
/Users/james/src/github.com/jamesottaway/blackbox

❯ git rev-parse --show-toplevel
/Users/james/src/github.com/jamesottaway/blackbox

❯ git checkout resolve-dot-dot
Switched to branch 'resolve-dot-dot'

❯ source bin/_blackbox_common.sh

❯ vcs_relative_path Makefile
Makefile%

❯ vcs_relative_path bin/../Makefile
Makefile%

❯ vcs_relative_path $PWD/bin/../Makefile
Makefile%

and on Ubuntu:

❯ uname -a
Linux JamesPrecision3431 5.3.0-46-generic #38-Ubuntu SMP Fri Mar 27 17:37:05 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

❯ echo $PWD
/home/james/src/github.com/jamesottaway/blackbox

❯ git rev-parse --show-toplevel
/home/james/src/github.com/jamesottaway/blackbox

❯ git checkout resolve-dot-dot
Switched to branch 'resolve-dot-dot'
Your branch is up to date with 'origin/resolve-dot-dot'.

❯ source bin/_blackbox_common.sh

❯ vcs_relative_path Makefile
Makefile%                                                                                                                                              

❯ vcs_relative_path bin/../Makefile
Makefile%                                                                                                                                              

❯ vcs_relative_path $PWD/bin/../Makefile
Makefile%

@TomOnTime
Copy link
Collaborator

Looks great! Could you please add a comment that cites the StackOverflow page? Other than that, its ready to merge.

@jamesottaway
Copy link
Contributor Author

All done. While I'm here, and on a similar topic to #302, is this likely to make it into a new version?

@tlimoncelli tlimoncelli merged commit 87b7cd0 into StackExchange:master Apr 27, 2020
@tlimoncelli
Copy link
Contributor

Thanks!

@jamesottaway jamesottaway deleted the resolve-dot-dot branch April 28, 2020 00:02
@tlimoncelli
Copy link
Contributor

Hi @jamesottaway !

Sadly I had to revert 87b7cd0. "make test" fails. Can you take a look. A file at the base of the repo adds "/" to .gitignore instead of "/filename".

========== CREATED: secret.txt.gpg
========== UPDATING REPO:
NOTE: "already tracked!" messages are safe to ignore.
[master 67cf029] registered in blackbox: secret.txt
 3 files changed, 2 insertions(+)
 create mode 100644 secret.txt.gpg
========== UPDATING VCS: DONE
Local repo updated.  Please push when ready.
    git push
ASSERT FAILED: line '/secret.txt' should exist in file .gitignore
==== file contents: START .gitignore
/
/var/folders/qw/qp8v2j353wz7q57_jymyxj0h0000gn/T/SO.p8wByYEg
==== file contents: END .gitignore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to reference files in a sibling directory using ..
3 participants