Skip to content

Commit 35daa8b

Browse files
committed
Optimize checkout and update readme
1 parent 1893932 commit 35daa8b

8 files changed

Lines changed: 33 additions & 5 deletions

File tree

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ In this mode, extension creates a stash from working directory, switches to a ne
3737
> [!TIP]
3838
> stash created with this mode is not compatible with the stash created by mode `Auto stash in current branch`, this means that it want be used to automatically restore. This stash might be used for manual access if needed.
3939
40+
> [!TIP]
41+
> you could set default auto stash behavior when using `Checkout to ... (With Stash)` command by changing default mode in status bar. If set to manual, you will be prompted to select auto stash mode after each checkout, otherwise selected auto stash strategy will be used by default.
42+
4043
### No auto stash
4144

4245
This mode is just ordinary checkout without any auto stash functionality.
46+
47+
## Pull with stash
48+
49+
The extension provides a convenient **Pull with stash** feature. When you run this command, your uncommitted changes are automatically stashed before pulling updates from the remote branch. After the pull completes, your changes are restored. This ensures a smooth workflow and prevents conflicts or loss of local changes during a pull operation.

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@
7474
"type": "boolean",
7575
"default": true,
7676
"description": "Enable logging output"
77+
},
78+
"git-smart-checkout.refetchBeforeCheckout": {
79+
"type": "boolean",
80+
"default": false,
81+
"description": "Refetch remotes each time before checkout"
7782
}
7883
}
7984
}

src/commands/checkoutToCommand/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ export class CheckoutToCommand extends BaseCommand {
8282
}
8383

8484
// Get the list of branches in current repo and show user a quick pick list
85-
const branchList = await git.getAllRefListExtended();
85+
const { refetchBeforeCheckout } = this.configManager.get();
86+
const branchList = await git.getAllRefListExtended(refetchBeforeCheckout);
8687

8788
const [locals, remotes] = getMergedBranchLists(branchList, currentBranch);
8889

src/common/git/gitExecutor.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class GitExecutor {
5252
// #endregion private
5353

5454
async fetchAllRemoteBranchesAndTags() {
55-
const commandFetchAllBranches = 'git fetch --all --prune';
55+
const commandFetchAllBranches = 'git fetch --all';
5656
// fetch all tags and overwrite local tags with remote if remote one has changed
5757
const commandFetchAllTags = 'git fetch --tags --force';
5858

@@ -94,7 +94,7 @@ export class GitExecutor {
9494
}
9595
}
9696

97-
async getAllRefListExtended(fetchRemotes = true): Promise<IGitRef[]> {
97+
async getAllRefListExtended(fetchRemotes = false): Promise<IGitRef[]> {
9898
if (fetchRemotes) {
9999
await this.fetchAllRemoteBranchesAndTags();
100100
}

src/configuration/configurationManager.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export class ConfigurationManager {
1010

1111
this.config = {
1212
mode: vscodeConfig.get('mode', AUTO_STASH_MODE_MANUAL),
13+
refetchBeforeCheckout: vscodeConfig.get('refetchBeforeCheckout', false),
1314
logging: {
1415
enabled: vscodeConfig.get('logging.enabled', true),
1516
},
@@ -21,6 +22,7 @@ export class ConfigurationManager {
2122

2223
this.config = {
2324
mode: vscodeConfig.get('mode', AUTO_STASH_MODE_MANUAL),
25+
refetchBeforeCheckout: vscodeConfig.get('refetchBeforeCheckout', false),
2426
logging: {
2527
enabled: vscodeConfig.get('logging.enabled', true),
2628
},
@@ -40,4 +42,9 @@ export class ConfigurationManager {
4042
const config = workspace.getConfiguration(EXTENSION_NAME);
4143
await config.update('logging.enabled', enabled, ConfigurationTarget.Global);
4244
}
45+
46+
public async updateRefetchBeforeCheckoutEnabled(enabled: boolean): Promise<void> {
47+
const config = workspace.getConfiguration(EXTENSION_NAME);
48+
await config.update('refetchBeforeCheckout', enabled, ConfigurationTarget.Global);
49+
}
4350
}

src/configuration/extensionConfig.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const AUTO_STASH_MODES = Object.values(autoStashModeConfig);
1616

1717
export interface ExtensionConfig {
1818
mode: TAutoStashModeConfig;
19+
refetchBeforeCheckout: boolean;
1920
logging: {
2021
enabled: boolean;
2122
};

src/logging/loggingService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export class LoggingService implements Disposable {
2626
this.outputChannel.appendLine(`Data: ${JSON.stringify(data, null, 2)}`);
2727
}
2828

29-
if (Boolean(data)) {
29+
if (!data) {
3030
console.log(formattedMessage);
3131
} else {
3232
console.log(formattedMessage, `Data: ${JSON.stringify(data, null, 2)}`);

src/statusBar/statusBarManager.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { ConfigurationManager } from '../configuration/configurationManager';
1111
import { LoggingService } from '../logging/loggingService';
1212
import { EXTENSION_NAME } from '../const';
1313
import {
14+
AUTO_STASH_MODE_MANUAL,
1415
AUTO_STASH_MODES,
1516
AUTO_STASH_MODES_DETAILS,
1617
TAutoStashModeConfig,
@@ -38,7 +39,13 @@ export class StatusBarManager implements Disposable {
3839

3940
this.statusBarItem.text = `${modeDetails.icon} ${modeDetails.briefLabel}`;
4041
this.statusBarItem.tooltip = `${EXTENSION_NAME}\nCurrent mode: ${modeDetails.label}\nClick to switch modes`;
41-
this.statusBarItem.backgroundColor = new ThemeColor('statusBarItem.warningBackground');
42+
43+
const statusBarColor =
44+
config.mode === AUTO_STASH_MODE_MANUAL
45+
? 'statusBarItem.descriptionForeground'
46+
: 'statusBarItem.warningBackground';
47+
48+
this.statusBarItem.backgroundColor = new ThemeColor(statusBarColor);
4249
}
4350

4451
public async showModeQuickPick(): Promise<void> {

0 commit comments

Comments
 (0)