vup: make 'v up' work from release archive, without a .git folder

pull/5275/head
JalonSolov 2020-06-07 16:59:15 -04:00 committed by GitHub
parent 3bbda7103f
commit 8c8df66986
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 28 additions and 13 deletions

View File

@ -11,21 +11,18 @@ fn main() {
println('Updating V...')
// git pull
git_result := os.exec('git pull --rebase origin master') or {
panic(err)
if !os.exists('.git') {
// initialize as if it had been cloned
git_command('init')
git_command('remote add origin https://github.com/vlang/v')
git_command('fetch')
git_command('reset --hard origin/master')
git_command('clean --quiet -xdf --exclude v.exe --exclude cmd/tools/vup.exe')
} else {
// pull latest
git_command('pull origin master')
}
if git_result.exit_code != 0 {
if git_result.output.contains('Permission denied') {
eprintln('have no access `$vroot`: Permission denied')
} else {
eprintln(git_result.output)
}
exit(1)
}
println(git_result.output)
v_hash := util.githash(false)
current_hash := util.githash(true)
// println(v_hash)
@ -77,3 +74,21 @@ fn backup(file string) {
}
os.mv(file, backup_file)
}
fn git_command(command string) {
vexe := pref.vexe_path()
vroot := os.dir(vexe)
git_result := os.exec('git $command') or {
panic(err)
}
if git_result.exit_code != 0 {
if git_result.output.contains('Permission denied') {
eprintln('have no access `$vroot`: Permission denied')
} else {
eprintln(git_result.output)
}
exit(1)
}
}