How to download files from a specific git pull request? - azure

I have a Pull Request on an azure devops remote git repository in format like this https://project-domain/project-name/_git/repo-name/pullrequest/xxxxx
Is there an easy way to just download the files which are part of this pull request without having to clone the entire repository?
If i have to use commit ids which are part of this pull request, that's alright with me. please let me know if anyone has done this before

In Azure DevOps, when viewing a Pull Request, on the Files tab, next to each file is a menu with three dots (...) with an option for "Download". You can do that for any file you wish to download.
However, it's very important to realize that the file you are downloading is the file from the point of view of the source branch. If the source branch is not up to date with the target branch, then you might not be downloading the final version of that file that will exist at the time the PR is completed. If you wish to download the future version of the file after PR is completed, then you should select the three dots (...) button next to the Complete button, and select "View Merge Commit". From there you can download each of the files the same way as previously described, and now you'll get the version of the files that would exist if you completed the PR right now. Obviously if that file gets modified on the target branch between now and when the PR is actually completed, the file would change yet again.
Side note, if you have many files in the PR that you wish to download, as far as I know you cannot download them all together in one shot from the UI, though you can probably automate it using the API (or by cloning and doing a diff which you said you wanted to avoid).

Related

In GitLab how to change file contents automatically when doing a push to a feature branch and then undo that change when merge into master?

I use GitLab on-premise and need to change the contents of a file automatically when I push into my feature branch so when tests run and code is executed, one of the files called from within the repo itself has modified content. When I merge that branch into master, I need to undo that change.
It's not enough to override the file contents just when the test runs, because of how the application works. It will end up pulling the repo from GitLab on it's own and execute one of the files contained within.
I have been looking into hooks a little bit, but I can't find any references or examples on how to accomplish something like this.
Currently I am changing the file manually so my CI tests run accurately. If the tests then pass, I can manually change the file back and skip the CI tests on the final push, and then merge into master.
There's not really a default way to automatically change, commit and push back into Gitlab from a pipeline, as the pipeline does not have authorization to write into the repo.
However, you can provide a "Personal Access Token" (PAT) for one of Gitlab's users (or even a special service-account created for that purpose) - either commit that to your repo (which is quite unsafe) or provide it through the "CI/CD Variables" setting from within Gitlab.
Your pipeline will then need to do something like:
# change file.txt
# add the remote with credentials authorized to commit; do not fail if the remote already exists
git remote remove pushorigin || true
git remote add pushorigin https://commituser:${PAT}#gitlab.local/path/to/project.git
# add and commit the file
git add file.txt
git commit -m "Commit Message"
# move the remote's branch tip:
git push pushorigin "HEAD:${CI_COMMIT_REF_NAME}"
I don't have a clue how to revert that automatically when/before finally merging the branch. Don't you mind those testing commits being merged back into main, possibly creating conflicts on those files?
I guess overall, the application should be modified to better support testing on those branches.

GitLab: Change closed and merged Merge request commit hashes

I've a problem with a Gitlab self-hosted community edition. Recently I've rewrite history on a git repository, and that changed a lot of SHA-1 of commits. I've tried to place the "replace" references, but Gitlab still in Merge Request uses the old commit hashs. After some trials I've tried to export the project and check inside the exported files, and I noticed that Gitlab uses its database to hold the commit hash codes. Is there a safe way to change those commits? I'm the system administrator, so I have full access to gitlab instance and also root access to the machine hosting it.
Thank you all.
In short, no, there's not a way to change this for MRs.
The most you can do is remove the content of the commits from GitLab (the SHA and links will still appear in the MR UI, but they will result in a 404 error after they are removed). This will also remove the ability to see the diffs of these MRs.
To do this, follow the documentation described here for cleaning up repos after history rewrite. After using git filter-repo and uploading the commit map to GitLab, the old commits will be remapped to the new ones (removing all the old references) and the rewritten history will be removed forever.
I've had a success exporting the project, modifying the json file inside the tar gz changing the old commit/new commit, and importing the project.
Yes, now the events are done by the importer (and no more the original committer/pusher), but this is accetable, as the story is now navigable in gitlab with the correct commit as company rules.

I have accidentally deleted a page from Azure DevOps Wiki. How can I recover it?

