Skip to content

Commit 4897204

Browse files
committed
Merge branch 'main' of vp-git:ViscousPotential/GitSync
2 parents a25d811 + 192dbd9 commit 4897204

File tree

9 files changed

+1554
-1487
lines changed

9 files changed

+1554
-1487
lines changed

lib/api/manager/git_manager.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -794,6 +794,36 @@ class GitManager {
794794
return result;
795795
}
796796

797+
static Future<void> setRemoteUrl(String newRemoteUrl, [int? repomanRepoindex]) async {
798+
if (await isLocked()) {
799+
Fluttertoast.showToast(msg: operationInProgressError, toastLength: Toast.LENGTH_SHORT, gravity: null);
800+
return;
801+
}
802+
803+
final repoIndex = await repoManager.getInt(StorageKey.repoman_repoIndex);
804+
805+
return await _runWithLock(repomanRepoindex ?? repoIndex, () async {
806+
final settingsManager = repomanRepoindex == null ? uiSettingsManager : await SettingsManager().reinit(repoIndex: repomanRepoindex);
807+
final dirPath = (await settingsManager.getGitDirPath());
808+
if (dirPath == null) return;
809+
await useDirectory(dirPath, (bookmarkPath) async => await uiSettingsManager.setGitDirPath(bookmarkPath), (dirPath) async {
810+
Logger.gmLog(type: LogType.RecentCommits, ".git folder found");
811+
812+
try {
813+
return (await GitManagerRs.setRemoteUrl(
814+
pathString: dirPath,
815+
remoteName: await settingsManager.getRemote(),
816+
newRemoteUrl: newRemoteUrl,
817+
log: _logWrapper,
818+
));
819+
} catch (e, stackTrace) {
820+
Logger.logError(LogType.RecentCommits, e, stackTrace);
821+
return;
822+
}
823+
});
824+
});
825+
}
826+
797827
static Future<void> checkoutBranch(String branchName, [int? repomanRepoindex]) async {
798828
if (await isLocked()) {
799829
Fluttertoast.showToast(msg: operationInProgressError, toastLength: Toast.LENGTH_SHORT, gravity: null);

lib/main.dart

Lines changed: 1405 additions & 1476 deletions
Large diffs are not rendered by default.

lib/src/rust/api/git_manager.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,18 @@ Future<List<String>> getBranchNames({
334334
log: log,
335335
);
336336

337+
Future<void> setRemoteUrl({
338+
required String pathString,
339+
required String remoteName,
340+
required String newRemoteUrl,
341+
required FutureOr<void> Function(LogType, String) log,
342+
}) => RustLib.instance.api.crateApiGitManagerSetRemoteUrl(
343+
pathString: pathString,
344+
remoteName: remoteName,
345+
newRemoteUrl: newRemoteUrl,
346+
log: log,
347+
);
348+
337349
Future<void> checkoutBranch({
338350
required String pathString,
339351
required String remote,

lib/ui/dialog/confirm_delete_file_folder.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import 'package:sprintf/sprintf.dart';
77
import '../../../constant/colors.dart';
88
import '../../../constant/dimens.dart';
99
import '../../../ui/dialog/base_alert_dialog.dart';
10-
import 'package:GitSync/l10n/app_localizations.dart';
1110
import 'package:path/path.dart' as p;
1211

1312
Future<void> showDialog(BuildContext context, List<String> selectedPaths, Future<void> Function() callback) {
@@ -41,7 +40,7 @@ Future<void> showDialog(BuildContext context, List<String> selectedPaths, Future
4140
),
4241
SizedBox(height: spaceMD),
4342
Text(
44-
AppLocalizations.of(context).thisActionCannotBeUndone,
43+
t.thisActionCannotBeUndone,
4544
style: const TextStyle(color: primaryLight, fontWeight: FontWeight.bold, fontSize: textSM),
4645
),
4746
],
@@ -50,7 +49,7 @@ Future<void> showDialog(BuildContext context, List<String> selectedPaths, Future
5049
actions: <Widget>[
5150
TextButton(
5251
child: Text(
53-
AppLocalizations.of(context).cancel.toUpperCase(),
52+
t.cancel.toUpperCase(),
5453
style: TextStyle(color: primaryLight, fontSize: textMD),
5554
),
5655
onPressed: () {
@@ -59,7 +58,7 @@ Future<void> showDialog(BuildContext context, List<String> selectedPaths, Future
5958
),
6059
TextButton(
6160
child: Text(
62-
AppLocalizations.of(context).delete.toUpperCase(),
61+
t.delete.toUpperCase(),
6362
style: TextStyle(color: tertiaryNegative, fontSize: textMD),
6463
),
6564
onPressed: () async {

lib/ui/dialog/create_file.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'package:GitSync/global.dart';
2-
import 'package:GitSync/l10n/app_localizations.dart';
32
import 'package:flutter/material.dart' as mat;
43
import 'package:flutter/material.dart';
54
import '../../../constant/colors.dart';
@@ -53,7 +52,7 @@ Future<void> showDialog(BuildContext context, Function(String text) callback) {
5352
actions: <Widget>[
5453
TextButton(
5554
child: Text(
56-
AppLocalizations.of(context).cancel.toUpperCase(),
55+
t.cancel.toUpperCase(),
5756
style: TextStyle(color: primaryLight, fontSize: textMD),
5857
),
5958
onPressed: () {
@@ -62,7 +61,7 @@ Future<void> showDialog(BuildContext context, Function(String text) callback) {
6261
),
6362
TextButton(
6463
child: Text(
65-
AppLocalizations.of(context).create.toUpperCase(),
64+
t.create.toUpperCase(),
6665
style: TextStyle(color: primaryPositive, fontSize: textMD),
6766
),
6867
onPressed: () async {

lib/ui/dialog/rename_file_folder.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import 'package:sprintf/sprintf.dart';
55
import '../../../constant/colors.dart';
66
import '../../../constant/dimens.dart';
77
import '../../../ui/dialog/base_alert_dialog.dart';
8-
import 'package:GitSync/l10n/app_localizations.dart';
98

109
Future<void> showDialog(BuildContext context, String originalName, bool fileDir, Function(String text) callback) {
1110
final textController = TextEditingController();
@@ -55,7 +54,7 @@ Future<void> showDialog(BuildContext context, String originalName, bool fileDir,
5554
actions: <Widget>[
5655
TextButton(
5756
child: Text(
58-
AppLocalizations.of(context).cancel.toUpperCase(),
57+
t.cancel.toUpperCase(),
5958
style: TextStyle(color: primaryLight, fontSize: textMD),
6059
),
6160
onPressed: () {
@@ -64,7 +63,7 @@ Future<void> showDialog(BuildContext context, String originalName, bool fileDir,
6463
),
6564
TextButton(
6665
child: Text(
67-
AppLocalizations.of(context).rename.toUpperCase(),
66+
t.rename.toUpperCase(),
6867
style: TextStyle(color: primaryPositive, fontSize: textMD),
6968
),
7069
onPressed: () async {

lib/ui/dialog/set_remote_url.dart

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import 'package:flutter/material.dart' as mat;
2+
import 'package:flutter/material.dart';
3+
import 'package:GitSync/global.dart';
4+
import '../../../constant/colors.dart';
5+
import '../../../constant/dimens.dart';
6+
import '../../../ui/dialog/base_alert_dialog.dart';
7+
8+
Future<void> showDialog(BuildContext context, String? oldRemoteUrl, Future<void> Function(String newRemoteUrl) callback) async {
9+
final newRemoteController = TextEditingController(text: oldRemoteUrl);
10+
11+
// TODO: Dialog doesn't open without this (investigate)
12+
await Future.delayed(Duration(milliseconds: 500));
13+
14+
return await mat.showDialog(
15+
context: context,
16+
builder: (BuildContext context) => BaseAlertDialog(
17+
expandable: false,
18+
backgroundColor: secondaryDark,
19+
title: SizedBox(
20+
width: MediaQuery.of(context).size.width,
21+
child: Text(
22+
"Set Remote URL".toUpperCase(),
23+
style: TextStyle(color: primaryLight, fontSize: textXL, fontWeight: FontWeight.bold),
24+
),
25+
),
26+
content: SingleChildScrollView(
27+
child: ListBody(
28+
children: [
29+
SizedBox(height: spaceMD),
30+
TextField(
31+
controller: newRemoteController,
32+
maxLines: 1,
33+
style: TextStyle(
34+
color: primaryLight,
35+
fontWeight: FontWeight.bold,
36+
decoration: TextDecoration.none,
37+
decorationThickness: 0,
38+
fontSize: textMD,
39+
),
40+
decoration: InputDecoration(
41+
fillColor: tertiaryDark,
42+
filled: true,
43+
border: const OutlineInputBorder(borderRadius: BorderRadius.all(cornerRadiusSM), borderSide: BorderSide.none),
44+
isCollapsed: true,
45+
label: Text(
46+
t.fileName.toUpperCase(),
47+
style: TextStyle(color: secondaryLight, fontSize: textSM, fontWeight: FontWeight.bold),
48+
),
49+
floatingLabelBehavior: FloatingLabelBehavior.always,
50+
contentPadding: const EdgeInsets.symmetric(horizontal: spaceMD, vertical: spaceSM),
51+
isDense: true,
52+
),
53+
),
54+
],
55+
),
56+
),
57+
actions: <Widget>[
58+
TextButton(
59+
child: Text(
60+
t.cancel.toUpperCase(),
61+
style: TextStyle(color: primaryLight, fontSize: textMD),
62+
),
63+
onPressed: () {
64+
Navigator.of(context).canPop() ? Navigator.pop(context) : null;
65+
},
66+
),
67+
TextButton(
68+
child: Text(
69+
"Modify".toUpperCase(),
70+
style: TextStyle(color: primaryPositive, fontSize: textMD),
71+
),
72+
onPressed: () async {
73+
callback(newRemoteController.text);
74+
Navigator.of(context).canPop() ? Navigator.pop(context) : null;
75+
},
76+
),
77+
],
78+
),
79+
);
80+
}

lib/ui/page/global_settings_main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class _GlobalSettingsMain extends State<GlobalSettingsMain> with WidgetsBindingO
5555

5656
if (widget.onboarding) {
5757
WidgetsBinding.instance.addPostFrameCallback((_) async {
58-
await _controller.animateTo(_controller.position.maxScrollExtent, duration: Duration(milliseconds: 500), curve: Curves.easeInOut);
58+
await _controller.animateTo(_controller.position.maxScrollExtent / 2, duration: Duration(milliseconds: 500), curve: Curves.easeInOut);
5959
await Future.delayed(Duration(milliseconds: 200));
6060
ShowCaseWidget.of(context).startShowCase([_uiSetupGuideKey]);
6161
while (!ShowCaseWidget.of(context).isShowCaseCompleted) {

rust/src/api/git_manager.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2327,6 +2327,25 @@ pub async fn get_branch_names(
23272327
branch_set.into_iter().collect()
23282328
}
23292329

2330+
pub async fn set_remote_url(
2331+
path_string: &String,
2332+
remote_name: &String,
2333+
new_remote_url: &String,
2334+
log: impl Fn(LogType, String) -> DartFnFuture<()> + Send + Sync + 'static,
2335+
) -> Result<(), git2::Error> {
2336+
let log_callback = Arc::new(log);
2337+
2338+
_log(
2339+
Arc::clone(&log_callback),
2340+
LogType::GitStatus,
2341+
"Getting local directory".to_string(),
2342+
);
2343+
let repo = Repository::open(Path::new(path_string)).unwrap();
2344+
repo.remote_set_url(&remote_name, &new_remote_url)?;
2345+
2346+
Ok(())
2347+
}
2348+
23302349
pub async fn checkout_branch(
23312350
path_string: &String,
23322351
remote: &String,

0 commit comments

Comments
 (0)