Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/pyinfra/operations/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@ def repo(

# Ensuring existing repo
else:
# Keep repository origin in sync with src, which may differ from last run
git_commands.append(StringCommand("remote", "set-url", "origin", QuoteString(src)))

is_tag = False
current_branch = host.get_fact(GitBranch, repo=dest)
if branch is not None and current_branch != branch:
Expand Down
1 change: 1 addition & 0 deletions tests/operations/git.repo/branch_pull.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}
},
"commands": [
"cd /home/myrepo && git remote set-url origin myrepo",
"cd /home/myrepo && git fetch",
"cd /home/myrepo && git checkout mybranch",
"cd /home/myrepo && git pull"
Expand Down
1 change: 1 addition & 0 deletions tests/operations/git.repo/branch_switch_up_to_date.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
}
},
"commands": [
"cd /home/myrepo && git remote set-url origin myrepo",
"cd /home/myrepo && git fetch",
"cd /home/myrepo && git checkout mybranch"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
}
},
"commands": [
"cd /home/myrepo && git remote set-url origin myrepo",
"cd /home/myrepo && git fetch",
"cd /home/myrepo && git checkout 'feature/evil; rm -rf /'"
]
Expand Down
28 changes: 28 additions & 0 deletions tests/operations/git.repo/clone_src_origin_changed_url.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"args": [
"myrepo",
"/home/myrepo"
],
"kwargs": {},
"facts": {
"files.Directory": {
"path=/home/myrepo": {},
"path=/home/myrepo/.git": {
"mode": 0
}
},
"git.GitBranch": {
"repo=/home/myrepo": "main"
},
"git.GitLocalCommit": {
"ref=main, repo=/home/myrepo": null
},
"git.GitRemoteBranchCommit": {
"branch=main, remote=origin, repo=/home/myrepo": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
}
},
"commands": [
"cd /home/myrepo && git remote set-url origin myrepo",
"cd /home/myrepo && git pull"
]
}
28 changes: 28 additions & 0 deletions tests/operations/git.repo/clone_src_origin_same_url.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"args": [
"changedrepo",
"/home/myrepo"
],
"kwargs": {},
"facts": {
"files.Directory": {
"path=/home/myrepo": {},
"path=/home/myrepo/.git": {
"mode": 0
}
},
"git.GitBranch": {
"repo=/home/myrepo": "main"
},
"git.GitLocalCommit": {
"ref=main, repo=/home/myrepo": null
},
"git.GitRemoteBranchCommit": {
"branch=main, remote=origin, repo=/home/myrepo": "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
}
},
"commands": [
"cd /home/myrepo && git remote set-url origin changedrepo",
"cd /home/myrepo && git pull"
]
}
1 change: 1 addition & 0 deletions tests/operations/git.repo/rebase.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
},
"commands": [
"cd /home/myrepo && git remote set-url origin myrepo",
"cd /home/myrepo && git pull --rebase"
],
"idempotent": false,
Expand Down
1 change: 1 addition & 0 deletions tests/operations/git.repo/recursive_submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
}
},
"commands": [
"cd /home/myrepo && git remote set-url origin myrepo",
"cd /home/myrepo && git pull",
"cd /home/myrepo && git submodule update --init --recursive"
],
Expand Down
4 changes: 3 additions & 1 deletion tests/operations/git.repo/up_to_date.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
"branch=master, remote=origin, repo=/home/myrepo": "1a2b3c4d5e6f7890abcdef1234567890abcdef12"
}
},
"commands": [],
"commands": [
"cd /home/myrepo && git remote set-url origin myrepo"
],
"noop_description": "git repository /home/myrepo is already up to date"
}
1 change: 1 addition & 0 deletions tests/operations/git.repo/update_submodules.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
}
},
"commands": [
"cd /home/myrepo && git remote set-url origin myrepo",
"cd /home/myrepo && git pull",
"cd /home/myrepo && git submodule update --init"
],
Expand Down
Loading