Skip to content

Commit

Permalink
Refactor directory checking into function
Browse files Browse the repository at this point in the history
Also check for .git folder if .here file not found. References #2
  • Loading branch information
korenmiklos committed Jul 31, 2020
1 parent 8bd8ffe commit ee78b51
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions here.ado
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,19 @@ program define here, rclass
local `current' = c(pwd)

* are we there yet?
capture confirm file ".here"
are_we_there_yet
while (_rc) {
* if at root folder without .here, stop with an error
if ("`c(pwd)'" == "") {
display in red "Project folder not found."
quietly cd "``current''/"
error 170
break_with_error, directory(``current'')
}

* if not, go up one level
capture quietly cd ".."
if (_rc) {
display in red "Project folder not found."
quietly cd "``current''/"
error 170
break_with_error, directory(``current'')
}
capture confirm file ".here"
are_we_there_yet
}

local `here' = c(pwd)
Expand All @@ -41,3 +37,18 @@ program define here, rclass
global here "``here''/"
display "``here''/"
end

program define are_we_there_yet
capture confirm file ".here"
if (_rc != 0) {
capture confirm file ".git"
}
end

program define break_with_error
syntax , directory(string)

display in red "Project folder not found."
quietly cd "`directory'/"
error 170
end

0 comments on commit ee78b51

Please sign in to comment.