Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.
Merged
1 change: 1 addition & 0 deletions lib/controllers/git-tab-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class GitTabController {
workspace={this.props.workspace}
commandRegistry={this.props.commandRegistry}
notificationManager={this.props.notificationManager}
initializeRepo={this.props.initializeRepo}
didSelectFilePath={this.props.didSelectFilePath}
didDiveIntoFilePath={this.props.didDiveIntoFilePath}
didSelectMergeConflictFile={this.props.didSelectMergeConflictFile}
Expand Down
8 changes: 8 additions & 0 deletions lib/controllers/root-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export default class RootController extends React.Component {
notificationManager: React.PropTypes.object.isRequired,
tooltips: React.PropTypes.object.isRequired,
confirm: React.PropTypes.func.isRequired,
activeProjectPath: React.PropTypes.string,
createRepositoryForProjectPath: React.PropTypes.func,
repository: React.PropTypes.object,
resolutionProgress: React.PropTypes.object,
statusBar: React.PropTypes.object,
Expand Down Expand Up @@ -151,6 +153,7 @@ export default class RootController extends React.Component {
commandRegistry={this.props.commandRegistry}
notificationManager={this.props.notificationManager}
repository={this.props.repository}
initializeRepo={this.initializeRepo}
resolutionProgress={this.props.resolutionProgress}
isAmending={this.state.amending}
didSelectFilePath={this.showFilePatchForPath}
Expand Down Expand Up @@ -238,6 +241,11 @@ export default class RootController extends React.Component {
}
}

@autobind
initializeRepo() {
this.props.createRepositoryForProjectPath(this.props.activeProjectPath);
}

@autobind
async showFilePatchForPath(filePath, stagingStatus, {activate, amending} = {}) {
if (!filePath) { return null; }
Expand Down
4 changes: 4 additions & 0 deletions lib/git-shell-out-strategy.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ export default class GitShellOutStrategy {
}
}

init() {
return this.exec(['init', this.workingDir]);
}

/**
* Staging/Unstaging files and patches and committing
*/
Expand Down
39 changes: 34 additions & 5 deletions lib/github-package.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,13 @@ export default class GithubPackage {
notificationManager={this.notificationManager}
tooltips={this.tooltips}
confirm={this.confirm}
activeProjectPath={this.activeProjectPath}
repository={this.getActiveRepository()}
resolutionProgress={this.getActiveResolutionProgress()}
statusBar={this.statusBar}
savedState={this.savedState.gitController}
githubEnabled={this.config.get('github.githubEnabled')}
createRepositoryForProjectPath={this.createRepositoryForProjectPath}
/>, this.element,
);
}
Expand Down Expand Up @@ -155,6 +157,22 @@ export default class GithubPackage {
await this.destroyModelsForPaths(Array.from(removed));
}

@autobind
async createRepositoryForProjectPath(projectPath) {
if (!projectPath) {
throw new Error('Must specify a project path to create a repository for');
}
await Repository.init(projectPath);
this.modelsByProjectPath.delete(projectPath);
this.modelPromisesByProjectPath.delete(projectPath);
const promises = this.cacheModelsForPaths([projectPath]);
await Promise.all([
promises.changeObserversStartedPromise,
promises.modelsPromise,
]);
await this.updateActiveModels();
}

@autobind
didChangeActivePaneItem() {
this.updateActiveModels();
Expand All @@ -168,6 +186,10 @@ export default class GithubPackage {
return this.initModelsPromise;
}

getActiveProjectPath() {
return this.activeProjectPath;
}

getActiveRepository() {
return this.activeRepository;
}
Expand All @@ -178,12 +200,13 @@ export default class GithubPackage {

async updateActiveModels() {
await this.initModelsPromise;
let nextActiveRepository, nextActiveResolutionProgress;
let nextActiveRepository, nextActiveResolutionProgress, nextActiveProjectPath;

const activeItem = this.workspace.getActivePaneItem();
if (activeItem && typeof activeItem.getPath === 'function') {
const projectPath = this.projectPathForItemPath(activeItem.getPath());
if (projectPath) {
nextActiveProjectPath = projectPath;
await Promise.all([
this.getRepositoryForWorkdirPath(projectPath).then(r => { nextActiveRepository = r; }),
this.getResolutionProgressForWorkdirPath(projectPath).then(rp => { nextActiveResolutionProgress = rp; }),
Expand All @@ -192,20 +215,24 @@ export default class GithubPackage {
} else {
nextActiveRepository = this.activeRepository;
nextActiveResolutionProgress = this.activeResolutionProgress;
nextActiveProjectPath = this.activeProjectPath;
}

if (activeItem instanceof FilePatchController) {
if (!activeItem.props.repository.isDestroyed()) {
nextActiveRepository = activeItem.props.repository;
nextActiveResolutionProgress = activeItem.props.resolutionProgress;
nextActiveProjectPath = nextActiveRepository.getWorkingDirectoryPath();
}
}

if (!activeItem && this.project.getPaths().length === 1) {
nextActiveRepository = await this.getRepositoryForWorkdirPath(this.project.getPaths()[0]);
nextActiveProjectPath = this.project.getPaths()[0];
nextActiveRepository = await this.getRepositoryForWorkdirPath(nextActiveProjectPath);
}

if (nextActiveRepository && nextActiveRepository !== this.activeRepository) {
this.activeProjectPath = nextActiveProjectPath || null;
this.setActiveModels(nextActiveRepository, nextActiveResolutionProgress);

if (this.destroyedRepositorySubscription) { this.destroyedRepositorySubscription.dispose(); }
Expand All @@ -215,9 +242,11 @@ export default class GithubPackage {
}
this.destroyedRepositorySubscription.dispose();
});
}

if (!nextActiveRepository) {
} else if (nextActiveRepository && this.activeProjectPath !== nextActiveProjectPath) {
this.activeProjectPath = nextActiveProjectPath || null;
this.rerender();
} else if (!nextActiveRepository) {
this.activeProjectPath = nextActiveProjectPath || null;
this.setActiveModels(null, null);
}
}
Expand Down
10 changes: 10 additions & 0 deletions lib/models/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ export default class Repository {
}
}

static async init(workingDirectoryPath, gitStrategy) {
const strategy = gitStrategy || CompositeGitStrategy.create(workingDirectoryPath);
await strategy.init(workingDirectoryPath);
return this.open(workingDirectoryPath, strategy);
}

static githubInfoFromRemote(remote) {
// proto login domain owner repo
const regex = /(?:.+:\/\/)?(?:.+@)?github\.com[:/]([^/]+)\/(.+)/;
Expand Down Expand Up @@ -122,6 +128,10 @@ export default class Repository {
/* eslint-enable no-console */
}

isGitRepository() {
return this.git.isGitRepository();
}

fetchStatusesForChangedFiles() {
return this.git.getStatusesForChangedFiles();
}
Expand Down
24 changes: 24 additions & 0 deletions lib/views/git-logo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/** @jsx etch.dom */
import etch from 'etch';

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#381 will get done one day, for reals... 😛


export default class GitLogo {
constructor() {
etch.initialize(this);
}

update() {}

render() {
/* eslint-disable */
return (
<svg width="114px" height="115px" viewBox="0 0 114 115">
<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
<g className="git-logo-path">
<path d="M111.78,51.977 L62.035,2.2381 C59.1728,-0.6267 54.5268,-0.6267 51.661,2.2381 L41.332,12.5681 L54.434,25.6701 C57.4799,24.6417 60.9711,25.33122 63.3979,27.7585 C65.8373,30.2009 66.5219,33.7219 65.4677,36.778 L78.0957,49.406 C81.1508,48.3532 84.6757,49.03338 87.1152,51.4772 C90.5258,54.8868 90.5258,60.4117 87.1152,63.8222 C83.7041,67.2338 78.1792,67.2338 74.7662,63.8222 C72.2017,61.2557 71.5674,57.4877 72.8663,54.328 L61.0893,42.551 L61.0883,73.542 C61.9198,73.95362 62.7045,74.503 63.3974,75.1929 C66.807,78.6021 66.807,84.126 63.3974,87.5409 C59.9868,90.95 54.4594,90.95 51.0524,87.5409 C47.6423,84.1263 47.6423,78.6024 51.0524,75.1929 C51.89515,74.35165 52.8703,73.7149 53.9108,73.2881 L53.9108,42.0091 C52.8698,41.5841 51.8958,40.9521 51.0518,40.1041 C48.4688,37.5231 47.8467,33.7321 49.1714,30.5602 L36.2554,17.6422 L2.1494,51.7472 C-0.7163,54.6142 -0.7163,59.2602 2.1494,62.1252 L51.8914,111.8642 C54.7552,114.729 59.3996,114.729 62.2674,111.8642 L111.7794,62.3602 C114.6442,59.494 114.6442,54.8466 111.7794,51.9812" id="Shape" />
</g>
</g>
</svg>
)
/* eslint-enable */
}
}
25 changes: 24 additions & 1 deletion lib/views/git-tab-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import etch from 'etch';
import {autobind} from 'core-decorators';

import StagingView from './staging-view';
import GitLogo from './git-logo';
import CommitViewController from '../controllers/commit-view-controller';

export default class GitTabView {
constructor(props) {
this.props = props;
etch.initialize(this);
this.repoCreationInProgress = false;

this.element.addEventListener('focusin', this.rememberLastFocus);

Expand All @@ -35,7 +37,15 @@ export default class GitTabView {
if (!this.props.repository) {
return (
<div className="github-Panel" tabIndex="-1">
<div ref="noRepoMessage" className="github-Panel no-repository">No repository for active pane item</div>
<div ref="noRepoMessage" className="github-Panel no-repository">
<div className="large-icon">
<GitLogo />
</div>
<div className="initialize-repo-description">Initialize this project directory with a Git repository</div>
<button onclick={this.initializeRepo} disabled={this.repoCreationInProgress} className="btn btn-primary">
{this.repoCreationInProgress ? 'Creating repository...' : 'Create repository'}
</button>
</div>
</div>
);
} else if (this.props.fetchInProgress) {
Expand Down Expand Up @@ -99,6 +109,19 @@ export default class GitTabView {
return etch.destroy(this);
}

@autobind
async initializeRepo(event) {
event.preventDefault();
this.repoCreationInProgress = true;
etch.update(this);
try {
await this.props.initializeRepo();
} finally {
this.repoCreationInProgress = false;
etch.update(this);
}
}

@autobind
blur() {
this.props.workspace.getActivePane().activate();
Expand Down
22 changes: 19 additions & 3 deletions styles/git-panel.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,27 @@
-webkit-user-select: none;
cursor: default;

&.is-loading,
&.no-repository {
&.is-loading, &.no-repository {
padding: @component-padding * 3;
text-align: center;
color: @text-color-subtle;
}

&.is-loading {
font-style: italic;
color: @text-color-subtle;
}

&.no-repository {
display: flex;
justify-content: center;
font-size: 1.25em;

> * {
margin: @component-padding 0;
}

.git-logo-path {
fill: mix(@base-background-color, @text-color, 66%); // 2/3 of bg color
}
}
}
Loading