Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow re-initialization with differen value of --with-forks #196

Merged
merged 2 commits into from
Aug 8, 2019
Merged

Disallow re-initialization with differen value of --with-forks #196

merged 2 commits into from
Aug 8, 2019

Conversation

smacker
Copy link
Contributor

@smacker smacker commented Aug 6, 2019

Fix #109 (we have a separate issue for status command now)

  • Switching --with-forks flag for already initialized working directory
    is unsupported because gitcollector/ghsync can't delete data. Also user
    might have some pre-computed data that would cause charts to fail if
    forks are removed. The only safe way to switch the flag is to prune and
    recreate. Automatic prune might be very unexpected for a user so it
    shows an error and asks the user to run prune manually.

  • Implement envFile decoder, it will be useful for showing status later
    as well

Example of the error when an org was already initialized without forks:

$ go run cmd/sourced/main.go init orgs golang-migrate --with-forks
initialization failed: workdir was previously initialized with a different value for forks support
Cannot perform this action, full re-initialization is needed, run 'prune' command first
exit status 1

@smacker smacker requested a review from a team August 6, 2019 11:45
@smacker smacker changed the title Disallow forks flag switch Disallow re-initialization with differen value of --with-forks Aug 6, 2019
Copy link
Contributor

@dpordomingo dpordomingo left a comment

Choose a reason for hiding this comment

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

LGTM
I didn't perform a really deeeeep review but I like the idea and code.

- Switching --with-forks flag for already initialized working directory
is unsupported because gitcollector/ghsync can't delete data. Also user
might have some pre-computed data that would cause charts to fail if
forks are removed. The only safe way to switch the flag is to prune and
recreate. Automatic prune might be very unexpected for a user so it
shows an error and asks the user to run prune manually.

- Implement envFile decoder, it will be useful for showing status later
as well

Example of the error when an org was already initialized without forks:
```
$ go run cmd/sourced/main.go init orgs golang-migrate --with-forks
initialization failed: workdir was previously initialized with a different value for forks support
Cannot perform this action, full re-initialization is needed, run 'prune' command first
exit status 1
```

Signed-off-by: Maxim Sukharev <[email protected]>
@@ -114,7 +159,7 @@ type envFile struct {
WithForks bool
}

func (f *envFile) String() string {
func (f *envFile) MarshalEnv() ([]byte, error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

why not simply Marshal/Unmarshal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be in line with std lib and other serialization libs.

}

line := strings.SplitN(scanner.Text(), "=", 2)
value := line[1]
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should check the length of line.
A line like # A comment will panic.

It should not fail with the current contents, but just in case we may change the contents later, or a user may edit this manually...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed by skipping lines without =, thanks

@smacker smacker merged commit ecc9c81 into src-d:master Aug 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to remove forks from the analysis
3 participants