@jjdenhertog/ai-driven-development
Version:
AI-driven development workflow with learning capabilities for Claude
62 lines • 2.71 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBranchState = getBranchState;
const getGitInstance_1 = require("./getGitInstance");
function getBranchState(cwd) {
return __awaiter(this, void 0, void 0, function* () {
try {
// Get appropriate git instance
const git = (0, getGitInstance_1.getGitInstance)(cwd);
// Get current branch
const branchSummary = yield git.branch();
const currentBranch = branchSummary.current;
// Check for changes
const status = yield git.status();
const hasChanges = !status.isClean();
// Check for unstaged files
const hasUnstagedFiles = status.files.some(file => file.working_dir !== ' ' || status.not_added.length > 0);
// Check for unpushed commits
let unpushedCommits = 0;
if (currentBranch) {
try {
// Check if there are commits ahead of upstream
const result = yield git.raw(['rev-list', '@{u}..HEAD']);
unpushedCommits = result.trim().length > 0 ? 1 : 0;
}
catch (_a) {
// No upstream or other error, assume there are unpushed commits
unpushedCommits = 1;
}
}
return {
currentBranch,
hasChanges,
hasUnstagedFiles,
unpushedCommits,
clean: status.isClean(),
ready: true
};
}
catch (error) {
return {
currentBranch: '',
hasChanges: false,
hasUnstagedFiles: false,
unpushedCommits: 0,
clean: false,
ready: false,
error: error instanceof Error ? error.message : 'Unknown git error'
};
}
});
}
//# sourceMappingURL=getBranchState.js.map