Skip to content

Commit

Permalink
[#200] Add -c client_name option to the p4 command line
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahmad ATWI authored and mengdaming committed Feb 1, 2023
1 parent 7910299 commit 668f8fb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/vcs/p4/p4_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,17 @@ func (*p4Impl) CheckRemoteAccess() bool {
// traceP4 runs a p4 command and traces its output.
// The command is launched from the p4 root directory
func (p *p4Impl) traceP4(args ...string) error {
return p.traceP4Function(append([]string{"-d", p.GetRootDir()}, args...)...)
return p.traceP4Function(p.buildP4Args(args...)...)
}

// runP4 calls p4 command in a separate process and returns its output traces
// The command is launched from the p4 root directory
func (p *p4Impl) runP4(args ...string) (output []byte, err error) {
return p.runP4Function(append([]string{"-d", p.GetRootDir()}, args...)...)
return p.runP4Function(p.buildP4Args(args...)...)
}

func (p *p4Impl) buildP4Args(args ...string) []string {
return append([]string{"-d", p.GetRootDir(), "-c", p.clientName}, args...)
}

func (p *p4Impl) createChangeList(messages ...string) (*changeList, error) {
Expand Down
28 changes: 25 additions & 3 deletions src/vcs/p4/p4_impl_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func Test_p4_diff(t *testing.T) {
p, _ := newP4Impl(inMemoryDepotInit, "", true)
p.rootDir = ""
p.runP4Function = func(args ...string) (output []byte, err error) {
actualArgs = args[2:]
actualArgs = args[4:]
return []byte(tt.p4DiffOutput), tt.p4DiffError
}
fileDiffs, err := p.Diff()
Expand Down Expand Up @@ -324,7 +324,7 @@ func Test_p4_add(t *testing.T) {
var actualArgs []string
p, _ := newP4Impl(inMemoryDepotInit, "", true)
p.traceP4Function = func(args ...string) (err error) {
actualArgs = args[2:]
actualArgs = args[4:]
return tt.p4Error
}

Expand Down Expand Up @@ -403,7 +403,7 @@ func Test_p4_commit(t *testing.T) {
}
p.traceP4Function = func(args ...string) (err error) {
// Stub for the call to "p4 submit -c <cl_number>"
p4SubmitActualArgs = args[2:]
p4SubmitActualArgs = args[4:]
return tt.p4SubmitError
}

Expand Down Expand Up @@ -486,3 +486,25 @@ func Test_convert_to_p4_client_path(t *testing.T) {
})
}
}

func Test_p4_run_command_global_parameters(t *testing.T) {
p, _ := newP4Impl(inMemoryDepotInit, "/basedir", true)
p.clientName = "test_client"
p.runP4Function = func(params ...string) (out []byte, err error) {
return []byte(fmt.Sprintf("%v", params)), nil
}
output, _ := p.runP4()
assert.Equal(t, "[-d /basedir -c test_client]", string(output))
}

func Test_p4_trace_command_global_parameters(t *testing.T) {
p, _ := newP4Impl(inMemoryDepotInit, "/basedir", true)
p.clientName = "test_client"
var trace string
p.traceP4Function = func(params ...string) (err error) {
trace = fmt.Sprintf("%v", params)
return nil
}
_ = p.traceP4()
assert.Equal(t, "[-d /basedir -c test_client]", trace)
}

0 comments on commit 668f8fb

Please sign in to comment.