From 330a45a58eef95095d9fb7343f8daeb8c408e4f5 Mon Sep 17 00:00:00 2001 From: Máximo Cuadros Date: Wed, 19 Jul 2017 01:02:11 +0200 Subject: worktree: commit, use path package instead of filepath --- plumbing/format/config/decoder.go | 4 +++- plumbing/format/config/encoder.go | 8 +++++++- 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'plumbing/format/config') diff --git a/plumbing/format/config/decoder.go b/plumbing/format/config/decoder.go index 0f02ce1..c6ad3d8 100644 --- a/plumbing/format/config/decoder.go +++ b/plumbing/format/config/decoder.go @@ -2,6 +2,7 @@ package config import ( "io" + "os" "github.com/src-d/gcfg" ) @@ -33,5 +34,6 @@ func (d *Decoder) Decode(config *Config) error { config.AddOption(s, ss, k, v) return nil } - return gcfg.ReadWithCallback(d, cb) + + return gcfg.ReadWithCallback(io.TeeReader(d, os.Stdout), cb) } diff --git a/plumbing/format/config/encoder.go b/plumbing/format/config/encoder.go index 88bdf65..76d73fd 100644 --- a/plumbing/format/config/encoder.go +++ b/plumbing/format/config/encoder.go @@ -3,6 +3,7 @@ package config import ( "fmt" "io" + "strings" ) // An Encoder writes config files to an output stream. @@ -61,7 +62,12 @@ func (e *Encoder) encodeSubsection(sectionName string, s *Subsection) error { func (e *Encoder) encodeOptions(opts Options) error { for _, o := range opts { - if err := e.printf("\t%s = %s\n", o.Key, o.Value); err != nil { + pattern := "\t%s = %s\n" + if strings.Index(o.Value, "\\") == -1 { + pattern = "\t%s = %q\n" + } + + if err := e.printf(pattern, o.Key, o.Value); err != nil { return err } } -- cgit