Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions lib/views/file-patch-header-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {ItemTypePropType} from '../prop-types';
export default class FilePatchHeaderView extends React.Component {
static propTypes = {
relPath: PropTypes.string.isRequired,
newPath: PropTypes.string,
stagingStatus: PropTypes.oneOf(['staged', 'unstaged']),
isPartiallyStaged: PropTypes.bool,
hasHunks: PropTypes.bool.isRequired,
Expand Down Expand Up @@ -51,16 +52,26 @@ export default class FilePatchHeaderView extends React.Component {
if (this.props.itemType === ChangedFileItem) {
const status = this.props.stagingStatus;
return (
<span>{status[0].toUpperCase()}{status.slice(1)} Changes for {this.renderPath()}</span>
<span>{status[0].toUpperCase()}{status.slice(1)} Changes for {this.renderDisplayPath()}</span>
);
} else {
return this.renderPath();
return this.renderDisplayPath();
}
}

renderPath() {
const dirname = path.dirname(this.props.relPath);
const basename = path.basename(this.props.relPath);
renderDisplayPath() {
if (this.props.newPath && this.props.newPath !== this.props.relPath) {
const oldPath = this.renderPath(this.props.relPath);
const newPath = this.renderPath(this.props.newPath);
return <span>{oldPath} <span>→</span> {newPath}</span>;
} else {
return this.renderPath(this.props.relPath);
}
}

renderPath(filePath) {
const dirname = path.dirname(filePath);
const basename = path.basename(filePath);

if (dirname === '.') {
return <span className="gitub-FilePatchHeaderView-basename">{basename}</span>;
Expand Down
1 change: 1 addition & 0 deletions lib/views/multi-file-patch-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ export default class MultiFilePatchView extends React.Component {
<FilePatchHeaderView
itemType={this.props.itemType}
relPath={filePatch.getPath()}
newPath={filePatch.getStatus() === 'renamed' ? filePatch.getNewPath() : null}
stagingStatus={this.props.stagingStatus}
isPartiallyStaged={this.props.isPartiallyStaged}
hasHunks={filePatch.getHunks().length > 0}
Expand Down
7 changes: 7 additions & 0 deletions test/views/file-patch-header-view.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ describe('FilePatchHeaderView', function() {
assert.strictEqual(wrapper.find('.github-FilePatchView-title').text(), `Staged Changes for ${relPath}`);
});
});

it('renders title for a renamed file as oldPath → newPath', function() {
const oldPath = path.join('dir', 'a.txt');
const newPath = path.join('dir', 'b.txt');
const wrapper = shallow(buildApp({relPath: oldPath, newPath}));
assert.strictEqual(wrapper.find('.github-FilePatchView-title').text(), `${oldPath} → ${newPath}`);
});
});

describe('the button group', function() {
Expand Down