Skip to content

Commit

Permalink
Group local branch tip with its remotes into one bubble
Browse files Browse the repository at this point in the history
if they are on the same commit. Only if it's safe to do so, i.e. there are no tags or stashes with the same name. Two remotes without the local one also won't be grouped. Grouping can be deactivated by setting `{ "git-log--graph.group-branch-remotes": false }`
  • Loading branch information
phil294 committed Sep 28, 2024
1 parent 2ca9714 commit 5452998
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 8 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ Please consider opening an issue or PR if you think a certain action or option w
"As a view in the Source Control side nav section. You will also be able to drag it to any other place in the interface."
]
},
"git-log--graph.group-branch-remotes": {
"description": "If active, branches and their origins will be merged into a single branch-tip bubble, but only if there is no ambiguity.",
"type": "boolean",
"default": true
},
"git-log--graph.hide-quick-branch-tips": {
"description": "If active, the area at the top with the dotted branch lines and git status will not be shown anymore.",
"type": "boolean",
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@
"As a view in the Source Control side nav section. You will also be able to drag it to any other place in the interface."
]
},
"git-log--graph.group-branch-remotes": {
"description": "If active, branches and their origins will be merged into a single branch-tip bubble, but only if there is no ambiguity.",
"type": "boolean",
"default": true
},
"git-log--graph.details-panel-position": {
"description": "Decide where the commit details should appear when you click a row in the main view.",
"type": "string",
Expand Down
2 changes: 2 additions & 0 deletions src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ interface GitRef {
interface Branch extends GitRef {
type: "branch"
remote_name?: string
/** For display of multiple remotes inside one Ref */
remote_names_group?: string[]
tracking_remote_name?: string
inferred?: boolean
}
Expand Down
52 changes: 52 additions & 0 deletions web/src/views/CommitRefTips.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<template>
<div class="commit-ref-tips row align-center">
<ref-tip v-for="ref of refs" :key="ref.id" :commit="commit" :git_ref="ref" />
</div>
</template>
<script setup>
import { computed } from 'vue'
import { config } from '../state/store'
let props = defineProps({
commit: {
required: true,
/** @type {Vue.PropType<Commit>} */
type: Object,
},
})
function group_same_name_branches_into_one(/** @type {Branch[]} */ branches) {
return {
...branches[0],
remote_name: undefined,
id: branches[0].name,
remote_names_group: branches
.map(ref => ref.remote_name)
.filter(is_truthy),
}
}
let refs = computed(() => {
if (config.value['group-branch-remotes'] === false)
return props.commit.refs
return Object.values(props.commit.refs.reduce((/** @type {Record<string, GitRef[]>} */ all, ref) => {
all[ref.name] ||= []
all[ref.name].push(ref)
return all
}, {}))
.map(name_group => {
let as_branches = name_group.filter(is_branch)
let is_all_branches = as_branches.length === name_group.length
let has_local_branch_tip = as_branches.some(branch => ! branch.remote_name)
if (as_branches.length > 1 && is_all_branches && has_local_branch_tip)
return group_same_name_branches_into_one(as_branches)
return name_group
}).flat()
})
</script>
<style scoped>
.commit-ref-tips {
line-height: 1em;
z-index: 1;
}
</style>
10 changes: 2 additions & 8 deletions web/src/views/CommitRow.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
<template>
<div :class="{merge:commit.merge}" class="commit row">
<div :class="{merge:commit.merge}" class="commit-row commit row">
<SVGVisualization :commit="commit" :height="calculated_height" :style="vis_style" class="vis" />
<div v-if="commit.hash" class="info flex-1 row gap-20">
<div class="subject-wrapper flex-1 row align-center">
<div :style="commit.branch? {color:commit.branch.color} : undefined" class="vis-ascii-circle vis-resize-handle" @mousedown="vis_resize_handle_mousedown">
&nbsp;
</div>
<div class="refs row align-center">
<ref-tip v-for="ref of commit.refs" :key="ref.id" :commit="commit" :git_ref="ref" />
</div>
<commit-ref-tips :commit="commit" />
<div class="subject">
&nbsp;{{ commit.subject }}
</div>
Expand Down Expand Up @@ -102,10 +100,6 @@ let calculated_height = computed(() =>
.info > .subject-wrapper > .vis-resize-handle {
cursor: col-resize;
}
.info > .subject-wrapper > .refs {
line-height: 1em;
z-index: 1;
}
.info > .datetime,
.info > .author {
color: #808080;
Expand Down
6 changes: 6 additions & 0 deletions web/src/views/RefTip.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<template>
<div v-context-menu="context_menu_provider" v-drag="drag" v-drop="drop" class="ref-tip" v-bind="bind">
{{ git_ref.id }}
<template v-if="branch?.remote_names_group">
<span v-for="remote_name of branch.remote_names_group" :key="remote_name" class="remote-name-group-entry"> + {{ remote_name }}</span>
</template>
</div>
</template>
<script setup>
Expand Down Expand Up @@ -116,4 +119,7 @@ let context_menu_provider = computed(() => () => {
background: #fff !important;
color: #f00 !important;
}
.remote-name-group-entry {
color: #fff;
}
</style>

0 comments on commit 5452998

Please sign in to comment.