Skip to content

Commit

Permalink
Git - handle --intent-to-add on a renamed resource (#183307)
Browse files Browse the repository at this point in the history
  • Loading branch information
lszomoru authored May 24, 2023
1 parent 3646465 commit e7e97f8
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 4 deletions.
1 change: 1 addition & 0 deletions extensions/git/src/api/api1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,7 @@ function getStatus(status: Status): string {
case Status.UNTRACKED: return 'UNTRACKED';
case Status.IGNORED: return 'IGNORED';
case Status.INTENT_TO_ADD: return 'INTENT_TO_ADD';
case Status.INTENT_TO_RENAME: return 'INTENT_TO_RENAME';
case Status.ADDED_BY_US: return 'ADDED_BY_US';
case Status.ADDED_BY_THEM: return 'ADDED_BY_THEM';
case Status.DELETED_BY_US: return 'DELETED_BY_US';
Expand Down
1 change: 1 addition & 0 deletions extensions/git/src/api/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const enum Status {
UNTRACKED,
IGNORED,
INTENT_TO_ADD,
INTENT_TO_RENAME,

ADDED_BY_US,
ADDED_BY_THEM,
Expand Down
2 changes: 1 addition & 1 deletion extensions/git/src/decorationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ class GitDecorationProvider implements FileDecorationProvider {
bucket.set(r.rightUri.toString(), decoration);
}

if (r.type === Status.INDEX_RENAMED) {
if (r.type === Status.INDEX_RENAMED || r.type === Status.INTENT_TO_RENAME) {
bucket.set(r.resourceUri.toString(), decoration);
}
}
Expand Down
2 changes: 1 addition & 1 deletion extensions/git/src/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ export class GitStatusParser {
// space
i++;

if (entry.x === 'R' || entry.x === 'C') {
if (entry.x === 'R' || entry.y === 'R' || entry.x === 'C') {
lastIndex = raw.indexOf('\0', i);

if (lastIndex === -1) {
Expand Down
15 changes: 13 additions & 2 deletions extensions/git/src/repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export class Resource implements SourceControlResourceState {
case Status.UNTRACKED: return l10n.t('Untracked');
case Status.IGNORED: return l10n.t('Ignored');
case Status.INTENT_TO_ADD: return l10n.t('Intent to Add');
case Status.INTENT_TO_RENAME: return l10n.t('Intent to Rename');
case Status.BOTH_DELETED: return l10n.t('Conflict: Both Deleted');
case Status.ADDED_BY_US: return l10n.t('Conflict: Added By Us');
case Status.DELETED_BY_THEM: return l10n.t('Conflict: Deleted By Them');
Expand All @@ -71,7 +72,7 @@ export class Resource implements SourceControlResourceState {

@memoize
get resourceUri(): Uri {
if (this.renameResourceUri && (this._type === Status.MODIFIED || this._type === Status.DELETED || this._type === Status.INDEX_RENAMED || this._type === Status.INDEX_COPIED)) {
if (this.renameResourceUri && (this._type === Status.MODIFIED || this._type === Status.DELETED || this._type === Status.INDEX_RENAMED || this._type === Status.INDEX_COPIED || this._type === Status.INTENT_TO_RENAME)) {
return this.renameResourceUri;
}

Expand Down Expand Up @@ -136,6 +137,7 @@ export class Resource implements SourceControlResourceState {
case Status.UNTRACKED: return Resource.Icons[theme].Untracked;
case Status.IGNORED: return Resource.Icons[theme].Ignored;
case Status.INTENT_TO_ADD: return Resource.Icons[theme].Added;
case Status.INTENT_TO_RENAME: return Resource.Icons[theme].Renamed;
case Status.BOTH_DELETED: return Resource.Icons[theme].Conflict;
case Status.ADDED_BY_US: return Resource.Icons[theme].Conflict;
case Status.DELETED_BY_THEM: return Resource.Icons[theme].Conflict;
Expand Down Expand Up @@ -193,6 +195,7 @@ export class Resource implements SourceControlResourceState {
case Status.DELETED:
return 'D';
case Status.INDEX_RENAMED:
case Status.INTENT_TO_RENAME:
return 'R';
case Status.UNTRACKED:
return 'U';
Expand Down Expand Up @@ -230,6 +233,7 @@ export class Resource implements SourceControlResourceState {
return new ThemeColor('gitDecoration.addedResourceForeground');
case Status.INDEX_COPIED:
case Status.INDEX_RENAMED:
case Status.INTENT_TO_RENAME:
return new ThemeColor('gitDecoration.renamedResourceForeground');
case Status.UNTRACKED:
return new ThemeColor('gitDecoration.untrackedResourceForeground');
Expand Down Expand Up @@ -520,6 +524,7 @@ class ResourceCommandResolver {
case Status.INDEX_MODIFIED:
case Status.INDEX_RENAMED:
case Status.INDEX_ADDED:
case Status.INTENT_TO_RENAME:
return toGitUri(resource.original, 'HEAD');

case Status.MODIFIED:
Expand Down Expand Up @@ -554,7 +559,8 @@ class ResourceCommandResolver {
case Status.MODIFIED:
case Status.UNTRACKED:
case Status.IGNORED:
case Status.INTENT_TO_ADD: {
case Status.INTENT_TO_ADD:
case Status.INTENT_TO_RENAME: {
const uriString = resource.resourceUri.toString();
const [indexStatus] = this.repository.indexGroup.resourceStates.filter(r => r.resourceUri.toString() === uriString);

Expand Down Expand Up @@ -599,6 +605,10 @@ class ResourceCommandResolver {
case Status.UNTRACKED:
return l10n.t('{0} (Untracked)', basename);

case Status.INTENT_TO_ADD:
case Status.INTENT_TO_RENAME:
return l10n.t('{0} (Intent to add)', basename);

default:
return '';
}
Expand Down Expand Up @@ -2177,6 +2187,7 @@ export class Repository implements Disposable {
case 'M': workingTreeGroup.push(new Resource(this.resourceCommandResolver, ResourceGroupType.WorkingTree, uri, Status.MODIFIED, useIcons, renameUri)); break;
case 'D': workingTreeGroup.push(new Resource(this.resourceCommandResolver, ResourceGroupType.WorkingTree, uri, Status.DELETED, useIcons, renameUri)); break;
case 'A': workingTreeGroup.push(new Resource(this.resourceCommandResolver, ResourceGroupType.WorkingTree, uri, Status.INTENT_TO_ADD, useIcons, renameUri)); break;
case 'R': workingTreeGroup.push(new Resource(this.resourceCommandResolver, ResourceGroupType.WorkingTree, uri, Status.INTENT_TO_RENAME, useIcons, renameUri)); break;
}

return undefined;
Expand Down
1 change: 1 addition & 0 deletions extensions/github/src/typings/git.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ export const enum Status {
UNTRACKED,
IGNORED,
INTENT_TO_ADD,
INTENT_TO_RENAME,

ADDED_BY_US,
ADDED_BY_THEM,
Expand Down

0 comments on commit e7e97f8

Please sign in to comment.