Skip to content

Commit

Permalink
fix(dev): deletion of untracked files not taken into account
Browse files Browse the repository at this point in the history
  • Loading branch information
alexey-igrychev committed Oct 4, 2021
1 parent b737a50 commit c67a956
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
1 change: 0 additions & 1 deletion pkg/git_repo/local.go
Expand Up @@ -85,7 +85,6 @@ func OpenLocalRepo(ctx context.Context, name, workTreeDir string, opts OpenLocal
l.headCommit,
true_git.SyncSourceWorktreeWithServiceBranchOptions{
ServiceBranchPrefix: opts.ServiceBranchOptions.Prefix,
GlobIncludeList: gitStatusResult.PathList(),
GlobExcludeList: opts.ServiceBranchOptions.GlobExcludeList,
},
)
Expand Down
28 changes: 10 additions & 18 deletions pkg/true_git/service_branch.go
Expand Up @@ -16,7 +16,6 @@ import (

type SyncSourceWorktreeWithServiceBranchOptions struct {
ServiceBranchPrefix string
GlobIncludeList []string
GlobExcludeList []string
}

Expand All @@ -43,7 +42,7 @@ func SyncSourceWorktreeWithServiceBranch(ctx context.Context, gitDir, sourceWork
}

branchName := fmt.Sprintf("%s%s", opts.ServiceBranchPrefix, commit)
resultCommit, err = syncWorktreeWithServiceWorktreeBranch(ctx, sourceWorktreeDir, serviceWorktreeDir, commit, branchName, opts.GlobIncludeList, opts.GlobExcludeList)
resultCommit, err = syncWorktreeWithServiceWorktreeBranch(ctx, sourceWorktreeDir, serviceWorktreeDir, commit, branchName, opts.GlobExcludeList)
if err != nil {
return fmt.Errorf("unable to sync worktree with service branch %q: %s", branchName, err)
}
Expand All @@ -56,7 +55,7 @@ func SyncSourceWorktreeWithServiceBranch(ctx context.Context, gitDir, sourceWork
return resultCommit, nil
}

func syncWorktreeWithServiceWorktreeBranch(ctx context.Context, sourceWorktreeDir, serviceWorktreeDir, sourceCommit, branchName string, globIncludeList, globExcludeList []string) (string, error) {
func syncWorktreeWithServiceWorktreeBranch(ctx context.Context, sourceWorktreeDir, serviceWorktreeDir, sourceCommit, branchName string, globExcludeList []string) (string, error) {
serviceBranchHeadCommit, err := getOrPrepareServiceBranchHeadCommit(ctx, serviceWorktreeDir, sourceCommit, branchName)
if err != nil {
return "", fmt.Errorf("unable to get or prepare service branch head commit: %s", err)
Expand All @@ -71,7 +70,7 @@ func syncWorktreeWithServiceWorktreeBranch(ctx context.Context, sourceWorktreeDi
return "", fmt.Errorf("unable to revert excluded changes in service worktree index: %q", err)
}

newChangesExist, err := checkNewChangesInSourceWorktreeDir(ctx, sourceWorktreeDir, serviceWorktreeDir, globIncludeList, globExcludeList)
newChangesExist, err := checkNewChangesInSourceWorktreeDir(ctx, sourceWorktreeDir, serviceWorktreeDir, globExcludeList)
if err != nil {
return "", fmt.Errorf("unable to check new changes in source worktree: %s", err)
}
Expand All @@ -80,7 +79,7 @@ func syncWorktreeWithServiceWorktreeBranch(ctx context.Context, sourceWorktreeDi
return serviceBranchHeadCommit, nil
}

if err = addNewChangesInServiceWorktreeDir(ctx, sourceWorktreeDir, serviceWorktreeDir, globIncludeList, globExcludeList); err != nil {
if err = addNewChangesInServiceWorktreeDir(ctx, sourceWorktreeDir, serviceWorktreeDir, globExcludeList); err != nil {
return "", fmt.Errorf("unable to add new changes in service worktree: %s", err)
}

Expand Down Expand Up @@ -148,21 +147,21 @@ func revertExcludedChangesInServiceWorktreeIndex(ctx context.Context, sourceWork
return true, nil
}

func checkNewChangesInSourceWorktreeDir(ctx context.Context, sourceWorktreeDir string, serviceWorktreeDir string, globIncludeList, globExcludeList []string) (bool, error) {
output, err := runGitAddCmd(ctx, sourceWorktreeDir, serviceWorktreeDir, globIncludeList, globExcludeList, true)
func checkNewChangesInSourceWorktreeDir(ctx context.Context, sourceWorktreeDir string, serviceWorktreeDir string, globExcludeList []string) (bool, error) {
output, err := runGitAddCmd(ctx, sourceWorktreeDir, serviceWorktreeDir, globExcludeList, true)
if err != nil {
return false, err
}

return len(output.Bytes()) != 0, nil
}

func addNewChangesInServiceWorktreeDir(ctx context.Context, sourceWorktreeDir string, serviceWorktreeDir string, globIncludeList, globExcludeList []string) error {
_, err := runGitAddCmd(ctx, sourceWorktreeDir, serviceWorktreeDir, globIncludeList, globExcludeList, false)
func addNewChangesInServiceWorktreeDir(ctx context.Context, sourceWorktreeDir string, serviceWorktreeDir string, globExcludeList []string) error {
_, err := runGitAddCmd(ctx, sourceWorktreeDir, serviceWorktreeDir, globExcludeList, false)
return err
}

func runGitAddCmd(ctx context.Context, sourceWorktreeDir string, serviceWorktreeDir string, globIncludeList []string, globExcludeList []string, dryRun bool) (*bytes.Buffer, error) {
func runGitAddCmd(ctx context.Context, sourceWorktreeDir string, serviceWorktreeDir string, globExcludeList []string, dryRun bool) (*bytes.Buffer, error) {
gitAddArgs := []string{
"--work-tree",
sourceWorktreeDir,
Expand All @@ -175,14 +174,7 @@ func runGitAddCmd(ctx context.Context, sourceWorktreeDir string, serviceWorktree

var pathSpecList []string
{
if len(globIncludeList) == 0 {
pathSpecList = append(pathSpecList, ":.")
} else {
for _, glob := range globIncludeList {
pathSpecList = append(pathSpecList, ":"+glob)
}
}

pathSpecList = append(pathSpecList, ":.")
for _, glob := range globExcludeList {
pathSpecList = append(pathSpecList, ":!"+glob)
}
Expand Down

0 comments on commit c67a956

Please sign in to comment.