Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repository is not clean after cli/core update #14600

Closed
drew-thompson opened this issue May 30, 2019 · 19 comments
Closed

Repository is not clean after cli/core update #14600

drew-thompson opened this issue May 30, 2019 · 19 comments

Comments

@drew-thompson
Copy link

drew-thompson commented May 30, 2019

🐞 Bug report

Command (mark with an x)

- [ ] new
- [ ] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [x] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Is this a regression?

No, this issue only applies to updating from version 7 to 8.

Description

I'm unable to update @angular/material when following the update instructions for a basic application. After updating the project with ng update @angular/cli @angular/core, I'm receiving an error when attempting to run ng update @angular/material.

🔬 Minimal Reproduction

  1. Create a new application with the CLI v7.3.9 ng new update-test --routing --style scss
  2. cd into the app's root directory and add angular material ng add @angular/material
  3. Select the Indigo/Pink theme, yes to HammerJS and browser animations
  4. Begin the update process to v8 ng update @angular/cli @angular/core
  5. Update material ng update @angular/material

The error should appear after entering the command in step 5 and before the schematic executes.

🔥 Exception or Error




Repository is not clean.  Please commit or stash any changes before updating.

🌍 Your Environment




     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/
    

Angular CLI: 8.0.0
Node: 12.3.1
OS: darwin x64
Angular: 8.0.0
... animations, cli, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.800.0
@angular-devkit/build-angular     0.800.0
@angular-devkit/build-optimizer   0.800.0
@angular-devkit/build-webpack     0.800.0
@angular-devkit/core              8.0.0
@angular-devkit/schematics        8.0.0
@angular/cdk                      7.3.7
@angular/material                 7.3.7
@ngtools/webpack                  8.0.0
@schematics/angular               8.0.0
@schematics/update                0.800.0
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.30.0

Anything else relevant?

I was able to reproduce on both Windows 10 and OS X.

@drew-thompson drew-thompson changed the title Repository is not Clean After CLI/Core Update Repository is not clean after cli/core update May 30, 2019
@clydin
Copy link
Member

clydin commented May 30, 2019

This is expected and intentional. The git repository has uncommitted changes. If the changes aren’t committed before the update then there would be a risk that the update may fail (or succeed but leave the application in a broken state) and there may be no easy way to revert the bad changes introduced by the update.

@clydin clydin closed this as completed May 30, 2019
@rodlourenco
Copy link

rodlourenco commented Jun 3, 2019

I have the same issue. And it happens cause my angular project is not in the main git folder. And there's nothing to commit in the entire folder.
image

@jbethke
Copy link

jbethke commented Jun 3, 2019

FYI, there is an allow-dirty flag to bypass the repo check.

ng update @angular/cli @angular/core --allow-dirty

@clydin
Copy link
Member

clydin commented Jun 11, 2019

@rodlourenco The next patch release will account for your use case and only consider files inside the Angular workspace.

@cjonasw
Copy link

cjonasw commented Jul 3, 2019

FYI, there is an allow-dirty flag to bypass the repo check.

ng update @angular/cli @angular/core --allow-dirty

This doesn't seem to exist anymore in 8.0.0, although it's still in their documentation, ng update --help has no mention of it and I've tried --allow-dirty/--allowDirty. I unfortunately had to commit and then undo that commit.

@Splaktar
Copy link
Member

Splaktar commented Jul 5, 2019

@cjonasw it was only introduced in 8.1.0-beta.0 and finally released in 8.1.0.

@clydin
Copy link
Member

clydin commented Jul 5, 2019

It’s also in 8.0.1+.
8.0.3+ has the fix for more complex git repositories that contain the Angular project in a nested directory.

@jmpreston
Copy link

I just updated to 8.1.1 from 7 and this message and stopping the update is a huge pain. Please make the need for --allow-dirty to go away. A simple message with y/n is good enough. Actually, the whole update process this time has been a train wreak of crashing updates. Not the place for that discussion here but it hasn't been this bad since RC days.

@dcolakchile
Copy link

Why is this issue closed when it's not fixed?

I do not understand.

@Splaktar
Copy link
Member

@dcolakchile it's unclear what you mean. #14600 (comment) details how this is intended.

It would be nice if there was an angular.json option to set your updates to always --allow-dirty as I have to use it many times per week at this point. However, so far requests for that feature have not been met with much interest.

@tamusjroyce
Copy link

tamusjroyce commented Sep 17, 2019

