Side effects are running/applying changes concurrently and on success moving old "current" tag
( ctx context.Context, mo *SingleMethodObj, currentState plumbing.Hash, desiredState plumbing.Hash, targetPath string, tags *[]string, )
| 95 | |
| 96 | // Side effects are running/applying changes concurrently and on success moving old "current" tag |
| 97 | func (fc *FetchitConfig) Apply( |
| 98 | ctx context.Context, |
| 99 | mo *SingleMethodObj, |
| 100 | currentState plumbing.Hash, |
| 101 | desiredState plumbing.Hash, |
| 102 | targetPath string, |
| 103 | tags *[]string, |
| 104 | ) error { |
| 105 | if desiredState.IsZero() { |
| 106 | return errors.New("Cannot run Apply if desired state is empty") |
| 107 | } |
| 108 | directory := filepath.Base(mo.Target.Url) |
| 109 | |
| 110 | currentTree, err := getTreeFromHash(directory, currentState) |
| 111 | if err != nil { |
| 112 | return utils.WrapErr(err, "Error getting tree from hash %s", currentState) |
| 113 | } |
| 114 | |
| 115 | desiredTree, err := getTreeFromHash(directory, desiredState) |
| 116 | if err != nil { |
| 117 | return utils.WrapErr(err, "Error getting tree from hash %s", desiredState) |
| 118 | } |
| 119 | |
| 120 | changeMap, err := getFilteredChangeMap(directory, targetPath, currentTree, desiredTree, tags) |
| 121 | if err != nil { |
| 122 | return utils.WrapErr(err, "Error getting filtered change map from %s to %s", currentState, desiredState) |
| 123 | } |
| 124 | |
| 125 | err = fc.runChangesConcurrent(ctx, mo, changeMap) |
| 126 | if err != nil { |
| 127 | return utils.WrapErr(err, "Error applying change from %s to %s for path %s in %s", |
| 128 | currentState, desiredState, targetPath, directory, |
| 129 | ) |
| 130 | } |
| 131 | |
| 132 | return nil |
| 133 | } |
| 134 | |
| 135 | func getTreeFromHash(directory string, hash plumbing.Hash) (*object.Tree, error) { |
| 136 | if hash.IsZero() { |
no test coverage detected