How to generate files conditionally when Git is selected?

To speed up my workflow with Qt Creator I create a custom project wizard in JSON format, as part of which I add a Summary page:

{
    "trDisplayName": "Project Management",
    "trShortTitle": "Summary",
    "typeId": "Summary"
}

Within the File generator I copy two files, i.e. .gitattributes and .gitignore, to the project directory:

{
    "source": ".gitattributes",
    "target": "%{TargetPath}/.gitattributes"
},
{
    "source": ".gitignore",
    "target": "%{TargetPath}/.gitignore"
}

Written like that, the files are always copied, even when Git is not selected as a version control system. I want the files to be copied only if they are needed.

The documentation for the Summary page says:

It sets VersionControl to the ID of the version control system in use

but no further info is added about the VersionControl variable and its values.

How to achieve the desired result?

1 answer

  • answered 2018-11-08 06:25 scopchanov

    I would suggest you the following solution:

    1. Assign a keyboard shortcut to the Wizard.Inspect command by going to

      Tools -> Options -> Environment -> Keyboard -> Shortcuts

    2. Start the custom wizard and navigate to the Summary page

    3. Press the selected schortcut

      This will open a window that lists all of the defined fields and variables in the wizard at the time the action was triggered. There you can find:

      Key            | Type    | Value | Eval
      VersionControl | QString | G.Git | G.Git
      
    4. Having this information, change the File generator code like this:

      {
          "source": ".gitattributes",
          "target": "%{TargetPath}/.gitattributes",
          "condition": "%{JS: '%{VersionControl}' === 'G.Git'}"
      },
      {
          "source": ".gitignore",
          "target": "%{TargetPath}/.gitignore",
          "condition": "%{JS: '%{VersionControl}' === 'G.Git'}"
      }