Skip to content

Commit

Permalink
Only change branch name if it is a new repository
Browse files Browse the repository at this point in the history
  • Loading branch information
mtfishman committed Nov 23, 2024
1 parent ea4fec2 commit 433e958
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ version = "0.1.0"
[deps]
Git = "d7ba0133-e1db-5d97-8f8c-041e4b3a1eb2"
Git_jll = "f8c6e375-362e-5223-8a59-34ff63f689eb"
LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433"
PkgSkeleton = "d254efa0-af53-535e-b7f1-03c1c9fbcbe7"
Preferences = "21216c6a-2e73-6563-6e65-726566657250"

[compat]
Aqua = "0.8.9"
Git = "1.3.1"
Git_jll = "2.46.2"
LibGit2 = "1.10"
PkgSkeleton = "1.3.1"
Preferences = "1.4.3"
Test = "1.10"
Expand Down
16 changes: 14 additions & 2 deletions src/ITensorPkgSkeleton.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module ITensorPkgSkeleton

using Git: git
using LibGit2: LibGit2
using PkgSkeleton: PkgSkeleton
using Preferences: Preferences

Expand Down Expand Up @@ -93,6 +94,14 @@ function set_default_template_path(template)
return joinpath(pkgdir(ITensorPkgSkeleton), "templates", template)
end

function is_git_repo(path)
return try LibGit2.GitRepo(path)
return true
catch
return false
end
end

function generate(
pkg_name; path=default_path(), templates=default_templates(), user_replacements=(;)
)
Expand All @@ -103,11 +112,14 @@ function generate(
# Process downstream package information.
user_replacements = format_downstream_pkgs(user_replacements)
pkg_path = joinpath(path, pkg_name)
is_new_repo = !is_git_repo(path)
branch_name = default_branch_name()
user_replacements_dict = Dict(keys(user_replacements) .=> values(user_replacements))
PkgSkeleton.generate(pkg_path; templates, user_replacements=user_replacements_dict)
# Change the default branch.
change_branch_name(pkg_path, branch_name)
if is_new_repo
# Change the default branch if this is a new repository.
change_branch_name(pkg_path, branch_name)
end
return nothing
end

Expand Down

0 comments on commit 433e958

Please sign in to comment.