try to use username and password credential to clone repository
This commit is contained in:
parent
f24b2d171a
commit
beed218947
6 changed files with 139 additions and 27 deletions
|
|
@ -23,11 +23,11 @@
|
|||
<rect key="frame" x="0.0" y="28" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="kff-Zw-ti1" id="x1h-9k-B9w">
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Title" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="E7G-EA-HbK">
|
||||
<rect key="frame" x="15" y="0.0" width="325" height="43.5"/>
|
||||
<rect key="frame" x="15" y="0.0" width="325" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
|
|
@ -81,11 +81,11 @@
|
|||
<rect key="frame" x="0.0" y="35" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="W3D-XV-i9c" id="W9C-sq-ric">
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Git Server" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="Nuw-cs-qZN">
|
||||
<rect key="frame" x="15" y="0.0" width="325" height="43.5"/>
|
||||
<rect key="frame" x="15" y="0.0" width="325" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
|
|
@ -101,11 +101,11 @@
|
|||
<rect key="frame" x="0.0" y="79" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="D5Y-70-cIk" id="j3q-u1-biY">
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="SSH Key" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="39M-pD-G4c">
|
||||
<rect key="frame" x="15" y="0.0" width="325" height="43.5"/>
|
||||
<rect key="frame" x="15" y="0.0" width="325" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
|
|
@ -125,18 +125,18 @@
|
|||
<rect key="frame" x="0.0" y="159" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="x7b-p5-sQR" id="wqT-nH-PgF">
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="342" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="PGP Key" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="9z4-m8-sRO">
|
||||
<rect key="frame" x="15" y="12" width="66" height="20.5"/>
|
||||
<rect key="frame" x="15" y="11" width="66" height="21"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<nil key="textColor"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<label opaque="NO" multipleTouchEnabled="YES" contentMode="left" text="Not Set" textAlignment="right" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" id="eUn-QA-sUA">
|
||||
<rect key="frame" x="282" y="12" width="58" height="20.5"/>
|
||||
<rect key="frame" x="282" y="11" width="58" height="21"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<fontDescription key="fontDescription" type="system" pointSize="17"/>
|
||||
<color key="textColor" white="0.66666666666666663" alpha="1" colorSpace="calibratedWhite"/>
|
||||
|
|
@ -169,18 +169,18 @@
|
|||
<scene sceneID="Obl-ql-ILG">
|
||||
<objects>
|
||||
<tableViewController id="ynQ-64-MfA" customClass="GitServerSettingTableViewController" customModule="pass" customModuleProvider="target" sceneMemberID="viewController">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="62X-tb-qYf">
|
||||
<tableView key="view" clipsSubviews="YES" contentMode="scaleToFill" alwaysBounceVertical="YES" dataMode="static" style="grouped" separatorStyle="default" allowsSelection="NO" rowHeight="44" sectionHeaderHeight="18" sectionFooterHeight="18" id="62X-tb-qYf">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="667"/>
|
||||
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
|
||||
<color key="backgroundColor" cocoaTouchSystemColor="groupTableViewBackgroundColor"/>
|
||||
<sections>
|
||||
<tableViewSection id="pbe-W6-w4V">
|
||||
<cells>
|
||||
<tableViewCell clipsSubviews="YES" userInteractionEnabled="NO" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="gitRepositoryURLTabelViewCell" rowHeight="52" id="FRr-pf-aPO">
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="gitRepositoryURLTabelViewCell" rowHeight="52" id="FRr-pf-aPO">
|
||||
<rect key="frame" x="0.0" y="35" width="375" height="52"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="FRr-pf-aPO" id="60A-PS-qGe">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="51.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Git Repository URL" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="ugx-bs-r9H">
|
||||
|
|
@ -189,7 +189,7 @@
|
|||
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="https://" textAlignment="natural" minimumFontSize="17" clearButtonMode="unlessEditing" translatesAutoresizingMaskIntoConstraints="NO" id="EVT-VU-sCi">
|
||||
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="https://" textAlignment="natural" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="EVT-VU-sCi">
|
||||
<rect key="frame" x="15" y="23" width="352" height="21"/>
|
||||
<nil key="textColor"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||
|
|
@ -205,6 +205,64 @@
|
|||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="usernameTableVIewCell" rowHeight="52" id="RWE-qh-fFI">
|
||||
<rect key="frame" x="0.0" y="87" width="375" height="52"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="RWE-qh-fFI" id="fSL-1c-C64">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Username" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="wO6-YQ-5na">
|
||||
<rect key="frame" x="15" y="8" width="58" height="15"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
|
||||
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Username" textAlignment="natural" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="cxu-dD-J2H">
|
||||
<rect key="frame" x="15" y="23" width="352" height="21"/>
|
||||
<nil key="textColor"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="alphabet"/>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstItem="wO6-YQ-5na" firstAttribute="leading" secondItem="fSL-1c-C64" secondAttribute="leadingMargin" constant="7" id="4cx-80-Abn"/>
|
||||
<constraint firstItem="cxu-dD-J2H" firstAttribute="leading" secondItem="wO6-YQ-5na" secondAttribute="leading" id="5J9-mM-Mha"/>
|
||||
<constraint firstItem="cxu-dD-J2H" firstAttribute="top" secondItem="wO6-YQ-5na" secondAttribute="bottom" id="Gze-8B-wvG"/>
|
||||
<constraint firstAttribute="topMargin" secondItem="wO6-YQ-5na" secondAttribute="top" id="Mhn-u0-93u"/>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="cxu-dD-J2H" secondAttribute="trailing" id="oH6-ED-AJZ"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
<tableViewCell clipsSubviews="YES" contentMode="scaleToFill" selectionStyle="default" indentationWidth="10" reuseIdentifier="passwordTableViewCell" rowHeight="52" id="vIU-mk-Lbm">
|
||||
<rect key="frame" x="0.0" y="139" width="375" height="52"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="vIU-mk-Lbm" id="6VP-wN-g64">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Password" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="5Jt-ds-Hhi">
|
||||
<rect key="frame" x="15" y="8" width="55" height="15"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleCaption1"/>
|
||||
<color key="textColor" white="0.33333333333333331" alpha="1" colorSpace="calibratedWhite"/>
|
||||
<nil key="highlightedColor"/>
|
||||
</label>
|
||||
<textField opaque="NO" clipsSubviews="YES" contentMode="scaleToFill" contentHorizontalAlignment="left" contentVerticalAlignment="center" placeholder="Password" textAlignment="natural" minimumFontSize="17" clearButtonMode="whileEditing" translatesAutoresizingMaskIntoConstraints="NO" id="hSW-BQ-SXN">
|
||||
<rect key="frame" x="15" y="23" width="352" height="21"/>
|
||||
<nil key="textColor"/>
|
||||
<fontDescription key="fontDescription" style="UICTFontTextStyleBody"/>
|
||||
<textInputTraits key="textInputTraits" autocorrectionType="no" spellCheckingType="no" keyboardType="alphabet" keyboardAppearance="alert" secureTextEntry="YES"/>
|
||||
</textField>
|
||||
</subviews>
|
||||
<constraints>
|
||||
<constraint firstAttribute="trailingMargin" secondItem="hSW-BQ-SXN" secondAttribute="trailing" id="3gM-Hv-ZaR"/>
|
||||
<constraint firstAttribute="topMargin" secondItem="5Jt-ds-Hhi" secondAttribute="top" id="INe-r1-0Lo"/>
|
||||
<constraint firstItem="hSW-BQ-SXN" firstAttribute="leading" secondItem="5Jt-ds-Hhi" secondAttribute="leading" id="JRs-qa-035"/>
|
||||
<constraint firstItem="hSW-BQ-SXN" firstAttribute="top" secondItem="5Jt-ds-Hhi" secondAttribute="bottom" id="mVE-aV-0yw"/>
|
||||
<constraint firstItem="5Jt-ds-Hhi" firstAttribute="leading" secondItem="6VP-wN-g64" secondAttribute="leadingMargin" constant="7" id="sMW-lm-4pj"/>
|
||||
</constraints>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
</cells>
|
||||
</tableViewSection>
|
||||
</sections>
|
||||
|
|
@ -229,6 +287,8 @@
|
|||
<simulatedToolbarMetrics key="simulatedBottomBarMetrics"/>
|
||||
<connections>
|
||||
<outlet property="gitRepositoryURLTextField" destination="EVT-VU-sCi" id="2EH-Uq-tbU"/>
|
||||
<outlet property="passwordTextField" destination="hSW-BQ-SXN" id="uFS-s5-yfZ"/>
|
||||
<outlet property="usernameTextField" destination="cxu-dD-J2H" id="RjU-Hf-xyw"/>
|
||||
</connections>
|
||||
</tableViewController>
|
||||
<placeholder placeholderIdentifier="IBFirstResponder" id="7c1-c7-Qyp" userLabel="First Responder" sceneMemberID="firstResponder"/>
|
||||
|
|
@ -251,7 +311,7 @@
|
|||
<rect key="frame" x="0.0" y="0.0" width="375" height="44"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="zAx-8x-oje" id="17r-45-oPf">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="43.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="43"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
</tableViewCellContentView>
|
||||
</tableViewCell>
|
||||
|
|
@ -283,7 +343,7 @@
|
|||
<rect key="frame" x="0.0" y="35" width="375" height="52"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="BYZ-9g-xZy" id="Zfn-rK-sN1">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="51.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="PGP Key URL" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="dWi-eh-7Eq">
|
||||
|
|
@ -312,7 +372,7 @@
|
|||
<rect key="frame" x="0.0" y="87" width="375" height="52"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<tableViewCellContentView key="contentView" opaque="NO" clipsSubviews="YES" multipleTouchEnabled="YES" contentMode="center" tableViewCell="qrQ-bd-sV8" id="7ts-YH-1tP">
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="51.5"/>
|
||||
<rect key="frame" x="0.0" y="0.0" width="375" height="51"/>
|
||||
<autoresizingMask key="autoresizingMask"/>
|
||||
<subviews>
|
||||
<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Passphrase" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="KFQ-DQ-XNg">
|
||||
|
|
|
|||
|
|
@ -17,4 +17,11 @@ extension DefaultsKeys {
|
|||
static let pgpKeyUserID = DefaultsKey<String>("pgpKeyUserID")
|
||||
|
||||
static let gitRepositoryURL = DefaultsKey<URL?>("gitRepositoryURL")
|
||||
static let gitRepositoryUsername = DefaultsKey<String>("gitRepositoryUsername")
|
||||
static let gitRepositoryPassword = DefaultsKey<String>("gitRepositoryPassword")
|
||||
static let gitRepositorySSHPublicKeyURL = DefaultsKey<URL?>("gitRepositorySSHPublicKeyURL")
|
||||
static let gitRepositorySSHPrivateKeyURL = DefaultsKey<URL?>("gitRepositorySSHPrivateKeyURL")
|
||||
static let gitRepositorySSHPrivateKeyPassphrase = DefaultsKey<String?>("gitRepositorySSHPrivateKeyPassphrase")
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,17 @@ class GitServerSettingTableViewController: UITableViewController {
|
|||
|
||||
@IBOutlet weak var gitRepositoryURLTextField: UITextField!
|
||||
|
||||
@IBOutlet weak var usernameTextField: UITextField!
|
||||
|
||||
@IBOutlet weak var passwordTextField: UITextField!
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
if let url = Defaults[.gitRepositoryURL] {
|
||||
gitRepositoryURLTextField.text = url.absoluteString
|
||||
}
|
||||
usernameTextField.text = Defaults[.gitRepositoryUsername]
|
||||
passwordTextField.text = Defaults[.gitRepositoryPassword]
|
||||
}
|
||||
|
||||
override func viewDidAppear(_ animated: Bool) {
|
||||
|
|
|
|||
|
|
@ -13,11 +13,36 @@ import UIKit
|
|||
import SwiftyUserDefaults
|
||||
import ObjectiveGit
|
||||
|
||||
struct GitCredential {
|
||||
|
||||
enum Credential {
|
||||
case http(userName: String, password: String)
|
||||
case ssh(userName: String, password: String, publicKeyFile: URL, privateKeyFile: URL)
|
||||
}
|
||||
|
||||
var credential: Credential
|
||||
|
||||
func credentialProvider() throws -> GTCredentialProvider {
|
||||
return GTCredentialProvider { (_, _, _) -> (GTCredential) in
|
||||
let credential: GTCredential?
|
||||
switch self.credential {
|
||||
case let .http(userName, password):
|
||||
print("username \(userName), password \(password)")
|
||||
credential = try? GTCredential(userName: userName, password: password)
|
||||
case let .ssh(userName, password, publicKeyFile, privateKeyFile):
|
||||
credential = try? GTCredential(userName: userName, publicKeyURL: publicKeyFile, privateKeyURL: privateKeyFile, passphrase: password)
|
||||
}
|
||||
return credential ?? GTCredential()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PasswordStore {
|
||||
static let shared = PasswordStore()
|
||||
|
||||
let storeURL = URL(fileURLWithPath: "\(Globals.shared.documentPath)/password-store")
|
||||
var storeRepository: GTRepository?
|
||||
var gitCredential: GitCredential
|
||||
|
||||
let pgp: ObjectivePGP = ObjectivePGP()
|
||||
|
||||
|
|
@ -32,8 +57,9 @@ class PasswordStore {
|
|||
}
|
||||
if Defaults[.pgpKeyID] != "" {
|
||||
pgp.importKeys(fromFile: Globals.shared.secringPath, allowDuplicates: false)
|
||||
|
||||
}
|
||||
gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: Defaults[.gitRepositoryUsername], password: Defaults[.gitRepositoryPassword]))
|
||||
|
||||
}
|
||||
|
||||
func initPGP(pgpKeyURL: URL, pgpKeyLocalPath: String) -> Bool {
|
||||
|
|
@ -55,9 +81,10 @@ class PasswordStore {
|
|||
|
||||
|
||||
func cloneRepository(remoteRepoURL: URL,
|
||||
credential: GitCredential,
|
||||
transferProgressBlock: @escaping (UnsafePointer<git_transfer_progress>, UnsafeMutablePointer<ObjCBool>) -> Void,
|
||||
checkoutProgressBlock: @escaping (String?, UInt, UInt) -> Void) -> Bool {
|
||||
print("start cloning remote repo")
|
||||
print("start cloning remote repo: \(remoteRepoURL)")
|
||||
let fm = FileManager.default
|
||||
if (storeRepository != nil) {
|
||||
print("remove item")
|
||||
|
|
@ -69,11 +96,16 @@ class PasswordStore {
|
|||
}
|
||||
do {
|
||||
print("start cloning...")
|
||||
storeRepository = try GTRepository.clone(from: remoteRepoURL, toWorkingDirectory: storeURL, options: nil, transferProgressBlock:transferProgressBlock, checkoutProgressBlock: checkoutProgressBlock)
|
||||
let credentialProvider = try credential.credentialProvider()
|
||||
let options: [String: Any] = [
|
||||
GTRepositoryCloneOptionsCredentialProvider: credentialProvider
|
||||
]
|
||||
storeRepository = try GTRepository.clone(from: remoteRepoURL, toWorkingDirectory: storeURL, options: options, transferProgressBlock:transferProgressBlock, checkoutProgressBlock: checkoutProgressBlock)
|
||||
print("clone finish")
|
||||
updatePasswordEntityCoreData()
|
||||
gitCredential = credential
|
||||
return true
|
||||
} catch {
|
||||
storeRepository = nil
|
||||
print(error)
|
||||
return false
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class PasswordsTableViewController: UITableViewController {
|
|||
searchController.dimsBackgroundDuringPresentation = false
|
||||
definesPresentationContext = true
|
||||
tableView.tableHeaderView = searchController.searchBar
|
||||
tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.top, animated: false)
|
||||
// tableView.scrollToRow(at: IndexPath(row: 0, section: 0), at: UITableViewScrollPosition.top, animated: false)
|
||||
}
|
||||
|
||||
func filterContentForSearchText(searchText: String, scope: String = "All") {
|
||||
|
|
|
|||
|
|
@ -20,15 +20,18 @@ class SettingsTableViewController: UITableViewController {
|
|||
|
||||
@IBAction func save(segue: UIStoryboardSegue) {
|
||||
if let controller = segue.source as? GitServerSettingTableViewController {
|
||||
if Defaults[.gitRepositoryURL] == nil || controller.gitRepositoryURLTextField.text != Defaults[.gitRepositoryURL]!.absoluteString {
|
||||
Defaults[.gitRepositoryURL] = URL(string: controller.gitRepositoryURLTextField.text!)
|
||||
|
||||
let gitRepostiroyURL = controller.gitRepositoryURLTextField.text!
|
||||
let username = controller.usernameTextField.text!
|
||||
let password = controller.passwordTextField.text!
|
||||
|
||||
if Defaults[.gitRepositoryURL] == nil || gitRepostiroyURL != Defaults[.gitRepositoryURL]!.absoluteString {
|
||||
SVProgressHUD.setDefaultMaskType(.black)
|
||||
SVProgressHUD.show(withStatus: "Prepare Repository")
|
||||
//SVProgressHUD.showProgress(0.0, status: "Clone Remote Repository")
|
||||
|
||||
let gitCredential = GitCredential(credential: GitCredential.Credential.http(userName: username, password: password))
|
||||
|
||||
DispatchQueue.global(qos: .userInitiated).async {
|
||||
let ret = PasswordStore.shared.cloneRepository(remoteRepoURL: Defaults[.gitRepositoryURL]!,
|
||||
let ret = PasswordStore.shared.cloneRepository(remoteRepoURL: URL(string: gitRepostiroyURL)!,
|
||||
credential: gitCredential,
|
||||
transferProgressBlock:{ (git_transfer_progress, stop) in
|
||||
DispatchQueue.main.async {
|
||||
SVProgressHUD.showProgress(Float(git_transfer_progress.pointee.received_objects)/Float(git_transfer_progress.pointee.total_objects), status: "Clone Remote Repository")
|
||||
|
|
@ -44,6 +47,10 @@ class SettingsTableViewController: UITableViewController {
|
|||
if ret {
|
||||
SVProgressHUD.showSuccess(withStatus: "Done")
|
||||
SVProgressHUD.dismiss(withDelay: 1)
|
||||
Defaults[.gitRepositoryURL] = URL(string: gitRepostiroyURL)
|
||||
Defaults[.gitRepositoryUsername] = username
|
||||
Defaults[.gitRepositoryPassword] = password
|
||||
|
||||
NotificationCenter.default.post(Notification(name: Notification.Name("passwordUpdated")))
|
||||
} else {
|
||||
SVProgressHUD.showError(withStatus: "Error")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue