Skip to content

Commit

Permalink
add check whether remote repo is a github repository
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Mar 9, 2022
1 parent f565f8f commit 0d1d657
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/ArcCommander/APIs/GitAPI.fs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,11 @@ module GitAPI =
let remoteSpecified () =
let ok, msg, error = Fake.Tools.Git.CommandHelper.runGitCommand repoDir "remote -v"
msg.Length > 0


let remoteIsGitHub () =
executeGitCommandWithResponse repoDir "remote get-url origin"
|> Seq.exists (fun s -> s.ToLower().Contains("github.com"))

/// check whether the specified remote exists online
let remoteExists () =
let ok, msg, error = Fake.Tools.Git.CommandHelper.runGitCommand repoDir "fetch"
Expand Down Expand Up @@ -174,9 +178,22 @@ module GitAPI =

if containsFlag "Force" gitArgs then

log.Trace("Remote does not exist and --force flag was set. Trying to create upstream repo.")
if remoteIsGitHub() then
let m =
[
"Remote does not exist and --force flag was set. But force pushing a new repository to GitHub is not supported."
"First create an empty repository on github and try pushing again"
"More info: https://docs.github.com/en/get-started/importing-your-projects-to-github/importing-source-code-to-github/adding-an-existing-project-to-github-using-the-command-line"
]
|> List.reduce (fun a b -> a + "\n" + b)

log.Error(m)

else

log.Trace("Remote does not exist and --force flag was set. Trying to create upstream repo.")

executeGitCommand repoDir ($"push --set-upstream origin {branch}") |> ignore
executeGitCommand repoDir ($"push --set-upstream origin {branch}") |> ignore

else
let m =
Expand Down

0 comments on commit 0d1d657

Please sign in to comment.