Skip to content

Conversation

@croqaz
Copy link
Member

@croqaz croqaz commented Jul 16, 2019

Implemented simple Clone as discussed in #33

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling 12a6909 on cmd-clone into aa8ca57 on master.

@coveralls
Copy link

coveralls commented Jul 16, 2019

Coverage Status

Coverage remained the same at 100.0% when pulling 83ee232 on cmd-clone into aa8ca57 on master.

cmd.go Outdated
c.Args...,
)
clone.Lock()
defer clone.Unlock()
Copy link
Member

Choose a reason for hiding this comment

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

Why lock? clone hasn't been returned yet, so nothing else can be using it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me try. I remember testing with "-race" in similar cases and the tests were randomly failing because if race conditions.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok, I removed the lock.

// Clone clones a Cmd. All the options are transferred,
// but the state of the original object is lost.
// Cmd is one-use only, so if you need to re-start a Cmd,
// you need to Clone it.
Copy link
Member

@daniel-nichter daniel-nichter Jul 18, 2019

Choose a reason for hiding this comment

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

Does the cloned Cmd reuse the original's Stdout and Stderr channels?

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe I should document this another way, so it's more clear.

stdout, stderr and the status are dropped when cloning.
Only the public properties of the Cmd are transferred to the clone.
I'll add this ^ to the comment of the function.

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh wait, you mean the public Stdout and Stderr?
No, they shouldn't be transferred to the clone, because you want a fresh copy, ready to run from scratch. That's the point of the function.

Copy link
Member

Choose a reason for hiding this comment

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

Ah yes, right: fresh Stdout and Stderr. 👍

@croqaz croqaz merged commit 593c238 into master Jul 20, 2019
@croqaz croqaz deleted the cmd-clone branch July 20, 2019 23:18
daniel-nichter pushed a commit that referenced this pull request Nov 23, 2019
Implement Cmd.Clone
daniel-nichter added a commit that referenced this pull request Nov 23, 2019
* hfrappier-master:
  fix: ignore vendor directory. do not source control the same
  fix: deep framework reverted back to 1.0.1
  feat: upgrade deep framework
  refactor: remove vendor directory . should not be source controlled
  fix: remove redundant ls
  fix: list gopath in
  fix: install goveralls
  fix: set up modules
  fix: pull dependencies using go mod
  feat: remove dep
  feat: go mod
  Implement Cmd.Clone() (#35)
  Chores (#34)
  Updating typo syntax error
  Fix Gopkg.lock
  Test on go1.11, remove go1.8
  Test no output (back to 100% coverage)
  commands can be run in specified folder
  Fix no output: Buffered=false, Streaming=false
  Add basic windows support
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.

4 participants