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

Feat/git behind #469

Merged
merged 1 commit into from
Jul 12, 2024
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
4 changes: 2 additions & 2 deletions apps/ui/src/components/GitToolBar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<span class="badge" v-if="gitStats.headAhead > 0">
{{ gitStats.headAhead }} commits ahead remote
</span>
<span class="badge" v-if="gitStats.headAhead < 0">
{{ -gitStats.headAhead }} commits behind remote
<span class="badge" v-if="gitStats.headBehind > 0">
{{ gitStats.headBehind }} commits behind remote
</span>
</ToolButton>

Expand Down
4 changes: 2 additions & 2 deletions apps/ui/src/pages/GDocsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@
<span class="badge" v-if="gitStats.headAhead > 0">
{{ gitStats.headAhead }} commits ahead remote
</span>
<span class="badge" v-if="gitStats.headAhead < 0">
{{ -gitStats.headAhead }} commits behind remote
<span class="badge" v-if="gitStats.headBehind > 0">
{{ gitStats.headBehind }} commits behind remote
</span>
</ToolButton>

Expand Down
23 changes: 12 additions & 11 deletions src/git/GitScanner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -776,27 +776,27 @@ export class GitScanner {
}
}

async countAhead(remoteBranch: string) {
let retVal = 0;

async countAheadBehind(remoteBranch: string) {
try {
const result = await this.exec(`git log origin/${remoteBranch}..HEAD`, {
const result = await this.exec(`git rev-list --left-right --count HEAD...origin/${remoteBranch}`, {
skipLogger: true
});
for (const line of result.stdout.split('\n')) {
if (line.startsWith('commit ')) {
retVal++;
}
}
const firstLine = result.stdout.split('\n')[0];

const [ ahead, behind ] = firstLine.split(/\s+/).map(val => parseInt(val));

return {
ahead, behind
};
// eslint-disable-next-line no-empty
} catch (ignore) {}

return retVal;
return { ahead: 0, behind: 0 };
}

async getStats(userConfig: UserConfig) {
let initialized = true;
const headAhead = userConfig.remote_branch ? await this.countAhead(userConfig.remote_branch) : 0;
const { ahead: headAhead, behind: headBehind } = userConfig.remote_branch ? await this.countAheadBehind(userConfig.remote_branch) : { ahead: 0, behind: 0 };
let unstaged = 0;

try {
Expand Down Expand Up @@ -834,6 +834,7 @@ export class GitScanner {
return {
initialized,
headAhead,
headBehind,
unstaged,
remote_branch: userConfig.remote_branch,
remote_url: initialized ? await this.getRemoteUrl() : null
Expand Down
Loading