Skip to content

Commit

Permalink
snapshot
Browse files Browse the repository at this point in the history
  • Loading branch information
twpayne committed May 18, 2020
1 parent d7fff66 commit 9ea6695
Show file tree
Hide file tree
Showing 163 changed files with 15,088 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/chezmoi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
os:
- macos-latest
- ubuntu-latest
- windows-latest
#- windows-latest # FIXME
runs-on: ${{ matrix.os }}
steps:
- name: Set up Go
Expand Down
10 changes: 8 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ linters:
- ineffassign
- interfacer
- misspell
- nakedret
- prealloc
- rowserrcheck
- scopelint
Expand All @@ -42,6 +41,7 @@ linters:
- gomnd
- lll
- maligned
- nakedret
- nestif
- testpackage
- wsl
Expand Down Expand Up @@ -69,4 +69,10 @@ issues:
path: internal/generate-helps/
- linters:
- scopelint
path: "_test\\.go"
path: "_test\\.go"
- linters:
- deadcode
- unparam
- unused
- varcheck
path: next/
12 changes: 12 additions & 0 deletions TODO
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Use build flag to selectively activate v2 functionality?
Add dir to RunScript?
Encryption should use System.IdempotentCommandOutput
Encryption
Test EncryptionTool that uses randomly generated key

script name is currently part of run once state (in key)
need to decide whether rename of script means its a different script
also executedAt in JSON representation should probably be runAt

document dump --recursive
document global --output
19 changes: 12 additions & 7 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ require (
github.com/hectane/go-acl v0.0.0-20190604041725-da78bae5fc95 // indirect
github.com/huandu/xstrings v1.3.1 // indirect
github.com/imdario/mergo v0.3.9 // indirect
github.com/json-iterator/go v1.1.9 // indirect
github.com/logrusorgru/aurora v0.0.0-20200102142835-e9ef32dff381 // indirect
github.com/mattn/go-isatty v0.0.11 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/mitchellh/copystructure v1.0.0 // indirect
github.com/mitchellh/mapstructure v1.2.2 // indirect
github.com/mitchellh/mapstructure v1.3.0 // indirect
github.com/mitchellh/reflectwalk v1.0.1 // indirect
github.com/pelletier/go-toml v1.7.0
github.com/muesli/combinator v0.3.0
github.com/pelletier/go-toml v1.8.0
github.com/pkg/diff v0.0.0-20190930165518-531926345625
github.com/rogpeppe/go-internal v1.6.0
github.com/sergi/go-diff v1.1.0
Expand All @@ -35,21 +37,24 @@ require (
github.com/spf13/cobra v1.0.0
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/spf13/viper v1.6.3
github.com/spf13/viper v1.7.0
github.com/stretchr/objx v0.2.0 // indirect
github.com/stretchr/testify v1.4.0
github.com/twpayne/go-shell v0.2.0
github.com/twpayne/go-vfs v1.4.0
github.com/twpayne/go-vfs v1.4.2
github.com/twpayne/go-vfsafero v1.0.0
github.com/twpayne/go-xdg/v3 v3.1.0
github.com/yuin/goldmark v1.1.28 // indirect
github.com/zalando/go-keyring v0.0.0-20200121091418-667557018717
go.etcd.io/bbolt v1.3.4
go.uber.org/multierr v1.5.0
golang.org/x/crypto v0.0.0-20200406173513-056763e48d71
golang.org/x/net v0.0.0-20200324143707-d3edc9973b7e // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d
golang.org/x/sys v0.0.0-20200420163511-1957bb5e6d1f
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9
google.golang.org/appengine v1.6.5 // indirect
gopkg.in/ini.v1 v1.55.0 // indirect
gopkg.in/yaml.v2 v2.2.8
gopkg.in/ini.v1 v1.56.0 // indirect
gopkg.in/yaml.v2 v2.3.0
)

replace github.com/go-git/go-git/v5 => github.com/twpayne/go-git/v5 v5.0.1-0.20200517130039-70111361e674
174 changes: 166 additions & 8 deletions go.sum

Large diffs are not rendered by default.

18 changes: 17 additions & 1 deletion internal/git/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,5 +232,21 @@ func ParseStatusPorcelainV2(output []byte) (*Status, error) {
return nil, ParseError(text)
}
}
return status, s.Err()
if err := s.Err(); err != nil {
return nil, err
}
if status.Empty() {
return nil, nil
}
return status, nil
}

