@@ -26,6 +26,7 @@ final class GitKitTests: XCTestCase {
26
26
( " testCommandWithArgs " , testCommandWithArgs) ,
27
27
( " testClone " , testClone) ,
28
28
( " testCheckoutRemoteTracking " , testCheckoutRemoteTracking) ,
29
+ ( " testRevParse " , testRevParse) ,
29
30
]
30
31
31
32
// MARK: - helpers
@@ -50,7 +51,7 @@ final class GitKitTests: XCTestCase {
50
51
try self . clean ( path: path)
51
52
let expectedOutput = expectation
52
53
let git = Git ( path: path)
53
- try git. run ( . raw( " init && git commit -m 'initial' --allow-empty " ) )
54
+ try git. run ( . raw( " init && git commit -m 'initial' --allow-empty --no-gpg-sign " ) )
54
55
let output = try git. run ( alias)
55
56
self . assert ( type: " output " , result: output, expected: expectedOutput)
56
57
try self . clean ( path: path)
@@ -74,44 +75,39 @@ final class GitKitTests: XCTestCase {
74
75
try self . clean ( path: path)
75
76
let git = Git ( path: path)
76
77
try git. run ( . cmd( . initialize) )
77
- try git. run ( . commit( message: expectation, true ) )
78
- let out = try git. run ( . log( 1 ) )
78
+ try git. run ( . commit( message: expectation, allowEmpty : true ) )
79
+ let out = try git. run ( . log( numberOfCommits : 1 ) )
79
80
try self . clean ( path: path)
80
81
XCTAssertTrue ( out. hasSuffix ( expectation) , " Commit was not created. " )
81
82
}
82
83
83
84
func testCommandWithArgs( ) throws {
84
85
let path = self . currentPath ( )
85
86
86
- try self . _test ( . cmd( . branch, " -a " ) , path: path, expectation: " * master " )
87
+ try self . _test ( . cmd( . branch, " -a " ) , path: path, expectation: " * main " )
87
88
}
88
89
89
90
func testClone( ) throws {
90
91
let path = self . currentPath ( )
91
92
92
93
let expectation = """
93
- On branch master
94
- Your branch is up to date with 'origin/master '.
94
+ On branch main
95
+ Your branch is up to date with 'origin/main '.
95
96
96
97
nothing to commit, working tree clean
97
98
"""
98
99
99
100
try self . clean ( path: path)
100
101
let git = Git ( path: path)
101
102
102
- try git. run ( . clone( url: " git@ github.com: binarybirds/shell-kit" ) )
103
+ try git. run ( . clone( url: " https:// github.com/ binarybirds/shell-kit.git " ) )
103
104
let statusOutput = try git. run ( " cd \( path) /shell-kit && git status " )
104
105
try self . clean ( path: path)
105
106
self . assert ( type: " output " , result: statusOutput, expected: expectation)
106
107
}
107
108
108
109
func testCheckoutRemoteTracking( ) throws {
109
- let path = self . currentPath ( )
110
-
111
- try self . clean ( path: path)
112
- let git = Git ( path: path)
113
-
114
- try git. run ( . clone( url: " https://github.com/binarybirds/shell-kit.git " ) )
110
+ try git. run ( . clone( url: " https://github.com/binarybirds/shell-kit.git " ) )
115
111
116
112
let repoPath = " \( path) /shell-kit "
117
113
let repoGit = Git ( path: repoPath)
@@ -124,17 +120,43 @@ final class GitKitTests: XCTestCase {
124
120
XCTAssertTrue ( branchOutput. contains ( " origin/main " ) , " Branch should track origin/main " )
125
121
}
126
122
123
+ func testRevParse( ) throws {
124
+
125
+ let path = self . currentPath ( )
126
+
127
+ try self . clean ( path: path)
128
+ let git = Git ( path: path)
129
+
130
+ try git. run ( . raw( " init " ) )
131
+ try git. run ( . commit( message: " initial commit " , allowEmpty: true ) )
132
+
133
+ let abbrevRef = try git. run ( . revParse( abbrevRef: true , revision: " HEAD " ) )
134
+ XCTAssertEqual ( abbrevRef, " main " , " Should return abbreviated reference name " )
135
+
136
+ let fullSHA = try git. run ( . revParse( abbrevRef: false , revision: " HEAD " ) )
137
+ XCTAssertTrue ( fullSHA. count == 40 , " Should return full 40-character SHA " )
138
+ XCTAssertTrue ( fullSHA. allSatisfy { $0. isHexDigit } , " SHA should contain only hex characters " )
139
+
140
+ let symbolicRef = try git. run ( . revParse( abbrevRef: false , revision: " @ " ) )
141
+ XCTAssertEqual ( symbolicRef, fullSHA, " Symbolic '@' should resolve to same SHA as HEAD " )
142
+
143
+ let currentBranch = try git. run ( . revParse( abbrevRef: true , revision: " @ " ) )
144
+ XCTAssertEqual ( currentBranch, " main " , " Should return current branch name " )
145
+
146
+ try self . clean ( path: path)
147
+ }
148
+
127
149
#if os(macOS)
128
150
func testAsyncRun( ) throws {
129
151
let path = self . currentPath ( )
130
152
try self . clean ( path: path)
131
153
let expectedOutput = """
132
- On branch master
154
+ On branch main
133
155
nothing to commit, working tree clean
134
156
"""
135
157
136
158
let git = Git ( path: path)
137
- try git. run ( . raw( " init && git commit -m 'initial' --allow-empty " ) )
159
+ try git. run ( . raw( " init && git commit -m 'initial' --allow-empty --no-gpg-sign " ) )
138
160
139
161
let expectation = XCTestExpectation ( description: " Shell command finished. " )
140
162
git. run ( . cmd( . status) ) { result, error in
0 commit comments