| 
									
										
										
										
											2020-04-20 13:00:10 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * @license | 
					
						
							| 
									
										
										
										
											2020-05-19 12:08:49 -07:00
										 |  |  |  * Copyright Google LLC All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2020-04-20 13:00:10 -07:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Use of this source code is governed by an MIT-style license that can be | 
					
						
							|  |  |  |  * found in the LICENSE file at https://angular.io/license
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import {getRepoBaseDir} from './config'; | 
					
						
							| 
									
										
										
										
											2020-06-05 11:03:32 +03:00
										 |  |  | import {exec} from './shelljs'; | 
					
						
							| 
									
										
										
										
											2020-04-20 13:00:10 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * A list of all files currently in the repo which have been modified since the provided sha. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * git diff | 
					
						
							|  |  |  |  * Deleted files (--diff-filter=d) are not included as they are not longer present in the repo | 
					
						
							|  |  |  |  * and can not be checked anymore. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * git ls-files | 
					
						
							|  |  |  |  * Untracked files (--others), which are not matched by .gitignore (--exclude-standard) | 
					
						
							|  |  |  |  * as they are expected to become tracked files. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export function allChangedFilesSince(sha = 'HEAD') { | 
					
						
							|  |  |  |   const diffFiles = gitOutputAsArray(`git diff --name-only --diff-filter=d ${sha}`); | 
					
						
							|  |  |  |   const untrackedFiles = gitOutputAsArray(`git ls-files --others --exclude-standard`); | 
					
						
							|  |  |  |   // Use a set to deduplicate the list as its possible for a file to show up in both lists.
 | 
					
						
							|  |  |  |   return Array.from(new Set([...diffFiles, ...untrackedFiles])); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-11 16:08:35 -07:00
										 |  |  | /** | 
					
						
							|  |  |  |  * A list of all staged files which have been modified. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Only added, created and modified files are listed as others (deleted, renamed, etc) aren't | 
					
						
							|  |  |  |  * changed or available as content to act upon. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | export function allStagedFiles() { | 
					
						
							|  |  |  |   return gitOutputAsArray(`git diff --staged --name-only --diff-filter=ACM`); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-20 13:00:10 -07:00
										 |  |  | export function allFiles() { | 
					
						
							|  |  |  |   return gitOutputAsArray(`git ls-files`); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | function gitOutputAsArray(cmd: string) { | 
					
						
							| 
									
										
										
										
											2020-06-05 11:03:32 +03:00
										 |  |  |   return exec(cmd, {cwd: getRepoBaseDir()}).split('\n').map(x => x.trim()).filter(x => !!x); | 
					
						
							| 
									
										
										
										
											2020-04-20 13:00:10 -07:00
										 |  |  | } |