Nx: merge-base fails in some forking scenarios

Created on 6 Jul 2020  路  2Comments  路  Source: nrwl/nx

I've found that some branches will fail our CI when running nx:affected commands
since nx uses git megre-base to find common ancestor to base branch (origin/master) or whatever
It is not a simple case of having the origin's history missing (we have a git fetch command in our CI script before use of nx)
It took me some time to understand why but I think it is because the branches were cut out of commits that did not enter master yet out of branches that were squashed in the merge so that there are no obvious common ancestors

apparently git has a solution for such - giving you the SHA before the forking point

git merge-base origin/master HEAD --fork-point
see this for more info

your code in getFilesUsingBaseAndHead src\command-line\shared.js:46

could be changed to make use of this flag and to stop errors like mine and possible other relevant issues (#2806 ? ) which have stack traces like this:
````

2020-07-06T08:32:28.4875058Z Error: Command failed: git merge-base origin/master HEAD
2020-07-06T08:32:28.4875233Z at checkExecSyncError (child_process.js:621:11)
2020-07-06T08:32:28.4875426Z at Object.execSync (child_process.js:657:15)
2020-07-06T08:32:28.4877692Z at getFilesUsingBaseAndHead (C:\TfsAgent_work\47\s\node_modules\@nrwl\workspace\src\command-line\shared.js:46:39)
2020-07-06T08:32:28.4878038Z at Object.parseFiles (C:\TfsAgent_work\47\s\node_modules\@nrwl\workspace\src\command-line\shared.js:31:20)
2020-07-06T08:32:28.4878424Z at Object.affected (C:\TfsAgent_work\47\s\node_modules\@nrwl\workspace\src\command-line\affected.js:19:108)
2020-07-06T08:32:28.4878782Z at Object.handler (C:\TfsAgent_work\47\s\node_modules\@nrwl\workspace\src\command-line\nx-commands.js:46:142)
2020-07-06T08:32:28.4879061Z at Object.runCommand (C:\TfsAgent_work\47\s\node_modules\@nrwl\workspace\node_modules\yargs\lib\command.js:235:44)
2020-07-06T08:32:28.4879352Z at Object.parseArgs [as _parseArgs] (C:\TfsAgent_work\47\s\node_modules\@nrwl\workspace\node_modules\yargs\yargs.js:1022:30)
2020-07-06T08:32:28.4879660Z at Object.get [as argv] (C:\TfsAgent_work\47\s\node_modules\@nrwl\workspace\node_modules\yargs\yargs.js:965:21)
2020-07-06T08:32:28.4879922Z at Object.initLocal (C:\TfsAgent_work\47\s\node_modules\@nrwl\cli\lib\init-local.js:22:13) {
2020-07-06T08:32:28.4880115Z status: 1,
2020-07-06T08:32:28.4881988Z signal: null,
2020-07-06T08:32:28.4882696Z output: [ null, 2020-07-06T08:32:28.4882971Z pid: 2776,
2020-07-06T08:32:28.4883130Z stdout: 2020-07-06T08:32:28.4883320Z stderr: 2020-07-06T08:32:28.4883463Z }
2020-07-06T08:32:28.5520622Z error Command failed with exit code 1.
````

Current Behavior


nx affected commands fails with stack trace like above

Expected Behavior


nx affected commands will work even for branches forked from unresolved commits

Steps to Reproduce


make a branch (1), commit some code and fork to another branch(2), then return to the first branch(1), rebase to squash all commits and merge to master. checkout the 2nd branch(2), use nx affected




Failure Logs


see above

Environment


@nrwl/angular : 9.5.1
@nrwl/cli : 9.5.1
@nrwl/cypress : 9.5.1
@nrwl/eslint-plugin-nx : Not Found
@nrwl/express : Not Found
@nrwl/jest : 9.5.1
@nrwl/linter : Not Found
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/react : Not Found
@nrwl/schematics : Not Found
@nrwl/tao : 9.5.1
@nrwl/web : Not Found
@nrwl/workspace : 9.5.1
typescript : 3.7.5

core enhancement

Most helpful comment

We have encountered the same problem. What is your git depth set to on the CI?

All 2 comments

We have encountered the same problem. What is your git depth set to on the CI?

actually I don't think we have configured maximum depth, the clone was not shallow one and therefor has the whole history depth
The repo is big, but not huge, it has 22140 commits

Was this page helpful?
0 / 5 - 0 ratings