1

Here is my code I want to check out file to default changelist.

But I don't know my default changlist ID. How can I get it?

enter image description here

string command = "-c";
string f = filePath;

cmd = new P4Command(p4, "add", true, command, changelist.Id.ToString(), "-f", f);
rslt = cmd.Run();

f = filePath.Replace("@", "%40");

cmd = new P4Command(p4, "edit", true, command, changelist.Id.ToString(), f);
rslt = cmd.Run();

cmd = new P4Command(p4, "reopen", true, command, changelist.Id.ToString(), f);
rslt = cmd.Run();
Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
TimChang
  • 2,249
  • 13
  • 25

2 Answers2

2

No need to overcomplicate things -- it's called the "default" because it's literally the default when you don't specify a changelist. The "default changelist" isn't really a changelist; it's just a collection of files open on your client that don't belong to a numbered changelist yet.

C:\Perforce\test>p4 edit foo
//stream/main/foo#4 - opened for edit

C:\Perforce\test>p4 opened
//stream/main/foo#4 - edit default change (text)

I think in terms of your code this is:

cmd = new P4Command(p4, "edit", true, f);
rslt = cmd.Run();

Just leave off the "-c" (which stands for "changelist") and the changelist number.

If you need to move a file out of a numbered change and into the default change you can use the reopen command as described in p4 help reopen:

    reopen -- Change the filetype of an open file or move it to
              another changelist

    p4 reopen [-c changelist#] [-t filetype] file ...

        ...

        The target changelist must exist; you cannot create a changelist by
        reopening a file. To move a file to the default changelist, use
        'p4 reopen -c default'.
Samwise
  • 68,105
  • 3
  • 30
  • 44
  • yes it's work for "edit" , but it's not working on "reopen" ~ – TimChang Apr 15 '20 at 07:54
  • For a file that's *already* open in a numbered change, where you want to move it out of that change, you'd use `reopen -c default`, as described in `p4 help reopen`. Added that to the answer. For every command that opens a file (`add`, `edit`, `delete`, `integrate`, `copy`, `reconcile`, etc) you only need to specify `-c change` if you want to open it in a specific (existing) numbered change. – Samwise Apr 15 '20 at 14:13
0

I think I found answer. dont input changeId , just input keyword : "default" like this.

string command = "-c";
cmd = new P4Command(p4, "add", true, command, "default", "-f", f);
cmd = new P4Command(p4, "edit", true, command, "default", f);
cmd = new P4Command(p4, "reopen", true, command, "default", f);
TimChang
  • 2,249
  • 13
  • 25