Skip to content

Commit

Permalink
pyinfra/operations: respect pull value in git.worktree
Browse files Browse the repository at this point in the history
  • Loading branch information
Pirols authored and Fizzadar committed Sep 1, 2024
1 parent 983426a commit 78c7376
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pyinfra/operations/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,15 @@ def worktree(
commitish="v1.0"
)
git.worktree(
name="Idempotent worktree creation, never pulls",
repo="/usr/local/src/pyinfra/master",
worktree="/usr/local/src/pyinfra/hotfix",
new_branch="v1.0",
commitish="v1.0",
pull=False
)
git.worktree(
name="Pull an existing worktree already linked to a tracking branch",
repo="/usr/local/src/pyinfra/master",
Expand Down Expand Up @@ -317,9 +326,12 @@ def worktree(

# It exists and we still want it => pull/rebase it
elif host.get_fact(Directory, path=worktree) and present:
if not pull:
host.noop("Pull is disabled")

# pull the worktree only if it's already linked to a tracking branch or
# if a remote branch is set
if host.get_fact(GitTrackingBranch, repo=worktree) or from_remote_branch:
elif host.get_fact(GitTrackingBranch, repo=worktree) or from_remote_branch:
command = "cd {0} && git pull".format(worktree)

if rebase:
Expand Down
18 changes: 18 additions & 0 deletions tests/operations/git.worktree/pull_disable.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"args": ["/home/myworktree"],
"kwargs": {
"pull": false
},
"facts": {
"files.Directory": {
"path=/home/myworktree": {
"mode": 0
}
},
"git.GitTrackingBranch" : {
"repo=/home/myworktree": "origin/master"
}
},
"commands": [],
"noop_description": "Pull is disabled"
}

0 comments on commit 78c7376

Please sign in to comment.