// Empty returns true if s is empty.
func (s *Status) Empty() bool {
return s == nil || true &&
len(s.Ignored) == 0 &&
len(s.Ordinary) == 0 &&
len(s.RenamedOrCopied) == 0 &&
len(s.Unmerged) == 0 &&
len(s.Untracked) == 0
}
11 changes: 9 additions & 2 deletions internal/git/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@ func TestParseStatusPorcelainV2(t *testing.T) {
for _, tc := range []struct {
name string
outputStr string
expectedEmpty bool
expectedStatus *Status
}{
{
name: "empty",
outputStr: "",
expectedEmpty: true,
},
{
name: "added",
outputStr: "1 A. N... 000000 100644 100644 0000000000000000000000000000000000000000 cea5c3500651a923bacd80f960dd20f04f71d509 main.go\n",
Expand Down Expand Up @@ -53,7 +59,7 @@ func TestParseStatusPorcelainV2(t *testing.T) {
},
{
name: "update",
outputStr: "1 .M N... 100644 100644 100644 353dbbb3c29a80fb44d4e26dac111739d25294db 353dbbb3c29a80fb44d4e26dac111739d25294db cmd/gitvcs.go\n",
outputStr: "1 .M N... 100644 100644 100644 353dbbb3c29a80fb44d4e26dac111739d25294db 353dbbb3c29a80fb44d4e26dac111739d25294db cmd/git.go\n",
expectedStatus: &Status{
Ordinary: []OrdinaryStatus{
{
Expand All @@ -65,7 +71,7 @@ func TestParseStatusPorcelainV2(t *testing.T) {
MW: 0o100644,
HH: "353dbbb3c29a80fb44d4e26dac111739d25294db",
HI: "353dbbb3c29a80fb44d4e26dac111739d25294db",
Path: "cmd/gitvcs.go",
Path: "cmd/git.go",
},
},
},
Expand Down Expand Up @@ -159,6 +165,7 @@ func TestParseStatusPorcelainV2(t *testing.T) {
t.Run(tc.name, func(t *testing.T) {
actualStatus, err := ParseStatusPorcelainV2([]byte(tc.outputStr))
require.NoError(t, err)
assert.Equal(t, tc.expectedEmpty, actualStatus.Empty())
assert.Equal(t, tc.expectedStatus, actualStatus)
})
}
Expand Down
63 changes: 63 additions & 0 deletions next/cmd/add.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package cmd

import (
"github.com/spf13/cobra"

"github.com/twpayne/chezmoi/next/internal/chezmoi"
)

var addCmd = &cobra.Command{
Use: "add targets...",
Aliases: []string{"manage"},
Args: cobra.MinimumNArgs(1),
Short: "Add an existing file, directory, or symlink to the source state",
Long: mustGetLongHelp("add"),
Example: getExample("add"),
RunE: config.runAddCmd, // FIXME
Annotations: map[string]string{
modifiesSourceDirectory: "true",
},
}

type addCmdConfig struct {
autoTemplate bool
empty bool
encrypt bool
exact bool
include *chezmoi.IncludeBits
recursive bool
template bool
}

func init() {
rootCmd.AddCommand(addCmd)

persistentFlags := addCmd.PersistentFlags()
persistentFlags.BoolVarP(&config.add.autoTemplate, "autotemplate", "a", config.add.autoTemplate, "auto generate the template when adding files as templates")
persistentFlags.BoolVarP(&config.add.empty, "empty", "e", config.add.empty, "add empty files")
persistentFlags.BoolVar(&config.add.encrypt, "encrypt", config.add.encrypt, "encrypt files")
persistentFlags.BoolVarP(&config.add.exact, "exact", "x", config.add.exact, "add directories exactly")
persistentFlags.BoolVarP(&config.add.recursive, "recursive", "r", config.add.recursive, "recursive")
persistentFlags.BoolVarP(&config.add.template, "template", "T", config.add.template, "add files as templates")
}

func (c *Config) runAddCmd(cmd *cobra.Command, args []string) error {
destPathInfos, err := c.getDestPathInfos(args, c.add.recursive)
if err != nil {
return err
}

s, err := c.getSourceState()
if err != nil {
return err
}

return s.Add(c.system, c.DestDir, destPathInfos, &chezmoi.AddOptions{
AutoTemplate: c.add.autoTemplate,
Empty: c.add.empty,
Encrypt: c.add.encrypt,
Exact: c.add.exact,
Include: c.add.include,
Template: c.add.template,
})
}
37 changes: 37 additions & 0 deletions next/cmd/apply.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package cmd

import (
"github.com/spf13/cobra"

"github.com/twpayne/chezmoi/next/internal/chezmoi"
)

var applyCmd = &cobra.Command{
Use: "apply [targets...]",
Short: "Update the destination directory to match the target state",
Long: mustGetLongHelp("apply"),
Example: getExample("apply"),
RunE: config.runApplyCmd,
Annotations: map[string]string{
modifiesDestinationDirectory: "true",
},
}

type applyCmdConfig struct {
include *chezmoi.IncludeBits
recursive bool
}

func init() {
rootCmd.AddCommand(applyCmd)

persistentFlags := applyCmd.PersistentFlags()
persistentFlags.VarP(config.apply.include, "include", "i", "include entry types")
persistentFlags.BoolVarP(&config.apply.recursive, "recursive", "r", config.apply.recursive, "recursive")

markRemainingZshCompPositionalArgumentsAsFiles(applyCmd, 1)
}

func (c *Config) runApplyCmd(cmd *cobra.Command, args []string) error {
return c.applyArgs(c.system, c.DestDir, args, c.apply.include, c.apply.recursive)
}
81 changes: 81 additions & 0 deletions next/cmd/archive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package cmd

// FIXME add -j option to bzip2 compress output
// FIXME add -z option to gzip compress output

import (
"archive/tar"
"os/user"
"strconv"
"strings"
"time"

"github.com/spf13/cobra"

"github.com/twpayne/chezmoi/next/internal/chezmoi"
)

var archiveCmd = &cobra.Command{
Use: "archive [targets...]",
Short: "Generate a tar archive of the target state",
Long: mustGetLongHelp("archive"),
Example: getExample("archive"),
RunE: config.runArchiveCmd,
}

type archiveCmdConfig struct {
include *chezmoi.IncludeBits
recursive bool
}

func init() {
rootCmd.AddCommand(archiveCmd)

persistentFlags := archiveCmd.PersistentFlags()
persistentFlags.VarP(config.archive.include, "include", "i", "include entry types")
persistentFlags.BoolVarP(&config.archive.recursive, "recursive", "r", config.archive.recursive, "recursive")
}

func (c *Config) runArchiveCmd(cmd *cobra.Command, args []string) error {
sb := &strings.Builder{}
tarSystem := chezmoi.NewTARSystem(sb, tarHeaderTemplate())
if err := c.applyArgs(tarSystem, "", args, c.archive.include, c.archive.recursive); err != nil {
return err
}
if err := tarSystem.Close(); err != nil {
return err
}
return c.writeOutputString(sb.String())
}

// tarHeaderTemplate returns a tar.Header template populated with the current
// user and time.
func tarHeaderTemplate() tar.Header {
// Attempt to lookup the current user. Ignore errors because the default
// zero values are reasonable.
var (
uid int
gid int
Uname string
Gname string
)
if currentUser, err := user.Current(); err == nil {
uid, _ = strconv.Atoi(currentUser.Uid)
gid, _ = strconv.Atoi(currentUser.Gid)
Uname = currentUser.Username
if group, err := user.LookupGroupId(currentUser.Gid); err == nil {
Gname = group.Name
}
}

now := time.Now()
return tar.Header{
Uid: uid,
Gid: gid,
Uname: Uname,
Gname: Gname,
ModTime: now,
AccessTime: now,
ChangeTime: now,
}
}
Loading

0 comments on commit 9ea6695

Please sign in to comment.