mirror of
https://github.com/HeyPuter/puter.git
synced 2026-05-29 21:01:27 +00:00
feat(git): Handle detached HEAD in git status and git branch --list
This commit is contained in:
@@ -269,6 +269,11 @@ const BRANCH = {
|
||||
throw SHOW_USAGE;
|
||||
}
|
||||
|
||||
if (!current_branch) {
|
||||
const oid = await git.resolveRef({ fs, dir, gitdir, ref: 'HEAD' });
|
||||
stdout(`* ${chalk.greenBright(`(HEAD detached at ${shorten_hash(oid)})`)}`);
|
||||
}
|
||||
|
||||
for (const branch of branches) {
|
||||
if (branch === current_branch) {
|
||||
stdout(chalk.greenBright(`* ${branch}`));
|
||||
|
||||
@@ -18,7 +18,8 @@
|
||||
*/
|
||||
import git from 'isomorphic-git';
|
||||
import path from 'path-browserify';
|
||||
import { find_repo_root } from '../git-helpers.js';
|
||||
import { find_repo_root, shorten_hash } from '../git-helpers.js';
|
||||
import chalk from 'chalk';
|
||||
|
||||
export default {
|
||||
name: 'status',
|
||||
@@ -107,7 +108,17 @@ export default {
|
||||
dir,
|
||||
gitdir,
|
||||
});
|
||||
stdout(`On branch ${current_branch}\n`);
|
||||
if (current_branch) {
|
||||
stdout(`On branch ${current_branch}`);
|
||||
// Check if the branch actually exists. If not, this is a fresh repo that's never been committed to.
|
||||
const actual_current_branch = await git.currentBranch({ fs, dir, gitdir, test: true });
|
||||
if (!actual_current_branch) {
|
||||
stdout('\nNo commits yet\n');
|
||||
}
|
||||
} else {
|
||||
const oid = await git.resolveRef({ fs, dir, gitdir, ref: 'HEAD' });
|
||||
stdout(`${chalk.redBright('HEAD detached at')} ${shorten_hash(oid)}`);
|
||||
}
|
||||
|
||||
if (staged.length) {
|
||||
stdout('Changes to be committed:');
|
||||
|
||||
Reference in New Issue
Block a user