@@ -65,7 +65,7 @@ defmodule GitWork.Commands.Init do
6565
6666 defp do_repair ( dir , git_dir , bare_dir ) do
6767 with :ok <- ensure_gitdir_pointer ( dir , git_dir ) ,
68- :ok <- configure_bare ( bare_dir ) ,
68+ :ok <- Project . configure_bare ( bare_dir ) ,
6969 { :ok , branch } <- Project . head_branch ( dir ) ,
7070 :ok <- ensure_worktree_dir ( dir , branch ) do
7171 { :ok , Project . worktree_path ( dir , branch ) }
@@ -119,12 +119,12 @@ defmodule GitWork.Commands.Init do
119119
120120 defp do_init_steps ( dir , branch , stashed? , git_dir , bare_dir ) do
121121 with :ok <- move_git_to_bare ( git_dir , bare_dir ) ,
122- :ok <- configure_bare ( bare_dir ) ,
122+ :ok <- Project . configure_bare ( bare_dir ) ,
123123 :ok <- move_files_to_worktree ( dir , branch ) ,
124124 :ok <- setup_worktree_linkage ( dir , branch ) ,
125125 :ok <- write_gitdir_pointer ( dir ) ,
126126 :ok <- reset_worktree_index ( dir , branch ) ,
127- :ok <- ensure_upstream ( dir , branch ) ,
127+ :ok <- Project . ensure_upstream ( Path . join ( dir , branch ) , branch ) ,
128128 :ok <- validate_init ( dir , branch , bare_dir ) ,
129129 :ok <- maybe_pop_stash ( dir , branch , stashed? ) do
130130 :ok
@@ -168,27 +168,6 @@ defmodule GitWork.Commands.Init do
168168 end
169169 end
170170
171- defp configure_bare ( bare_dir ) do
172- with { :ok , _ } <- Git . cmd ( [ "config" , "core.bare" , "true" ] , cd: bare_dir ) do
173- # Only set fetch refspec if remote origin exists
174- case Git . cmd ( [ "remote" , "get-url" , "origin" ] , cd: bare_dir ) do
175- { :ok , _ } ->
176- Git . cmd (
177- [ "config" , "remote.origin.fetch" , "+refs/heads/*:refs/remotes/origin/*" ] ,
178- cd: bare_dir
179- )
180- |> case do
181- { :ok , _ } -> :ok
182- { :error , msg } -> { :error , "failed to configure fetch: #{ msg } " }
183- end
184-
185- { :error , _ } ->
186- IO . write ( :stderr , "warning: no remote 'origin' configured\n " )
187- :ok
188- end
189- end
190- end
191-
192171 defp move_files_to_worktree ( dir , branch ) do
193172 worktree_dir = Path . join ( dir , branch )
194173
@@ -249,36 +228,6 @@ defmodule GitWork.Commands.Init do
249228 end
250229 end
251230
252- defp ensure_upstream ( dir , branch ) do
253- worktree_dir = Path . join ( dir , branch )
254-
255- case Git . cmd ( [ "rev-parse" , "--abbrev-ref" , "--symbolic-full-name" , "@{u}" ] ,
256- cd: worktree_dir
257- ) do
258- { :ok , _ } ->
259- :ok
260-
261- { :error , _ } ->
262- case Git . cmd ( [ "show-ref" , "--verify" , "--quiet" , "refs/remotes/origin/#{ branch } " ] ,
263- cd: worktree_dir
264- ) do
265- { :ok , _ } ->
266- case Git . cmd ( [ "branch" , "--set-upstream-to=origin/#{ branch } " , branch ] ,
267- cd: worktree_dir
268- ) do
269- { :ok , _ } ->
270- :ok
271-
272- { :error , msg } ->
273- IO . write ( :stderr , "warning: failed to set upstream for #{ branch } : #{ msg } \n " )
274- :ok
275- end
276-
277- { :error , _ } ->
278- :ok
279- end
280- end
281- end
282231
283232 defp validate_init ( dir , branch , bare_dir ) do
284233 worktree_dir = Path . join ( dir , branch )
0 commit comments