Or instead of saying "Please commit or stash any changes before updating."...which is untrue because I have nothing to commit or stash... display either how to actually resolve the issue (--allow-dirty) or where to go to find the correct information.

p.s. when using --allow-dirty, it suggested I need to use --force. When --allow-dirty is used, it correctly suggests how to resolve any blockers.

@Splaktar
Copy link
Member

@clydin can we please reopen this and get information about the --allow-dirty option added to the error message?

It would also be nice to add a workspace option to always allow dirty with ng update.

@clydin
Copy link
Member

clydin commented Sep 18, 2019

The option is intentionally not mentioned as it is not the correct step to remedy the situation and should only be used in extreme situations. The proper remedy is already specified within the error message (Please commit or stash any changes before updating). This will become even more relevant with 9.0 wherein each migration will be contained within a separate commit due to the larger volume and scope of the upcoming migrations.

As to the check itself, it is based on a call to git status. If git is saying the repository is not clean, barring a defect in git's change tracking (which is unlikely), the repository is most likely not clean.

@Splaktar
Copy link
Member

Splaktar commented Sep 18, 2019

I have not yet encountered a situation where I want to make a commit for each migration. I generally have to run ng update @angular/cli and then ng update @angular/material --allow-dirty and then possibly one more update. I don't want to make separate commits per migration. I only want to commit after the migrations are done, the project is building, tests are passing, and any other manual fixes or adjustments need to be made.

Encouraging a behavior that is an opinion of correctness is fine, but forcing a behavior that people do not want to follow is ... unfortunate. There are more than one "right" way to do most things.

@msbit
Copy link
Contributor

msbit commented Oct 4, 2019

@clydin

The proper remedy is already specified within the error message (Please commit or stash any changes before updating).

I think half the issue with this message, from what I can tell, is the use of clean, as an antonym of dirty which is a pretty well understood term in Git:

that is, your modified tracked files and staged changes

In my situation, there are no files to commit or stash, as all the files are untracked:

$ find . -type f | grep -v -e node_modules/ -e .git/ | sort
./a
./b
./c
./module-one/.gitignore
./module-one/README.md
./module-one/angular.json
./module-one/browserslist
./module-one/package-lock.json
./module-one/package.json
./module-one/src/app/app.component.ts
./module-one/src/app/app.module.ts
./module-one/src/assets/.gitkeep
./module-one/src/environments/environment.prod.ts
./module-one/src/environments/environment.ts
./module-one/src/favicon.ico
./module-one/src/index.html
./module-one/src/main.ts
./module-one/src/polyfills.ts
./module-one/src/styles.css
./module-one/tsconfig.app.json
./module-one/tsconfig.json
./module-two/a
./module-two/b
./module-two/c

$ pushd module-one

$ git status --porcelain
?? b
?? c
?? module-two/b
?? module-two/c

$ git stash
No local changes to save

$ git commit
On branch master
Untracked files:
	../b
	../c
	../module-two/b
	../module-two/c

nothing added to commit but untracked files present

$ ng update --all true
Repository is not clean.  Please commit or stash any changes before updating.

What's more, there are no untracked files (let alone modified files) in the Angular application directory.

@clydin
Copy link
Member

clydin commented Oct 4, 2019

The check is a call to “git status —porcelain” and a filter of any files that are outside the workspace root. If git status says the repository is dirty then it is considered not clean. Doing any kind of major change in such a state is not recommended.

https://mirrors.edge.kernel.org/pub/software/scm/git/docs/gitglossary.html#def_dirty

@msbit
Copy link
Contributor

msbit commented Oct 5, 2019

@clydin from your link:

A working tree is said to be "dirty" if it contains modifications which have not been committed to the current branch.

The working tree doesn't contain any modifications, just untracked files.

Also, this doesn't really address the logic behind requiring no untracked files anywhere within the git working tree, if the Angular project is under a subdirectory. Surely the update can be performed without considering anything outside the Angular project?

@msbit
Copy link
Contributor

msbit commented Oct 5, 2019

@clydin in case you were interested, this is the method I used to get the directory structure above, and to illustrate the state that the repository is in:

pushd $(mktemp -d)
git init .
touch a b c
ng new module-one --minimal --style css --routing false
mkdir module-two
touch module-two/{a,b,c}
git add a module-one module-two/a
git commit -m 'initial'
pushd module-one
ng update --all true

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Nov 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants