Skip to content

Commit 5e5896e

Browse files
committed
Merge branch 'main' into merogge/ref
2 parents 54402b4 + 4d38422 commit 5e5896e

File tree

42 files changed

+406
-205
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+406
-205
lines changed

build/azure-pipelines/cli/prepare.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/azure-pipelines/cli/prepare.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ const setLauncherEnvironmentVars = () => {
5454
['VSCODE_CLI_TUNNEL_SERVICE_MUTEX', product.win32TunnelServiceMutex],
5555
['VSCODE_CLI_TUNNEL_CLI_MUTEX', product.win32TunnelMutex],
5656
['VSCODE_CLI_COMMIT', commit],
57+
['VSCODE_CLI_DEFAULT_PARENT_DATA_DIR', product.dataFolderName],
5758
[
5859
'VSCODE_CLI_WIN32_APP_IDS',
5960
!isOSS && JSON.stringify(

cli/src/bin/code/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ async fn main() -> Result<(), std::convert::Infallible> {
3636
});
3737

3838
let core = parsed.core();
39-
let context_paths = LauncherPaths::new(&core.global_options.cli_data_dir).unwrap();
39+
let context_paths = LauncherPaths::migrate(core.global_options.cli_data_dir.clone()).unwrap();
4040
let context_args = core.clone();
4141

4242
// gets a command context without installing the global logger

cli/src/constants.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ pub const TUNNEL_ACTIVITY_NAME: &str = concatcp!(PRODUCT_NAME_LONG, " Tunnel");
7575

7676
const NONINTERACTIVE_VAR: &str = "VSCODE_CLI_NONINTERACTIVE";
7777

78+
/// Default data CLI data directory.
79+
pub const DEFAULT_DATA_PARENT_DIR: &str = match option_env!("VSCODE_CLI_DEFAULT_PARENT_DATA_DIR") {
80+
Some(n) => n,
81+
None => ".vscode-oss",
82+
};
83+
7884
pub fn get_default_user_agent() -> String {
7985
format!(
8086
"vscode-server-launcher/{}",

cli/src/state.rs

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
extern crate dirs;
77

88
use std::{
9-
fs::{create_dir, read_to_string, remove_dir_all, write},
9+
fs::{create_dir_all, read_to_string, remove_dir_all, write},
1010
path::{Path, PathBuf},
1111
sync::{Arc, Mutex},
1212
};
1313

1414
use serde::{de::DeserializeOwned, Serialize};
1515

1616
use crate::{
17-
constants::VSCODE_CLI_QUALITY,
17+
constants::{DEFAULT_DATA_PARENT_DIR, VSCODE_CLI_QUALITY},
1818
download_cache::DownloadCache,
1919
util::errors::{wrap, AnyError, NoHomeForLauncherError, WrappedError},
2020
};
@@ -107,8 +107,38 @@ where
107107
}
108108

109109
impl LauncherPaths {
110-
pub fn new(root: &Option<String>) -> Result<LauncherPaths, AnyError> {
111-
let root = root.as_deref().unwrap_or("~/.vscode-cli");
110+
/// todo@conno4312: temporary migration from the old CLI data directory
111+
pub fn migrate(root: Option<String>) -> Result<LauncherPaths, AnyError> {
112+
if root.is_some() {
113+
return Self::new(root);
114+
}
115+
116+
let home_dir = match dirs::home_dir() {
117+
None => return Self::new(root),
118+
Some(d) => d,
119+
};
120+
121+
let old_dir = home_dir.join(".vscode-cli");
122+
let mut new_dir = home_dir;
123+
new_dir.push(DEFAULT_DATA_PARENT_DIR);
124+
new_dir.push("cli");
125+
if !old_dir.exists() || new_dir.exists() {
126+
return Self::new_for_path(new_dir);
127+
}
128+
129+
if let Err(e) = std::fs::rename(&old_dir, &new_dir) {
130+
// no logger exists at this point in the lifecycle, so just log to stderr
131+
eprintln!(
132+
"Failed to migrate old CLI data directory, will create a new one ({})",
133+
e
134+
);
135+
}
136+
137+
Self::new_for_path(new_dir)
138+
}
139+
140+
pub fn new(root: Option<String>) -> Result<LauncherPaths, AnyError> {
141+
let root = root.unwrap_or_else(|| format!("~/{}/cli", DEFAULT_DATA_PARENT_DIR));
112142
let mut replaced = root.to_owned();
113143
for token in HOME_DIR_ALTS {
114144
if root.contains(token) {
@@ -120,14 +150,16 @@ impl LauncherPaths {
120150
}
121151
}
122152

123-
if !Path::new(&replaced).exists() {
124-
create_dir(&replaced)
125-
.map_err(|e| wrap(e, format!("error creating directory {}", &replaced)))?;
153+
Self::new_for_path(PathBuf::from(replaced))
154+
}
155+
156+
fn new_for_path(root: PathBuf) -> Result<LauncherPaths, AnyError> {
157+
if !root.exists() {
158+
create_dir_all(&root)
159+
.map_err(|e| wrap(e, format!("error creating directory {}", root.display())))?;
126160
}
127161

128-
Ok(LauncherPaths::new_without_replacements(PathBuf::from(
129-
replaced,
130-
)))
162+
Ok(LauncherPaths::new_without_replacements(root))
131163
}
132164

133165
pub fn new_without_replacements(root: PathBuf) -> LauncherPaths {

extensions/git/package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2073,6 +2073,12 @@
20732073
"markdownDescription": "%config.autofetchPeriod%",
20742074
"default": 180
20752075
},
2076+
"git.defaultBranchName": {
2077+
"type": "string",
2078+
"description": "%config.defaultBranchName%",
2079+
"default": "main",
2080+
"scope": "resource"
2081+
},
20762082
"git.branchPrefix": {
20772083
"type": "string",
20782084
"description": "%config.branchPrefix%",

extensions/git/package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"config.checkoutType.local": "Local branches",
132132
"config.checkoutType.tags": "Tags",
133133
"config.checkoutType.remote": "Remote branches",
134+
"config.defaultBranchName": "The name of the default branch (ex: main, trunk, development) when initializing a new git repository. When set to empty, the default branch name configured in git will be used.",
134135
"config.branchPrefix": "Prefix used when creating a new branch.",
135136
"config.branchProtection": "List of protected branches. By default, a prompt is shown before changes are committed to a protected branch. The prompt can be controlled using the `#git.branchProtectionPrompt#` setting.",
136137
"config.branchProtectionPrompt": "Controls whether a prompt is being shown before changes are committed to a protected branch.",

extensions/git/src/commands.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@ function getCheckoutProcessor(repository: Repository, type: string): CheckoutPro
307307
return undefined;
308308
}
309309

310+
function sanitizeBranchName(name: string, whitespaceChar: string): string {
311+
return name.trim().replace(/^-+/, '').replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$|\[|\]$/g, whitespaceChar);
312+
}
313+
310314
function sanitizeRemoteName(name: string) {
311315
name = name.trim();
312316
return name && name.replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$|\[|\]$/g, '-');
@@ -772,7 +776,11 @@ export class CommandCenter {
772776
}
773777
}
774778

775-
await this.git.init(repositoryPath);
779+
const config = workspace.getConfiguration('git');
780+
const defaultBranchName = config.get<string>('defaultBranchName', 'main');
781+
const branchWhitespaceChar = config.get<string>('branchWhitespaceChar', '-');
782+
783+
await this.git.init(repositoryPath, { defaultBranch: sanitizeBranchName(defaultBranchName, branchWhitespaceChar) });
776784

777785
let message = l10n.t('Would you like to open the initialized repository?');
778786
const open = l10n.t('Open');
@@ -2179,9 +2187,6 @@ export class CommandCenter {
21792187
const branchPrefix = config.get<string>('branchPrefix')!;
21802188
const branchWhitespaceChar = config.get<string>('branchWhitespaceChar')!;
21812189
const branchValidationRegex = config.get<string>('branchValidationRegex')!;
2182-
const sanitize = (name: string) => name ?
2183-
name.trim().replace(/^-+/, '').replace(/^\.|\/\.|\.\.|~|\^|:|\/$|\.lock$|\.lock\/|\\|\*|\s|^\s*$|\.$|\[|\]$/g, branchWhitespaceChar)
2184-
: name;
21852190

21862191
let rawBranchName = defaultName;
21872192

@@ -2206,7 +2211,7 @@ export class CommandCenter {
22062211
ignoreFocusOut: true,
22072212
validateInput: (name: string) => {
22082213
const validateName = new RegExp(branchValidationRegex);
2209-
const sanitizedName = sanitize(name);
2214+
const sanitizedName = sanitizeBranchName(name, branchWhitespaceChar);
22102215
if (validateName.test(sanitizedName)) {
22112216
// If the sanitized name that we will use is different than what is
22122217
// in the input box, show an info message to the user informing them
@@ -2224,7 +2229,7 @@ export class CommandCenter {
22242229
});
22252230
}
22262231

2227-
return sanitize(rawBranchName || '');
2232+
return sanitizeBranchName(rawBranchName || '', branchWhitespaceChar);
22282233
}
22292234

22302235
private async _branch(repository: Repository, defaultName?: string, from = false): Promise<void> {

extensions/git/src/git.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,14 @@ export class Git {
401401
return new Repository(this, repository, dotGit, logger);
402402
}
403403

404-
async init(repository: string): Promise<void> {
405-
await this.exec(repository, ['init']);
406-
return;
404+
async init(repository: string, options: { defaultBranch?: string } = {}): Promise<void> {
405+
const args = ['init'];
406+
407+
if (options.defaultBranch && options.defaultBranch !== '') {
408+
args.push('-b', options.defaultBranch);
409+
}
410+
411+
await this.exec(repository, args);
407412
}
408413

409414
async clone(url: string, options: ICloneOptions, cancellationToken?: CancellationToken): Promise<string> {

0 commit comments

Comments
 (0)