Skip to content

Commit 29b8058

Browse files
committed
Simplify branch tracking logic in apply_git_diff by removing redundant original branch storage and improving detached HEAD state handling
1 parent 47cb02d commit 29b8058

1 file changed

Lines changed: 9 additions & 14 deletions

File tree

  • packages/vscode/src/commands/checkpoints-command/utils

‎packages/vscode/src/commands/checkpoints-command/utils/git-utils.ts‎

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -105,27 +105,22 @@ export const apply_git_diff = async (
105105
): Promise<boolean> => {
106106
try {
107107
const cwd = workspace_folder.uri.fsPath
108-
let original_branch: string | null = null
109-
try {
110-
original_branch = execSync('git rev-parse --abbrev-ref HEAD', {
111-
cwd,
112-
encoding: 'utf8'
113-
}).trim()
114-
} catch (err) {
115-
// Might be in detached HEAD state
116-
original_branch = null
117-
}
118108
if (target_commit) {
119109
const current_commit = execSync('git rev-parse HEAD', {
120110
cwd,
121111
encoding: 'utf8'
122112
}).trim()
123113

124114
if (current_commit !== target_commit) {
125-
const current_branch = execSync('git rev-parse --abbrev-ref HEAD', {
126-
cwd,
127-
encoding: 'utf8'
128-
}).trim()
115+
let current_branch: string | undefined
116+
try {
117+
current_branch = execSync('git rev-parse --abbrev-ref HEAD', {
118+
cwd,
119+
encoding: 'utf8'
120+
}).trim()
121+
} catch (err) {
122+
// Might be in detached HEAD state
123+
}
129124

130125
if (target_branch && current_branch !== target_branch) {
131126
try {

0 commit comments

Comments
 (0)