I have accidentally deleted a Wiki-page from our repository in Azure DevOps.
(How) can I recover it?
That is not an option for us, since we will loose many changes that
were made after the last version no. up until the date I accidentally
deleted the wiki page.
You can choose Clone wiki to download the wiki repo to local machine.
Then use git commands(git revert or what) locally to get the deleted page, once you find the deleted page, publish it and add it back to Wiki page as a new commit.
I was just able to do this without too much fanfare. The resource that was helpful was this VS community topic. There is an answer that provides a solution that doesn't require you to clone the repo.
The key insight is that you can navigate to the Azure DevOps repo UI for the Git repo that's backing the wiki. The solution author says that the shape of the URL is something like https://dev.azure.com/<organization-name>/<project-name>/_git/<wiki-name>.wiki. This didn't quite work for me because we have a different URL scheme in our organization, but I was able to figure it out after a little trial and error. I later saw that you can get the URL by using the Clone Repo UI in the wiki - it gives you the URL, so you can just copy it and navigate to it.
Anyway, the steps were:
Figure out the URL of the git repo that backs the wiki
Navigate to the revision history for the entire wiki
the current UI shows you the Contents tab by default - switch to History
Scroll until you find the commits that deleted the pages you want to restore
it's one of those list views that populate themselves as you scroll, so you won't be able to use the browser page search efficiently, unfortunately
Revert the commits
In my case, this required clicking on them and creating pull requests to revert, but I was able to merge them myself without involving code reviewers. YMMV
All in all, not a wholly terrible experience, but completely undiscoverable.
Assuming you're managing a provisioned wiki (vs using published code as a wiki):
Look in the top-right corner for the vertical 3-dot menu, where there's an option to view revisions:
Choose the revision you want to revert to (e.g. the one prior to deleting the needed wiki page), from the list (click on its version hash):
From the revision details, select "Revert":
At this point, your wiki should be at its prior state, and your wiki page should once again be available.
Note: If you're using published code as a wiki, you would recover/revert your changes as you would with any other code commit.
More details may be found here.
I couldn't find a way to do this through the Azure DevOps web interface but you can restore the page by reverting the commit that deleted it if you clone the wiki locally.
Clone the wiki to your computer - find the clone wiki option in the menu at the top of the left bar which shows the wiki contents, copy the URL and use to clone locally using your usual git client.
Find the commit that deleted the page, the commit message will start with "Deleted page" then the name of the page you deleted.
Restore the page and commit the change. There are various ways to do this - I reverted the commit, you could checkout the commit and copy the page out to make a new commit. You may get a merge conflict on '.order', I'm not sure what the best thing to do is but I kept the current version and haven't had any problems.
Push the changes to Azure DevOps, refresh and you'll see the page has been restored.
This works even for Project Wikis. I wonder if Azure DevOps has added the functionality that enabled this since some of the other answers have been written.

Why can't I assign my merge request to a specific user in Gitlab

We are using gitlab to serve our git repositories. Now I've cloned our master project to track my own changes and now I would like to create a merge request to the master again. When I look at the youtube movie, I can see Job selecting a user to assign the merge request to. In my version this whole drop-down box is missing.
Is this because I use version 6.8.2, is it because I do a merge request from a fork? What is happening here?
I would like to be able to select an other team member to review the commit before merging it into the master project.
You're able to assign it to someone on the next screen. We agree that this flow is not ideal so we changed it in 6.9 https://www.gitlab.com/2014/05/22/gitlab-6-9-ee-and-ce-release/

Set Specific alerts on SVN commit with Tortoise

I noticed that in my developpment team, sometimes someone forgets to commit a file that must go with an other to keep the site working. this causes problemes and waste of time...
The question is : Is it possible to tell SVN tortoise : if someone tries to commit a file A without files (A1, A2,...An) ask them if they are sure they don't need to commit them too?
You need to have look at hooks.hook is nothing but a program triggered by some repository event.You can write whatever set of activities(alert in your case) inside hooks.use pre hooks for running the hooks before any task take place.
EDIT:
Refer commit monitor.CommitMonitor is a small tool to monitor Apacheā„¢ SubversionĀ® repositories for new commits.

Resources