Skip to content
Myr

Add nvm_tree_contains_path function

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jordan Harband · committed by Jordan Harband · parent 200a9aa · Browse files · 2 files+40 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+40 added−0 removed

  • tests:+27 added−0 removed
  • other:+13 added−0 removed

2 files+40 added−0 removed

added:test/fast/Unit tests/nvm_tree_contains_path+27 added
1#!/bin/sh23cleanup () {4 rm tmp/node5 rmdir tmp6 rm tmp2/node7 rmdir tmp28}9die () { echo $@ ; cleanup; exit 1; }1011. ../../../nvm.sh1213mkdir -p tmp14touch -p tmp/node15mkdir -p tmp216touch -p tmp2/node1718nvm_tree_contains_path tmp tmp/node || die '"tmp" should contain "tmp/node"'1920nvm_tree_contains_path tmp tmp2/node && die '"tmp" should not contain "tmp2/node"'2122nvm_tree_contains_path tmp2 tmp2/node || die '"tmp2" should contain "tmp2/node"'2324nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"'2526cleanup27
modified:nvm.sh+13 added
51 unmodified lines
52if [ -z "$NVM_NODEJS_ORG_MIRROR" ]; then53 export NVM_NODEJS_ORG_MIRROR="http://nodejs.org/dist"54fi5556nvm_tree_contains_path() {57 local tree58 tree="$1"59 local path60 path="$2"61 local pathdir62 pathdir=$(dirname "$path")63 while [ "$pathdir" != "" ] && [ "$pathdir" != "." ] && [ "$pathdir" != "/" ] && [ "$pathdir" != "$tree" ]; do64 pathdir=$(dirname "$pathdir")65 done66 [ "$pathdir" = "$tree" ]67}6869# Traverse up in directory tree to find containing folder70nvm_find_up() {71 local path72 path=$PWD
644 unmodified lines