Skip to content

Commit

Permalink
with_env(key,val): temporarily set and restore an evironment value.
Browse files Browse the repository at this point in the history
Use this to fix #4494 — older gits don't support merge --no-edit.
  • Loading branch information
StefanKarpinski committed Oct 12, 2013
1 parent 7b437bb commit 7dfa093
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
12 changes: 12 additions & 0 deletions base/env.jl
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,18 @@ function show(io::IO, ::EnvHash)
end
end

# temporarily set and then restore an environment value
function with_env(f::Function, key::String, val)
old = get(ENV,key,nothing)
val != nothing ? (ENV[key]=val) : _unsetenv(key)
try f()
finally
old != nothing ? (ENV[key]=old) : _unsetenv(key)
catch
rethrow()
end
end

## misc environment-related functionality ##

tty_cols() = parseint(Int32, get(ENV,"COLUMNS","80"), 10)
Expand Down
4 changes: 3 additions & 1 deletion base/pkg/entry.jl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,9 @@ function update(branch::String)
Git.run(`checkout -q $branch`)
end
# TODO: handle merge conflicts
Git.run(`pull -q --no-edit`, out=DevNull)
with_env("GIT_MERGE_AUTOEDIT","no") do
Git.run(`pull -q`, out=DevNull)
end
end
avail = Read.available()
# this has to happen before computing free/fixed
Expand Down

2 comments on commit 7dfa093

@kmsquire
Copy link
Member

Choose a reason for hiding this comment

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

with_env needs to be imported:

julia> Pkg.update()
INFO: Updating METADATA...
ERROR: with_env not defined
 in anonymous at no file:187
 in cd at file.jl:22
 in update at pkg/entry.jl:177
 in anonymous at pkg/dir.jl:30
 in cd at file.jl:22
 in cd at pkg/dir.jl:30
 in update at pkg.jl:39

@StefanKarpinski
Copy link
Member Author

Choose a reason for hiding this comment

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

Doh. Thanks.

Please sign in to comment.